From: huangchenghai <huangchenghai2@huawei.com>
To: Mark Rutland <mark.rutland@arm.com>
Cc: <arnd@arndb.de>, <catalin.marinas@arm.com>, <will@kernel.org>,
<akpm@linux-foundation.org>, <anshuman.khandual@arm.com>,
<ryan.roberts@arm.com>, <andriy.shevchenko@linux.intel.com>,
<herbert@gondor.apana.org.au>, <linux-kernel@vger.kernel.org>,
<linux-arch@vger.kernel.org>,
<linux-arm-kernel@lists.infradead.org>,
<linux-crypto@vger.kernel.org>, <linux-api@vger.kernel.org>,
<fanghao11@huawei.com>, <shenyang39@huawei.com>,
<liulongfang@huawei.com>, <qianweili@huawei.com>
Subject: Re: [PATCH RFC 4/4] arm64/io: Add {__raw_read|__raw_write}128 support
Date: Thu, 13 Nov 2025 22:19:34 +0800 [thread overview]
Message-ID: <017956b9-cb91-4068-b9d0-b54f93d83eeb@huawei.com> (raw)
In-Reply-To: <aRR9UesvUCFLdVoW@J2N7QTR9R3>
在 2025/11/12 20:28, Mark Rutland 写道:
> On Wed, Nov 12, 2025 at 09:58:46AM +0800, Chenghai Huang wrote:
>> From: Weili Qian <qianweili@huawei.com>
>>
>> Starting from ARMv8.4, stp and ldp instructions become atomic.
> That's not true for accesses to Device memory types.
>
> Per ARM DDI 0487, L.b, section B2.2.1.1 ("Changes to single-copy atomicity in
> Armv8.4"):
>
> If FEAT_LSE2 is implemented, LDP, LDNP, and STP instructions that load
> or store two 64-bit registers are single-copy atomic when all of the
> following conditions are true:
> • The overall memory access is aligned to 16 bytes.
> • Accesses are to Inner Write-Back, Outer Write-Back Normal cacheable memory.
>
> IIUC when used for Device memory types, those can be split, and a part
> of the access could be replayed multiple times (e.g. due to an
> intetrupt).
>
> I don't think we can add this generally. It is not atomic, and not
> generally safe.
>
> Mark.
Thanks for your correction. I misunderstood the behavior of LDP and
STP instructions. So, regarding device memory types, LDP and STP
instructions do not guarantee single-copy atomicity.
For devices that require 128-bit atomic access, is it only possible
to implement this functionality in the driver?
Chenghai
>
>> Currently, device drivers depend on 128-bit atomic memory IO access,
>> but these are implemented within the drivers. Therefore, this introduces
>> generic {__raw_read|__raw_write}128 function for 128-bit memory access.
>>
>> Signed-off-by: Weili Qian <qianweili@huawei.com>
>> Signed-off-by: Chenghai Huang <huangchenghai2@huawei.com>
>> ---
>> arch/arm64/include/asm/io.h | 21 +++++++++++++++++++++
>> 1 file changed, 21 insertions(+)
>>
>> diff --git a/arch/arm64/include/asm/io.h b/arch/arm64/include/asm/io.h
>> index 83e03abbb2ca..80430750a28c 100644
>> --- a/arch/arm64/include/asm/io.h
>> +++ b/arch/arm64/include/asm/io.h
>> @@ -50,6 +50,17 @@ static __always_inline void __raw_writeq(u64 val, volatile void __iomem *addr)
>> asm volatile("str %x0, %1" : : "rZ" (val), "Qo" (*ptr));
>> }
>>
>> +#define __raw_write128 __raw_write128
>> +static __always_inline void __raw_write128(u128 val, volatile void __iomem *addr)
>> +{
>> + u64 low, high;
>> +
>> + low = val;
>> + high = (u64)(val >> 64);
>> +
>> + asm volatile ("stp %x0, %x1, [%2]\n" :: "rZ"(low), "rZ"(high), "r"(addr));
>> +}
>> +
>> #define __raw_readb __raw_readb
>> static __always_inline u8 __raw_readb(const volatile void __iomem *addr)
>> {
>> @@ -95,6 +106,16 @@ static __always_inline u64 __raw_readq(const volatile void __iomem *addr)
>> return val;
>> }
>>
>> +#define __raw_read128 __raw_read128
>> +static __always_inline u128 __raw_read128(const volatile void __iomem *addr)
>> +{
>> + u64 high, low;
>> +
>> + asm volatile("ldp %0, %1, [%2]" : "=r" (low), "=r" (high) : "r" (addr));
>> +
>> + return (((u128)high << 64) | (u128)low);
>> +}
>> +
>> /* IO barriers */
>> #define __io_ar(v) \
>> ({ \
>> --
>> 2.33.0
>>
>>
prev parent reply other threads:[~2025-11-13 14:19 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-11-12 1:58 [PATCH RFC 0/4] Introduce 128-bit IO access Chenghai Huang
2025-11-12 1:58 ` [PATCH RFC 1/4] UAPI: Introduce 128-bit types and byteswap operations Chenghai Huang
2025-11-12 1:58 ` [PATCH RFC 2/4] asm-generic/io.h: add io{read,write}128 accessors Chenghai Huang
2025-11-12 1:58 ` [PATCH RFC 3/4] io-128-nonatomic: introduce io{read|write}128_{lo_hi|hi_lo} Chenghai Huang
2025-11-12 14:48 ` Ben Dooks
2025-11-13 11:10 ` huangchenghai
2025-11-12 1:58 ` [PATCH RFC 4/4] arm64/io: Add {__raw_read|__raw_write}128 support Chenghai Huang
2025-11-12 12:28 ` Mark Rutland
2025-11-12 14:01 ` David Laight
2025-11-12 14:17 ` Mark Rutland
2025-11-13 14:19 ` huangchenghai [this message]
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=017956b9-cb91-4068-b9d0-b54f93d83eeb@huawei.com \
--to=huangchenghai2@huawei.com \
--cc=akpm@linux-foundation.org \
--cc=andriy.shevchenko@linux.intel.com \
--cc=anshuman.khandual@arm.com \
--cc=arnd@arndb.de \
--cc=catalin.marinas@arm.com \
--cc=fanghao11@huawei.com \
--cc=herbert@gondor.apana.org.au \
--cc=linux-api@vger.kernel.org \
--cc=linux-arch@vger.kernel.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-crypto@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=liulongfang@huawei.com \
--cc=mark.rutland@arm.com \
--cc=qianweili@huawei.com \
--cc=ryan.roberts@arm.com \
--cc=shenyang39@huawei.com \
--cc=will@kernel.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