From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
To: Davidlohr Bueso <dave@stgolabs.net>
Cc: <dave.jiang@intel.com>, <dan.j.williams@intel.com>,
<alison.schofield@intel.com>, <ira.weiny@intel.com>,
<vishal.l.verma@intel.com>, <seven.yi.lee@gmail.com>,
<hch@infradead.org>, <a.manzanares@samsung.com>,
<fan.ni@samsung.com>, <anisa.su@samsung.com>,
<linux-cxl@vger.kernel.org>
Subject: Re: [PATCH v4] cxl/pci: Support Global Persistent Flush (GPF)
Date: Mon, 27 Jan 2025 11:26:50 +0000 [thread overview]
Message-ID: <20250127112650.00004dd8@huawei.com> (raw)
In-Reply-To: <20250124233533.910535-1-dave@stgolabs.net>
On Fri, 24 Jan 2025 15:35:33 -0800
Davidlohr Bueso <dave@stgolabs.net> wrote:
> Add support for GPF flows. It is found that the CXL specification
> around this to be a bit too involved from the driver side. And while
> this should really all handled by the hardware, this patch takes
> things with a grain of salt.
>
> Upon respective port enumeration, both phase timeouts are set to
> a max of 20 seconds, which is the NMI watchdog default for lockup
> detection. The premise is that the kernel does not have enough
> information to set anything better than a max across the board
> and hope devices finish their GPF flows within the platform energy
> budget.
>
> Timeout detection is based on dirty Shutdown semantics. The driver
> will mark it as dirty, expecting that the device clear it upon a
> successful GPF event. The admin may consult the device Health and
> check the dirty shutdown counter to see if there was a problem
> with data integrity.
>
> Signed-off-by: Davidlohr Bueso <dave@stgolabs.net>
A few minor things inline.
Only return 0 definitely wants changing, the others are just comments
that you can act on if you want.
Reviewed-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
> diff --git a/drivers/cxl/core/pci.c b/drivers/cxl/core/pci.c
> index b3aac9964e0d..b0a85f411e7d 100644
> --- a/drivers/cxl/core/pci.c
> +++ b/drivers/cxl/core/pci.c
> @@ -1054,3 +1054,89 @@ int cxl_pci_get_bandwidth(struct pci_dev *pdev, struct access_coordinate *c)
>
> return 0;
> }
> +
> +/*
> + * Set max timeout such that platforms will optimize GPF flow to avoid
> + * the implied worst-case scenario delays. On a sane platform, all
> + * devices should always complete GPF within the energy budget of
> + * the GPF flow. The kernel does not have enough information to pick
> + * anything better than "maximize timeouts and hope it works".
> + *
> + * A misbehaving device could block forward progress of GPF for all
> + * the other devices, exhausting the energy budget of the platform.
> + * However, the spec seems to assume that moving on from slow to respond
> + * devices is a virtue. It is not possible to know that, in actuality,
> + * the slow to respond device is *the* most critical device in the
> + * system to wait.
> + */
> +#define GPF_TIMEOUT_BASE_MAX 2
> +#define GPF_TIMEOUT_SCALE_MAX 7 /* 10 seconds */
> +
> +static int update_gpf_port_dvsec(struct pci_dev *pdev, int dvsec, int phase)
> +{
> + u16 ctrl;
> + int rc, offset, base, scale;
> +
> + switch (phase) {
> + case 1:
> + offset = CXL_DVSEC_PORT_GPF_PHASE_1_CONTROL_OFFSET;
> + base = CXL_DVSEC_PORT_GPF_PHASE_1_TMO_BASE_MASK;
> + scale = CXL_DVSEC_PORT_GPF_PHASE_1_TMO_SCALE_MASK;
> + break;
> + case 2:
> + offset = CXL_DVSEC_PORT_GPF_PHASE_2_CONTROL_OFFSET;
> + base = CXL_DVSEC_PORT_GPF_PHASE_2_TMO_BASE_MASK;
> + scale = CXL_DVSEC_PORT_GPF_PHASE_2_TMO_SCALE_MASK;
> + break;
> + default:
> + return -EINVAL;
> + }
> +
> + rc = pci_read_config_word(pdev, dvsec + offset, &ctrl);
> + if (rc)
> + return rc;
> +
> + if (FIELD_GET(base, ctrl) == GPF_TIMEOUT_BASE_MAX &&
> + FIELD_GET(scale, ctrl) == GPF_TIMEOUT_SCALE_MAX)
> + return rc;
return 0; // it is zero anyway, so be explicit that this
// is a good path.
> +
> + ctrl = FIELD_PREP(base, GPF_TIMEOUT_BASE_MAX);
> + ctrl |= FIELD_PREP(scale, GPF_TIMEOUT_SCALE_MAX);
> +
> + rc = pci_write_config_word(pdev, dvsec + offset, ctrl);
> + if (!rc)
> + pci_dbg(pdev, "Port GPF phase %d timeout: %d0 secs\n",
It's a bit nasty to assume for this print that the scale is 10 seconds
but allow the base to vary.
> + phase, GPF_TIMEOUT_BASE_MAX);
> +
> + return rc;
> +}
> diff --git a/drivers/cxl/cxlmem.h b/drivers/cxl/cxlmem.h
> index 2a25d1957ddb..17baced54b3b 100644
> --- a/drivers/cxl/cxlmem.h
> +++ b/drivers/cxl/cxlmem.h
> @@ -693,6 +693,10 @@ struct cxl_mbox_set_partition_info {
>
> #define CXL_SET_PARTITION_IMMEDIATE_FLAG BIT(0)
>
> +struct cxl_mbox_set_shutdown_state_in {
Spec reference maybe to keep inline with other similar structures?
> + u8 state;
> +} __packed;
> +
> /* Set Timestamp CXL 3.0 Spec 8.2.9.4.2 */
> struct cxl_mbox_set_timestamp_in {
> __le64 timestamp;
> @@ -829,6 +833,7 @@ void cxl_event_trace_record(const struct cxl_memdev *cxlmd,
> enum cxl_event_log_type type,
> enum cxl_event_type event_type,
> const uuid_t *uuid, union cxl_event *evt);
> +int cxl_dirty_shutdown_state(struct cxl_memdev_state *mds);
> int cxl_set_timestamp(struct cxl_memdev_state *mds);
> int cxl_poison_state_init(struct cxl_memdev_state *mds);
> int cxl_mem_get_poison(struct cxl_memdev *cxlmd, u64 offset, u64 len,
next prev parent reply other threads:[~2025-01-27 11:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-01-24 23:35 [PATCH v4] cxl/pci: Support Global Persistent Flush (GPF) Davidlohr Bueso
2025-01-25 2:26 ` Dan Williams
2025-01-27 11:26 ` Jonathan Cameron [this message]
2025-02-03 17:14 ` Dave Jiang
2025-02-03 20:48 ` Davidlohr Bueso
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=20250127112650.00004dd8@huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=a.manzanares@samsung.com \
--cc=alison.schofield@intel.com \
--cc=anisa.su@samsung.com \
--cc=dan.j.williams@intel.com \
--cc=dave.jiang@intel.com \
--cc=dave@stgolabs.net \
--cc=fan.ni@samsung.com \
--cc=hch@infradead.org \
--cc=ira.weiny@intel.com \
--cc=linux-cxl@vger.kernel.org \
--cc=seven.yi.lee@gmail.com \
--cc=vishal.l.verma@intel.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