From: Jonathan Cameron <Jonathan.Cameron@huawei.com>
To: qemu-devel@nongnu.org, "Peter Maydell" <peter.maydell@linaro.org>,
"Gregory Price" <gregory.price@memverge.com>,
"Alex Bennée" <alex.bennee@linaro.org>,
richard.henderson@linaro.org
Cc: <linux-cxl@vger.kernel.org>, <linuxarm@huawei.com>
Subject: [PATCH v3] arm/ptw: Handle atomic updates of page tables entries in MMIO during PTW.
Date: Fri, 23 Feb 2024 18:01:02 +0000 [thread overview]
Message-ID: <20240223180102.7657-1-Jonathan.Cameron@huawei.com> (raw)
Seen testing of CXL emulation on arm64 (currently out of tree).
CXL interleave occurs at subpage granularity so is emulated using an IO
Memory Region. The memory is general purpose and as such may contain page
tables. FEAT_HADFS using atomic accesses from the page table walkers to
update accessed and dirty bits.
Note that disabling kernel support this ARM 8.1 feature avoids this issue
as the PTW no longer does an atomic update of the page table entries, but
that is a nasty workaround beyond its use in root causing this issue.
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
v3: Thanks Richard and Peter for reviewing.
Much simpler error handle + use of BQL_LOCK_GUARD() (Richard)
Dropped RFC and updated description as seems this is converging!
---
target/arm/ptw.c | 31 +++++++++++++++++++++++++++++--
1 file changed, 29 insertions(+), 2 deletions(-)
diff --git a/target/arm/ptw.c b/target/arm/ptw.c
index 5eb3577bcd..140afed451 100644
--- a/target/arm/ptw.c
+++ b/target/arm/ptw.c
@@ -711,8 +711,35 @@ static uint64_t arm_casq_ptw(CPUARMState *env, uint64_t old_val,
void *host = ptw->out_host;
if (unlikely(!host)) {
- fi->type = ARMFault_UnsuppAtomicUpdate;
- return 0;
+ /* Page table in MMIO Memory Region */
+ CPUState *cs = env_cpu(env);
+ MemTxAttrs attrs = {
+ .space = ptw->out_space,
+ .secure = arm_space_is_secure(ptw->out_space),
+ };
+ AddressSpace *as = arm_addressspace(cs, attrs);
+ MemTxResult result = MEMTX_OK;
+ BQL_LOCK_GUARD();
+
+ cur_val = (ptw->out_be
+ ? address_space_ldq_be(as, ptw->out_phys, attrs, &result)
+ : address_space_ldq_le(as, ptw->out_phys, attrs, &result));
+ if (result == MEMTX_OK && cur_val == old_val) {
+ if (ptw->out_be) {
+ address_space_stq_be(as, ptw->out_phys, new_val, attrs,
+ &result);
+ } else {
+ address_space_stq_le(as, ptw->out_phys, new_val, attrs,
+ &result);
+ }
+ }
+ if (unlikely(result != MEMTX_OK)) {
+ fi->type = ARMFault_SyncExternalOnWalk;
+ fi->ea = arm_extabort_type(result);
+ return old_val;
+ }
+
+ return cur_val;
}
/*
--
2.39.2
next reply other threads:[~2024-02-23 18:01 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-23 18:01 Jonathan Cameron [this message]
2024-02-23 18:19 ` [PATCH v3] arm/ptw: Handle atomic updates of page tables entries in MMIO during PTW Richard Henderson
2024-02-26 14:12 ` Peter Maydell
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=20240223180102.7657-1-Jonathan.Cameron@huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=alex.bennee@linaro.org \
--cc=gregory.price@memverge.com \
--cc=linux-cxl@vger.kernel.org \
--cc=linuxarm@huawei.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=richard.henderson@linaro.org \
/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