[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20220920171134.000033a9@huawei.com>
Date: Tue, 20 Sep 2022 17:11:34 +0100
From: Jonathan Cameron <Jonathan.Cameron@...wei.com>
To: Ira Weiny <ira.weiny@...el.com>
CC: Dan Williams <dan.j.williams@...el.com>,
Alison Schofield <alison.schofield@...el.com>,
Vishal Verma <vishal.l.verma@...el.com>,
"Ben Widawsky" <bwidawsk@...nel.org>,
Steven Rostedt <rostedt@...dmis.org>,
Davidlohr Bueso <dave@...olabs.net>,
<linux-kernel@...r.kernel.org>, <linux-cxl@...r.kernel.org>
Subject: Re: [RFC PATCH 6/9] cxl/mem: Trace Memory Module Event Record
On Wed, 14 Sep 2022 14:17:14 -0700
Ira Weiny <ira.weiny@...el.com> wrote:
> On Thu, Aug 25, 2022 at 11:58:42AM +0100, Jonathan Cameron wrote:
> > On Fri, 12 Aug 2022 22:32:40 -0700
> > ira.weiny@...el.com wrote:
> >
> > > From: Ira Weiny <ira.weiny@...el.com>
> > >
> > > CXL v3.0 section 8.2.9.2.1.3 defines the Memory Module Event Record.
> > >
> > > Determine if the event read is memory module record and if so trace the
> > > record.
> > >
> > > Signed-off-by: Ira Weiny <ira.weiny@...el.com>
> > Similar comments to on previous patches around using
> > get_unaligned_le*()
>
> Yep...
>
> [snip]
>
> > >
> > > +/*
> > > + * Get Health Info Record
> > > + * CXL v3.0 section 8.2.9.8.3.1; Table 8-100
> > > + */
> > > +struct cxl_get_health_info {
> > > + u8 health_status;
> > > + u8 media_status;
> > > + u8 add_status;
> > > + u8 life_used;
> > > + u16 device_temp;
> >
> > As previous - even though they aren't aligned, I'd have thought
> > __le16 etc will still work. The unaligned accessors are fine
> > taking __le16 * for example.
>
> Ok my bad on using u16 here and I will change it. I 100% agree that these
> should be __le16/__le32. That said there is no need to use the unaligned
> accessors for the 16/32 bit fields.
>
> The unaligned accessors cast the pointer to a __le16/__le32 type and no
> architecture redefines those. So using le{16,32}_to_cpu() should work just
> fine on all archs.
If they are unaligned, make sure to use the unaligned accessors.
Key is that it's not a simple cast, but rather a cast to a packed
structure. The C spec guarantees that those will be handled correctly
even on platforms that don't do unaligned accesses - it will have to
use multiple instructions to construct the unaligned access from
a set of small aligned ones.
The C Spec doesn't guarantee the same for a simple cast to an __le16.
There are some hints on this in:
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/include/asm-generic/unaligned.h?id=778aaefb8e864fc61f850539ea479554dd4caea1
I recall a full explanation of why this worked, but no idea where
to find that now - might be the thread referred to in that patch from
Arnd.
Jonathan
>
> [snip]
>
> > > +
> > > + TP_fast_assign(
> > > + /* Common */
> > > + __assign_str(dev_name, dev_name);
> > > + memcpy(__entry->id, &rec->hdr.id, UUID_SIZE);
> > > + __entry->log = log;
> > > + __entry->flags = le32_to_cpu(rec->hdr.flags_length) >> 8;
> > > + __entry->handle = le16_to_cpu(rec->hdr.handle);
> > > + __entry->related_handle = le16_to_cpu(rec->hdr.related_handle);
> > > + __entry->timestamp = le64_to_cpu(rec->hdr.timestamp);
> > > +
> > > + /* Memory Module Event */
> > > + __entry->event_type = rec->event_type;
> > > +
> > > + /* Device Health Info */
> > > + __entry->health_status = rec->info.health_status;
> > > + __entry->media_status = rec->info.media_status;
> > > + __entry->life_used = rec->info.life_used;
> > > + __entry->dirty_shutdown_cnt = le32_to_cpu(rec->info.dirty_shutdown_cnt);
> > > + __entry->cor_vol_err_cnt = le32_to_cpu(rec->info.cor_vol_err_cnt);
> >
> > I've lost track, but my guess is some / all of these need the unaligned_get_le32()
> > etc rather than aligned form. Maybe just be lazy and use the unaligned versions
> > even when things happen to be aligned - then we don't have to think about it
> > when reviewing :)
>
> See above. I think the 16/32 bit fields work as intended except for my lack of
> using the correct type.
>
> Ira
Powered by blists - more mailing lists