From: Borislav Petkov <bp@alien8.de>
To: Tony Luck <tony.luck@intel.com>
Cc: x86@kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] x86/mce: /dev/mcelog: Dynamically allocate space for machine check records
Date: Mon, 17 Feb 2020 21:47:56 +0100 [thread overview]
Message-ID: <20200217204756.GE14426@zn.tnic> (raw)
In-Reply-To: <20200208000551.11364-1-tony.luck@intel.com>
On Fri, Feb 07, 2020 at 04:05:51PM -0800, Tony Luck wrote:
> We have had a hard coded limit of 32 machine check records since the
> dawn of time. But as numbers of cores increase, it is possible for
> more than 32 errors to be reported before a user process reads from
> /dev/mcelog. In this case the additional errors are lost.
>
> Keep 32 as the minimum. But tune the maximum value up based on the
> number of processors.
>
> Signed-off-by: Tony Luck <tony.luck@intel.com>
> ---
> arch/x86/include/asm/mce.h | 6 ++--
> arch/x86/kernel/cpu/mce/dev-mcelog.c | 46 ++++++++++++++++------------
> 2 files changed, 29 insertions(+), 23 deletions(-)
...
> @@ -214,21 +210,21 @@ static ssize_t mce_chrdev_read(struct file *filp, char __user *ubuf,
>
> /* Only supports full reads right now */
> err = -EINVAL;
> - if (*off != 0 || usize < MCE_LOG_LEN*sizeof(struct mce))
> + if (*off != 0 || usize < mcelog->len*sizeof(struct mce))
Add spaces around that *
> goto out;
>
> - next = mcelog.next;
> + next = mcelog->next;
> err = 0;
>
> for (i = 0; i < next; i++) {
> - struct mce *m = &mcelog.entry[i];
> + struct mce *m = &mcelog->entry[i];
>
> err |= copy_to_user(buf, m, sizeof(*m));
> buf += sizeof(*m);
> }
>
> - memset(mcelog.entry, 0, next * sizeof(struct mce));
> - mcelog.next = 0;
> + memset(mcelog->entry, 0, next * sizeof(struct mce));
> + mcelog->next = 0;
>
> if (err)
> err = -EFAULT;
...
> @@ -340,6 +336,15 @@ static struct miscdevice mce_chrdev_device = {
> static __init int dev_mcelog_init_device(void)
> {
> int err;
> + int mce_log_len;
Please sort function local variables declaration in a reverse christmas
tree order:
<type A> longest_variable_name;
<type B> shorter_var_name;
<type C> even_shorter;
<type D> i;
> +
> + mce_log_len = max(MCE_LOG_MIN_LEN, num_online_cpus());
arch/x86/kernel/cpu/mce/dev-mcelog.c: In function ‘dev_mcelog_init_device’:
./include/linux/kernel.h:835:29: warning: comparison of distinct pointer types lacks a cast
835 | (!!(sizeof((typeof(x) *)1 == (typeof(y) *)1)))
| ^~
./include/linux/kernel.h:849:4: note: in expansion of macro ‘__typecheck’
849 | (__typecheck(x, y) && __no_side_effects(x, y))
| ^~~~~~~~~~~
./include/linux/kernel.h:859:24: note: in expansion of macro ‘__safe_cmp’
859 | __builtin_choose_expr(__safe_cmp(x, y), \
| ^~~~~~~~~~
./include/linux/kernel.h:875:19: note: in expansion of macro ‘__careful_cmp’
875 | #define max(x, y) __careful_cmp(x, y, >)
| ^~~~~~~~~~~~~
arch/x86/kernel/cpu/mce/dev-mcelog.c:341:16: note: in expansion of macro ‘max’
341 | mce_log_len = max(MCE_LOG_MIN_LEN, num_online_cpus());
| ^~~
That MCE_LOG_MIN_LEN wants to be 32U.
> + mcelog = kzalloc(sizeof(*mcelog) + mce_log_len * sizeof(struct mce), GFP_KERNEL);
> + if (!mcelog)
> + return -ENOMEM;
<---- newline here.
> + strncpy(mcelog->signature, MCE_LOG_SIGNATURE, sizeof(mcelog->signature));
> + mcelog->len = mce_log_len;
> + mcelog->recordlen = sizeof(struct mce);
>
> /* register character device /dev/mcelog */
> err = misc_register(&mce_chrdev_device);
Thx.
--
Regards/Gruss,
Boris.
https://people.kernel.org/tglx/notes-about-netiquette
next prev parent reply other threads:[~2020-02-17 20:48 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-02-08 0:05 [PATCH] x86/mce: /dev/mcelog: Dynamically allocate space for machine check records Tony Luck
2020-02-08 4:22 ` Luck, Tony
2020-02-17 20:47 ` Borislav Petkov [this message]
2020-02-18 18:44 ` [PATCH v2] " Luck, Tony
2020-03-10 9:49 ` [tip: ras/core] x86/mce/dev-mcelog: " tip-bot2 for Tony Luck
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=20200217204756.GE14426@zn.tnic \
--to=bp@alien8.de \
--cc=linux-kernel@vger.kernel.org \
--cc=tony.luck@intel.com \
--cc=x86@kernel.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: 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