From: Dave Jiang <dave.jiang@intel.com>
To: <alison.schofield@intel.com>, Davidlohr Bueso <dave@stgolabs.net>,
Jonathan Cameron <jonathan.cameron@huawei.com>,
Vishal Verma <vishal.l.verma@intel.com>,
Ira Weiny <ira.weiny@intel.com>,
Dan Williams <dan.j.williams@intel.com>
Cc: <linux-cxl@vger.kernel.org>
Subject: Re: [PATCH 2/2] cxl/memdev: Hold region_rwsem during inject and clear poison ops
Date: Mon, 27 Nov 2023 10:58:52 -0700 [thread overview]
Message-ID: <2e5f09b5-373c-482e-8578-f6098a8cfbcb@intel.com> (raw)
In-Reply-To: <08721dc1df0a51e4e38fecd02425c3475912dfd5.1701041440.git.alison.schofield@intel.com>
On 11/26/23 17:09, alison.schofield@intel.com wrote:
> From: Alison Schofield <alison.schofield@intel.com>
>
> Poison inject and clear are supported via debugfs where a privileged
> user can inject and clear poison to a device physical address.
>
> Commit 458ba8189cb4 ("cxl: Add cxl_decoders_committed() helper")
> added a lockdep assert that highlighted a gap in poison inject and
> clear functions where holding the dpa_rwsem does not assure that a
> a DPA is not added to a region.
>
> The impact for inject and clear is that if the DPA address being
> injected or cleared has been attached to a region, but not yet
> committed, the dev_dbg() message intended to alert the debug user
> that they are acting on a mapped address is not emitted. Also, the
> cxl_poison trace event that serves as a log of the inject and clear
> activity will not include region info.
>
> Close this gap by snapshotting an unchangeable region state during
> poison inject and clear operations. That means holding both the
> region_rwsem and the dpa_rwsem during the inject and clear ops.
>
> Fixes: d2fbc4865802 ("cxl/memdev: Add support for the Inject Poison mailbox command")
> Fixes: 9690b07748d1 ("cxl/memdev: Add support for the Clear Poison mailbox command")
> Signed-off-by: Alison Schofield <alison.schofield@intel.com>
Reviewed-by: Dave Jiang <dave.jiang@intel.com>
> ---
> drivers/cxl/core/memdev.c | 18 ++++++++++++++++--
> 1 file changed, 16 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/cxl/core/memdev.c b/drivers/cxl/core/memdev.c
> index 5ad1b13e780a..2f43d368ba07 100644
> --- a/drivers/cxl/core/memdev.c
> +++ b/drivers/cxl/core/memdev.c
> @@ -331,10 +331,16 @@ int cxl_inject_poison(struct cxl_memdev *cxlmd, u64 dpa)
> if (!IS_ENABLED(CONFIG_DEBUG_FS))
> return 0;
>
> - rc = down_read_interruptible(&cxl_dpa_rwsem);
> + rc = down_read_interruptible(&cxl_region_rwsem);
> if (rc)
> return rc;
>
> + rc = down_read_interruptible(&cxl_dpa_rwsem);
> + if (rc) {
> + up_read(&cxl_region_rwsem);
> + return rc;
> + }
> +
> rc = cxl_validate_poison_dpa(cxlmd, dpa);
> if (rc)
> goto out;
> @@ -362,6 +368,7 @@ int cxl_inject_poison(struct cxl_memdev *cxlmd, u64 dpa)
> trace_cxl_poison(cxlmd, cxlr, &record, 0, 0, CXL_POISON_TRACE_INJECT);
> out:
> up_read(&cxl_dpa_rwsem);
> + up_read(&cxl_region_rwsem);
>
> return rc;
> }
> @@ -379,10 +386,16 @@ int cxl_clear_poison(struct cxl_memdev *cxlmd, u64 dpa)
> if (!IS_ENABLED(CONFIG_DEBUG_FS))
> return 0;
>
> - rc = down_read_interruptible(&cxl_dpa_rwsem);
> + rc = down_read_interruptible(&cxl_region_rwsem);
> if (rc)
> return rc;
>
> + rc = down_read_interruptible(&cxl_dpa_rwsem);
> + if (rc) {
> + up_read(&cxl_region_rwsem);
> + return rc;
> + }
> +
> rc = cxl_validate_poison_dpa(cxlmd, dpa);
> if (rc)
> goto out;
> @@ -419,6 +432,7 @@ int cxl_clear_poison(struct cxl_memdev *cxlmd, u64 dpa)
> trace_cxl_poison(cxlmd, cxlr, &record, 0, 0, CXL_POISON_TRACE_CLEAR);
> out:
> up_read(&cxl_dpa_rwsem);
> + up_read(&cxl_region_rwsem);
>
> return rc;
> }
next prev parent reply other threads:[~2023-11-27 17:58 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-27 0:09 [PATCH 0/2] cxl/core: Hold region_rwsem during poison ops alison.schofield
2023-11-27 0:09 ` [PATCH 1/2] cxl/core: Always hold region_rwsem while reading poison lists alison.schofield
2023-11-27 17:40 ` Dave Jiang
2023-11-27 21:20 ` Davidlohr Bueso
2023-11-30 1:21 ` Dan Williams
2023-11-27 0:09 ` [PATCH 2/2] cxl/memdev: Hold region_rwsem during inject and clear poison ops alison.schofield
2023-11-27 17:58 ` Dave Jiang [this message]
2023-11-28 0:58 ` 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=2e5f09b5-373c-482e-8578-f6098a8cfbcb@intel.com \
--to=dave.jiang@intel.com \
--cc=alison.schofield@intel.com \
--cc=dan.j.williams@intel.com \
--cc=dave@stgolabs.net \
--cc=ira.weiny@intel.com \
--cc=jonathan.cameron@huawei.com \
--cc=linux-cxl@vger.kernel.org \
--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