From: Petr Mladek <pmladek@suse.com> To: John Ogness <john.ogness@linutronix.de> Cc: Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>, Sergey Senozhatsky <sergey.senozhatsky@gmail.com>, Steven Rostedt <rostedt@goodmis.org>, Linus Torvalds <torvalds@linux-foundation.org>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, Thomas Gleixner <tglx@linutronix.de>, Peter Zijlstra <peterz@infradead.org>, Andrea Parri <parri.andrea@gmail.com>, Paul McKenney <paulmck@kernel.org>, kexec@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH next v3 5/8] printk: ringbuffer: clear initial reserved fields Date: Tue, 1 Sep 2020 16:33:06 +0200 [thread overview] Message-ID: <20200901143306.GQ4928@alley> (raw) In-Reply-To: <20200831011058.6286-6-john.ogness@linutronix.de> On Mon 2020-08-31 03:16:55, John Ogness wrote: > prb_reserve() will set some meta data values and leave others > uninitialized (or rather, containing the values of the previous > wrap). Simplify the API by always clearing out all the fields. > Only the sequence number is filled in. The caller is now > responsible for filling in the rest of the meta data fields. > In particular, for correctly filling in text and dict lengths. > > Signed-off-by: John Ogness <john.ogness@linutronix.de> > > --- > kernel/printk/printk.c | 7 ++++++- > kernel/printk/printk_ringbuffer.c | 29 +++++++++++++++++++---------- > 2 files changed, 25 insertions(+), 11 deletions(-) > > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c > index ad8d1dfe5fbe..7e7d596c8878 100644 > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -520,8 +520,11 @@ static int log_store(u32 caller_id, int facility, int level, > memcpy(&r.text_buf[0], text, text_len); > if (trunc_msg_len) > memcpy(&r.text_buf[text_len], trunc_msg, trunc_msg_len); > - if (r.dict_buf) > + r.info->text_len = text_len + trunc_msg_len; > + if (r.dict_buf) { > memcpy(&r.dict_buf[0], dict, dict_len); > + r.info->dict_len = dict_len; > + } > r.info->facility = facility; > r.info->level = level & 7; > r.info->flags = flags & 0x1f; > @@ -1078,9 +1081,11 @@ static unsigned int __init add_to_rb(struct printk_ringbuffer *rb, > return 0; > > memcpy(&dest_r.text_buf[0], &r->text_buf[0], dest_r.text_buf_size); > + dest_r.info->text_len = r->info->text_len; It looks a bit non-consistent that memcpy() copies text_buf_size but valid data are defined by text_len. I would prefer to be on the safe size and copy only text_len. I could imagine some later optimization that will make buf_size bigger by alignment or something like that. The reason might be preparation for continuous lines or so. Then the size of the original buffer and the destination one might differ. It is unrelated to this patch. I would solve it by a preparation or followup one. > if (dest_r.dict_buf) { > memcpy(&dest_r.dict_buf[0], &r->dict_buf[0], > dest_r.dict_buf_size); > + dest_r.info->dict_len = r->info->dict_len; Same here. > } > dest_r.info->facility = r->info->facility; > dest_r.info->level = r->info->level; > diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c > index d66718e74aae..da54d4fadf96 100644 > --- a/kernel/printk/printk_ringbuffer.c > +++ b/kernel/printk/printk_ringbuffer.c > @@ -1159,6 +1162,18 @@ bool prb_reserve(struct prb_reserved_entry *e, struct printk_ringbuffer *rb, > > d = to_desc(desc_ring, id); > > + /* > + * Clear all @info fields except for @seq, which is used to determine > + * the new sequence number. The writer must fill in new values. > + */ > + d->info.ts_nsec = 0; > + d->info.text_len = 0; > + d->info.dict_len = 0; > + d->info.facility = 0; > + d->info.flags = 0; > + d->info.level = 0; > + d->info.caller_id = 0; This will be easy to miss when a new field is added in the future. I would prefer to store @seq into temporary variable and clear the entire structure by memset(). The new sequence number is calculated few lines below anyway. Otherwise, it looks good to me. Best Regards, Petr
WARNING: multiple messages have this Message-ID (diff)
From: Petr Mladek <pmladek@suse.com> To: John Ogness <john.ogness@linutronix.de> Cc: Andrea Parri <parri.andrea@gmail.com>, Sergey Senozhatsky <sergey.senozhatsky.work@gmail.com>, Paul McKenney <paulmck@kernel.org>, Peter Zijlstra <peterz@infradead.org>, Greg Kroah-Hartman <gregkh@linuxfoundation.org>, kexec@lists.infradead.org, linux-kernel@vger.kernel.org, Steven Rostedt <rostedt@goodmis.org>, Sergey Senozhatsky <sergey.senozhatsky@gmail.com>, Thomas Gleixner <tglx@linutronix.de>, Linus Torvalds <torvalds@linux-foundation.org> Subject: Re: [PATCH next v3 5/8] printk: ringbuffer: clear initial reserved fields Date: Tue, 1 Sep 2020 16:33:06 +0200 [thread overview] Message-ID: <20200901143306.GQ4928@alley> (raw) In-Reply-To: <20200831011058.6286-6-john.ogness@linutronix.de> On Mon 2020-08-31 03:16:55, John Ogness wrote: > prb_reserve() will set some meta data values and leave others > uninitialized (or rather, containing the values of the previous > wrap). Simplify the API by always clearing out all the fields. > Only the sequence number is filled in. The caller is now > responsible for filling in the rest of the meta data fields. > In particular, for correctly filling in text and dict lengths. > > Signed-off-by: John Ogness <john.ogness@linutronix.de> > > --- > kernel/printk/printk.c | 7 ++++++- > kernel/printk/printk_ringbuffer.c | 29 +++++++++++++++++++---------- > 2 files changed, 25 insertions(+), 11 deletions(-) > > diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c > index ad8d1dfe5fbe..7e7d596c8878 100644 > --- a/kernel/printk/printk.c > +++ b/kernel/printk/printk.c > @@ -520,8 +520,11 @@ static int log_store(u32 caller_id, int facility, int level, > memcpy(&r.text_buf[0], text, text_len); > if (trunc_msg_len) > memcpy(&r.text_buf[text_len], trunc_msg, trunc_msg_len); > - if (r.dict_buf) > + r.info->text_len = text_len + trunc_msg_len; > + if (r.dict_buf) { > memcpy(&r.dict_buf[0], dict, dict_len); > + r.info->dict_len = dict_len; > + } > r.info->facility = facility; > r.info->level = level & 7; > r.info->flags = flags & 0x1f; > @@ -1078,9 +1081,11 @@ static unsigned int __init add_to_rb(struct printk_ringbuffer *rb, > return 0; > > memcpy(&dest_r.text_buf[0], &r->text_buf[0], dest_r.text_buf_size); > + dest_r.info->text_len = r->info->text_len; It looks a bit non-consistent that memcpy() copies text_buf_size but valid data are defined by text_len. I would prefer to be on the safe size and copy only text_len. I could imagine some later optimization that will make buf_size bigger by alignment or something like that. The reason might be preparation for continuous lines or so. Then the size of the original buffer and the destination one might differ. It is unrelated to this patch. I would solve it by a preparation or followup one. > if (dest_r.dict_buf) { > memcpy(&dest_r.dict_buf[0], &r->dict_buf[0], > dest_r.dict_buf_size); > + dest_r.info->dict_len = r->info->dict_len; Same here. > } > dest_r.info->facility = r->info->facility; > dest_r.info->level = r->info->level; > diff --git a/kernel/printk/printk_ringbuffer.c b/kernel/printk/printk_ringbuffer.c > index d66718e74aae..da54d4fadf96 100644 > --- a/kernel/printk/printk_ringbuffer.c > +++ b/kernel/printk/printk_ringbuffer.c > @@ -1159,6 +1162,18 @@ bool prb_reserve(struct prb_reserved_entry *e, struct printk_ringbuffer *rb, > > d = to_desc(desc_ring, id); > > + /* > + * Clear all @info fields except for @seq, which is used to determine > + * the new sequence number. The writer must fill in new values. > + */ > + d->info.ts_nsec = 0; > + d->info.text_len = 0; > + d->info.dict_len = 0; > + d->info.facility = 0; > + d->info.flags = 0; > + d->info.level = 0; > + d->info.caller_id = 0; This will be easy to miss when a new field is added in the future. I would prefer to store @seq into temporary variable and clear the entire structure by memset(). The new sequence number is calculated few lines below anyway. Otherwise, it looks good to me. Best Regards, Petr _______________________________________________ kexec mailing list kexec@lists.infradead.org http://lists.infradead.org/mailman/listinfo/kexec
next prev parent reply other threads:[~2020-09-01 14:35 UTC|newest] Thread overview: 34+ messages / expand[flat|nested] mbox.gz Atom feed top 2020-08-31 1:10 [PATCH next v3 0/8] printk: reimplement LOG_CONT handling John Ogness 2020-08-31 1:10 ` John Ogness 2020-08-31 1:10 ` [PATCH next v3 1/8] printk: ringbuffer: rename DESC_COMMITTED_MASK flag John Ogness 2020-08-31 1:10 ` John Ogness 2020-08-31 1:10 ` [PATCH next v3 2/8] printk: ringbuffer: change representation of reusable John Ogness 2020-08-31 1:10 ` John Ogness 2020-08-31 1:10 ` [PATCH next v3 3/8] printk: ringbuffer: relocate get_data() John Ogness 2020-08-31 1:10 ` John Ogness 2020-08-31 1:10 ` [PATCH next v3 4/8] printk: ringbuffer: add BLK_DATALESS() macro John Ogness 2020-08-31 1:10 ` John Ogness 2020-08-31 1:10 ` [PATCH next v3 5/8] printk: ringbuffer: clear initial reserved fields John Ogness 2020-08-31 1:10 ` John Ogness 2020-09-01 14:33 ` Petr Mladek [this message] 2020-09-01 14:33 ` Petr Mladek 2020-08-31 1:10 ` [PATCH next v3 6/8] printk: ringbuffer: add finalization/extension support John Ogness 2020-08-31 1:10 ` John Ogness 2020-08-31 12:54 ` John Ogness 2020-08-31 12:54 ` John Ogness 2020-09-02 10:52 ` state names: vas: " Petr Mladek 2020-09-02 10:52 ` Petr Mladek 2020-09-02 11:20 ` John Ogness 2020-09-02 11:20 ` John Ogness 2020-09-02 12:39 ` Petr Mladek 2020-09-02 12:39 ` Petr Mladek 2020-09-02 10:58 ` Petr Mladek 2020-09-02 10:58 ` Petr Mladek 2020-09-02 12:21 ` misc: was: " Petr Mladek 2020-09-02 12:21 ` Petr Mladek 2020-08-31 1:10 ` [PATCH next v3 7/8] printk: reimplement log_cont using record extension John Ogness 2020-08-31 1:10 ` John Ogness 2020-09-02 13:38 ` Petr Mladek 2020-09-02 13:38 ` Petr Mladek 2020-08-31 1:10 ` [PATCH next v3 8/8] scripts/gdb: support printk finalized records John Ogness 2020-08-31 1:10 ` John Ogness
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=20200901143306.GQ4928@alley \ --to=pmladek@suse.com \ --cc=gregkh@linuxfoundation.org \ --cc=john.ogness@linutronix.de \ --cc=kexec@lists.infradead.org \ --cc=linux-kernel@vger.kernel.org \ --cc=parri.andrea@gmail.com \ --cc=paulmck@kernel.org \ --cc=peterz@infradead.org \ --cc=rostedt@goodmis.org \ --cc=sergey.senozhatsky.work@gmail.com \ --cc=sergey.senozhatsky@gmail.com \ --cc=tglx@linutronix.de \ --cc=torvalds@linux-foundation.org \ /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: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.