From: Ira Weiny <ira.weiny@intel.com>
To: Dan Williams <dan.j.williams@intel.com>,
Ira Weiny <ira.weiny@intel.com>,
Jonathan Cameron <jonathan.cameron@huawei.com>,
Smita Koralahalli <Smita.KoralahalliChannabasappa@amd.com>,
Shiju Jose <shiju.jose@huawei.com>
Cc: Yazen Ghannam <yazen.ghannam@amd.com>,
Davidlohr Bueso <dave@stgolabs.net>,
Dave Jiang <dave.jiang@intel.com>,
Alison Schofield <alison.schofield@intel.com>,
Vishal Verma <vishal.l.verma@intel.com>,
"Ard Biesheuvel" <ardb@kernel.org>, <linux-efi@vger.kernel.org>,
<linux-kernel@vger.kernel.org>, <linux-cxl@vger.kernel.org>,
Ira Weiny <ira.weiny@intel.com>
Subject: Re: [PATCH 6/6] cxl/memdev: Register for and process CPER events
Date: Fri, 8 Dec 2023 11:43:42 -0800 [thread overview]
Message-ID: <657371eec6ac5_1e7d272948d@iweiny-mobl.notmuch> (raw)
In-Reply-To: <657279a68c270_b991294e@dwillia2-mobl3.amr.corp.intel.com.notmuch>
Dan Williams wrote:
> Ira Weiny wrote:
[snip]
> >
> > +#define CXL_EVENT_HDR_FLAGS_REC_SEVERITY GENMASK(1, 0)
> > +static int cxl_cper_event_call(struct notifier_block *nb, unsigned long action,
> > + void *data)
> > +{
> > + struct cxl_cper_notifier_data *nd = data;
> > + struct cper_cxl_event_devid *device_id = &nd->rec->hdr.device_id;
> > + enum cxl_event_log_type log_type;
> > + struct cxl_memdev_state *mds;
> > + struct cxl_dev_state *cxlds;
> > + struct pci_dev *pdev;
> > + unsigned int devfn;
> > + u32 hdr_flags;
> > +
> > + mds = container_of(nb, struct cxl_memdev_state, cxl_cper_nb);
> > +
> > + devfn = PCI_DEVFN(device_id->device_num, device_id->func_num);
> > + pdev = pci_get_domain_bus_and_slot(device_id->segment_num,
> > + device_id->bus_num, devfn);
> > + cxlds = pci_get_drvdata(pdev);
> > + if (cxlds != &mds->cxlds) {
>
> Checks of drvdata are only valid under the device lock, or with the
> assumption that this callback will never be called while pci_get_drvdata
> would return NULL.
For the device we have registered pci_get_drvdata() will be always be valid.
Each driver is registering it's own call with valid driver state in the chain.
However, I see I have a bug here. Using devm_add_action_or_reset() breaks
this assumption.
>
> With that, the check of cxlds looks like another artifact of using a
> blocking notifier chain for this callback.
It is a desired artifact. This check is determining if this event is for this
device. It is not checking if cxlds is valid.
> With an explicit single
> callback it simply becomes safe to assume that it is being called back
> before unregister_cxl_cper() has run. I.e. it is impossible to even
> write this check in that case.
Exploring the use of a single register call... you must check if the cxlds is
valid on that pdev. Because the driver may not be attached.
Something like this in cxl_core vs cxl_pci:
#define CXL_EVENT_HDR_FLAGS_REC_SEVERITY GENMASK(1, 0)
static void cxl_cper_event_call(struct cxl_cper_notifier_data *nd)
{
struct cper_cxl_event_devid *device_id = &nd->rec->hdr.device_id;
enum cxl_event_log_type log_type;
struct cxl_dev_state *cxlds;
struct pci_dev *pdev;
unsigned int devfn;
u32 hdr_flags;
devfn = PCI_DEVFN(device_id->device_num, device_id->func_num);
pdev = pci_get_domain_bus_and_slot(device_id->segment_num,
device_id->bus_num, devfn);
device_lock(&pdev->dev);
cxlds = pci_get_drvdata(pdev);
if (!cxlds)
goto out;
/* Fabricate a log type */
hdr_flags = get_unaligned_le24(nd->rec->event.generic.hdr.flags);
log_type = FIELD_GET(CXL_EVENT_HDR_FLAGS_REC_SEVERITY, hdr_flags);
cxl_event_trace_record(cxlds->cxlmd, log_type, nd->event_type,
&nd->rec->event);
out:
device_unlock(&pdev->dev);
pci_dev_put(pdev);
}
This does simplify registering.
Is this what you were thinking?
[snip]
> > +
> > +static void register_cper_events(struct cxl_memdev_state *mds)
> > +{
> > + mds->cxl_cper_nb.notifier_call = cxl_cper_event_call;
> > +
> > + if (register_cxl_cper_notifier(&mds->cxl_cper_nb)) {
> > + dev_err(mds->cxlds.dev, "CPER registration failed\n");
> > + return;
> > + }
> > +
> > + devm_add_action_or_reset(mds->cxlds.dev, cxl_unregister_cper_events, mds);
>
> Longer term I am not sure cxl_pci should be doing this registration
> directly to the CPER code vs some indirection in the core that the
> generic type-3 and the type-2 cases can register for processing. That
> can definitely wait until a Type-2 CXL.mem device driver arrives and
> wants to get notified of CXL CPER events.
>
Yes these calls will need to be moved to the core for drivers to share
later. Same for mailbox event handling.
Ira
next prev parent reply other threads:[~2023-12-08 19:43 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-29 18:00 [PATCH 0/6] efi/cxl-cper: Report CPER CXL component events through trace events Ira Weiny
2023-11-29 18:00 ` [PATCH 1/6] cxl/trace: Pass uuid explicitly to event traces Ira Weiny
2023-12-08 0:30 ` Dan Williams
2023-12-08 18:21 ` Ira Weiny
2023-11-29 18:00 ` [PATCH 2/6] cxl/events: Promote CXL event structures to a core header Ira Weiny
2023-11-29 18:00 ` [PATCH 3/6] cxl/events: Separate UUID from event structures Ira Weiny
2023-11-29 18:00 ` [PATCH 4/6] cxl/events: Create a CXL event union Ira Weiny
2023-11-29 18:00 ` [PATCH 5/6] firmware/efi: Process CXL Component Events Ira Weiny
2023-12-08 1:40 ` Dan Williams
2023-12-08 18:47 ` Ira Weiny
2023-12-08 21:39 ` Dan Williams
2023-11-29 18:00 ` [PATCH 6/6] cxl/memdev: Register for and process CPER events Ira Weiny
2023-12-08 2:04 ` Dan Williams
2023-12-08 19:43 ` Ira Weiny [this message]
2023-12-08 21:46 ` Dan Williams
2023-12-11 19:01 ` Ira Weiny
2023-12-11 19:16 ` Dan Williams
2023-12-11 23:01 ` Ira Weiny
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=657371eec6ac5_1e7d272948d@iweiny-mobl.notmuch \
--to=ira.weiny@intel.com \
--cc=Smita.KoralahalliChannabasappa@amd.com \
--cc=alison.schofield@intel.com \
--cc=ardb@kernel.org \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=jonathan.cameron@huawei.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-efi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=shiju.jose@huawei.com \
--cc=vishal.l.verma@intel.com \
--cc=yazen.ghannam@amd.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