linux-edac.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Robert Richter <rrichter@marvell.com>
To: Borislav Petkov <bp@alien8.de>
Cc: James Morse <james.morse@arm.com>,
	"linux-edac@vger.kernel.org" <linux-edac@vger.kernel.org>,
	Mauro Carvalho Chehab <mchehab@kernel.org>,
	Toshi Kani <toshi.kani@hpe.com>
Subject: Re: [PATCH] EDAC, ghes: Fix grain calculation
Date: Fri, 14 Jun 2019 07:21:47 +0000	[thread overview]
Message-ID: <20190614072139.vzet6t5erl6uz6st@rric.localdomain> (raw)
In-Reply-To: <20190613224130.GI11598@zn.tnic>

On 14.06.19 00:41:30, Borislav Petkov wrote:
> On Thu, Jun 13, 2019 at 09:07:38PM +0000, Robert Richter wrote:
> >  grain_bits = fls_long(e->grain) + 1;
> 
> For 4K grain this makes grain_bits == 12.

fls(0) == 0
fls(1) == 1
fls(2) == 2
fls(4) == 3
...
fls(0x1000) == 13

grain_bits = fls_long(0x1000) + 1 = 14

> 
> > In ras_event.h the grain then is calculated different to edac_mc
> > again:
> > 
> >  1 << __entry->grain_bits
> 
> and this makes it 4096.

It then calculates to 16k.

> 
> Looks ok to me.
> 
> But if in James' example, physical_address_mask is 0xfffffffffffff000,
> doing
> 
>   grain_bits = fls_long(~mem_err->physical_addr_mask);
> 
> would make it 11 because ~mem_err->physical_addr_mask (negated) should
> be 0xfff.

If it is not power of 2 (e.g. 0xfff), with

 fls_long(e->grain) + 1;

from edac_mc there is still an off by one (so James' calculation for
ghes is correct).

Correct for edac_mc is:

 grain_bits = fls_long(e->grain ? e->grain - 1 : 0);

This works for both, power of 2 and less:

 grain_bits(0x1000) == 12;
 grain_bits(0x0fff) == 12;
 grain_bits(0x1001) == 13;
 grain_bits(0) == 0
 grain_bits(1) == 0
 grain_bits(2) == 1

James' calculation for ghes is correct in this particular case
(assuming a bit mask with (power of 2 - 1)).

But my formula is more generic.

-Robert

  reply	other threads:[~2019-06-14  7:21 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-29 15:22 [PATCH] EDAC, ghes: Fix grain calculation James Morse
2019-05-30 16:50 ` Kani, Toshi
2019-06-12  4:34 ` Borislav Petkov
2019-06-13 17:06   ` James Morse
2019-06-13 19:18     ` Borislav Petkov
2019-06-13 21:07       ` Robert Richter
2019-06-13 22:41         ` Borislav Petkov
2019-06-14  7:21           ` Robert Richter [this message]
2019-06-14  8:39             ` Robert Richter
2019-06-14 10:09             ` Borislav Petkov
2019-06-14 14:40               ` Robert Richter
2019-06-14 15:06                 ` Borislav Petkov
2019-06-14  6:32         ` Robert Richter

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=20190614072139.vzet6t5erl6uz6st@rric.localdomain \
    --to=rrichter@marvell.com \
    --cc=bp@alien8.de \
    --cc=james.morse@arm.com \
    --cc=linux-edac@vger.kernel.org \
    --cc=mchehab@kernel.org \
    --cc=toshi.kani@hpe.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;
as well as URLs for NNTP newsgroup(s).