Enable build of full Xen for RISC-V
v3 cover Enable build of full Xen for RISC-V
This patch series performs all of the additions necessary to drop the build overrides for RISCV and enable the full Xen build. Except in cases where compatibile implementations already exist (e.g. atomic.h and bitops.h), the newly added definitions are simple.
The patch series is based on the following patch series:
- [PATCH v6 0/9] Introduce generic headers [1]
- [PATCH] move __read_mostly to xen/cache.h [2]
Right now, the patch series doesn't have a direct dependency on [2] and it provides __read_mostly in the patch:
[PATCH v3 26/34] xen/riscv: add definition of __read_mostly
However, it will be dropped as soon as [2] is merged or at least when the final version of the patch [2] is provided.
[1] https://lore.kernel.org/xen-devel/[email protected]/
[2] https://lore.kernel.org/xen-devel/[email protected]/
---
Changes in V3:
- Update the cover letter message
- The following patches were dropped as they were merged to staging:
[PATCH v2 03/39] xen/riscv:introduce asm/byteorder.h
[PATCH v2 04/39] xen/riscv: add public arch-riscv.h
[PATCH v2 05/39] xen/riscv: introduce spinlock.h
[PATCH v2 20/39] xen/riscv: define bug frame tables in xen.lds.S [PATCH v2 34/39] xen: add RISCV support for pmu.h
[PATCH v2 35/39] xen: add necessary headers to common to build full Xen for RISC-V
- Instead of the following patches were introduced new:
[PATCH v2 10/39] xen/riscv: introduce asm/iommu.h
[PATCH v2 11/39] xen/riscv: introduce asm/nospec.h
- remove "asm/" for commit messages which start with "xen/riscv:"
- code style updates.
- add emulation of {cmp}xchg_* for 1 and 2 bytes types.
- code style fixes.
- add SPDX and footer for the newly added headers.
- introduce generic find-next-bit.c.
- some other mionor changes. ( details please find in a patch )
---
Changes in V2:
- Drop the following patches as they are the part of [2]:
[PATCH v1 06/57] xen/riscv: introduce paging.h
[PATCH v1 08/57] xen/riscv: introduce asm/device.h
[PATCH v1 10/57] xen/riscv: introduce asm/grant_table.h
[PATCH v1 12/57] xen/riscv: introduce asm/hypercall.h
[PATCH v1 13/57] xen/riscv: introduce asm/iocap.h
[PATCH v1 15/57] xen/riscv: introduce asm/mem_access.h
[PATCH v1 18/57] xen/riscv: introduce asm/random.h
[PATCH v1 21/57] xen/riscv: introduce asm/xenoprof.h
[PATCH v1 24/57] xen/riscv: introduce asm/percpu.h
[PATCH v1 29/57] xen/riscv: introduce asm/hardirq.h
[PATCH v1 33/57] xen/riscv: introduce asm/altp2m.h
[PATCH v1 38/57] xen/riscv: introduce asm/monitor.h
[PATCH v1 39/57] xen/riscv: introduce asm/numa.h
[PATCH v1 42/57] xen/riscv: introduce asm/softirq.h
- xen/lib.h in most of the cases were changed to xen/bug.h as
mostly functionilty of bug.h is used.
- align arch-riscv.h with Arm's version of it.
- change the Author of commit with introduction of asm/atomic.h.
- update some definition from spinlock.h.
- code style changes.
---
Bobby Eshleman (1):
xen/riscv: introduce atomic.h
Oleksii Kurochko (33):
xen/riscv: disable unnecessary configs
xen/riscv: use some asm-generic headers
xen: add support in public/hvm/save.h for PPC and RISC-V xen/riscv: introduce cpufeature.h
xen/riscv: introduce guest_atomics.h
xen: avoid generation of empty asm/iommu.h xen/asm-generic: introdure nospec.h
xen/riscv: introduce setup.h
xen/riscv: introduce system.h
xen/riscv: introduce bitops.h
xen/riscv: introduce flushtlb.h
xen/riscv: introduce smp.h
xen/riscv: introduce cmpxchg.h
xen/riscv: introduce io.h
xen/lib: introduce generic find next bit operations xen/riscv: add compilation of generic find-next-bit.c xen/riscv: introduce domain.h
xen/riscv: introduce guest_access.h
xen/riscv: introduce irq.h
xen/riscv: introduce p2m.h
xen/riscv: introduce regs.h
xen/riscv: introduce time.h
xen/riscv: introduce event.h
xen/riscv: introduce monitor.h
xen/riscv: add definition of __read_mostly xen/riscv: define an address of frame table xen/riscv: add required things to current.h xen/riscv: add minimal stuff to page.h to build full Xen xen/riscv: add minimal stuff to processor.h to build full Xen xen/riscv: add minimal stuff to mm.h to build full Xen xen/rirscv: add minimal amount of stubs to build full Xen xen/riscv: enable full Xen build
xen/README: add compiler and binutils versions for RISC-V64
README | 3 +
.../gitlab-ci/riscv-fixed-randconfig.yaml | 27 +
xen/arch/arm/include/asm/Makefile | 1 +
xen/arch/ppc/include/asm/Makefile | 1 +
xen/arch/ppc/include/asm/nospec.h | 15 -
xen/arch/ppc/include/asm/p2m.h | 3 +-
xen/arch/riscv/Kconfig | 1 +
xen/arch/riscv/Makefile | 17 +-
xen/arch/riscv/arch.mk | 4 -
xen/arch/riscv/configs/tiny64_defconfig | 18 +
xen/arch/riscv/early_printk.c | 168 ------
xen/arch/riscv/include/asm/Makefile | 14 +
xen/arch/riscv/include/asm/atomic.h | 384 ++++++++++++++
xen/arch/riscv/include/asm/bitops.h | 267 ++++++++++
xen/arch/riscv/include/asm/cache.h | 2 +
xen/arch/riscv/include/asm/cmpxchg.h | 496 ++++++++++++++++++
xen/arch/riscv/include/asm/config.h | 87 +--
xen/arch/riscv/include/asm/cpufeature.h | 23 +
xen/arch/riscv/include/asm/current.h | 19 +
xen/arch/riscv/include/asm/domain.h | 53 ++
xen/arch/riscv/include/asm/event.h | 40 ++
xen/arch/riscv/include/asm/fence.h | 22 +
xen/arch/riscv/include/asm/flushtlb.h | 33 ++
xen/arch/riscv/include/asm/guest_access.h | 29 +
xen/arch/riscv/include/asm/guest_atomics.h | 49 ++
xen/arch/riscv/include/asm/io.h | 142 +++++
xen/arch/riscv/include/asm/irq.h | 37 ++
xen/arch/riscv/include/asm/mm.h | 249 ++++++++-
xen/arch/riscv/include/asm/monitor.h | 26 +
xen/arch/riscv/include/asm/p2m.h | 102 ++++
xen/arch/riscv/include/asm/page.h | 22 +
xen/arch/riscv/include/asm/processor.h | 15 +
xen/arch/riscv/include/asm/regs.h | 29 +
xen/arch/riscv/include/asm/setup.h | 17 +
xen/arch/riscv/include/asm/smp.h | 28 +
xen/arch/riscv/include/asm/system.h | 90 ++++
xen/arch/riscv/include/asm/time.h | 29 +
xen/arch/riscv/mm.c | 52 +-
xen/arch/riscv/setup.c | 9 +-
xen/arch/riscv/stubs.c | 422 +++++++++++++++
xen/arch/riscv/traps.c | 25 +
xen/common/Kconfig | 3 +
xen/include/asm-generic/bitops/bitops-bits.h | 10 +
xen/include/asm-generic/bitops/ffs.h | 9 +
xen/include/asm-generic/bitops/ffz.h | 13 +
.../asm-generic/bitops/find-first-bit-set.h | 17 +
xen/include/asm-generic/bitops/fls.h | 18 +
xen/include/asm-generic/bitops/flsl.h | 10 +
xen/include/asm-generic/bitops/hweight.h | 13 +
xen/include/asm-generic/bitops/test-bit.h | 16 +
.../asm => include/asm-generic}/nospec.h | 10 +-
xen/include/public/hvm/save.h | 4 +-
xen/include/xen/iommu.h | 4 +
xen/lib/Makefile | 1 +
xen/lib/find-next-bit.c | 281 ++++++++++
55 files changed, 3248 insertions(+), 231 deletions(-)
delete mode 100644 xen/arch/ppc/include/asm/nospec.h
create mode 100644 xen/arch/riscv/include/asm/Makefile
create mode 100644 xen/arch/riscv/include/asm/atomic.h
create mode 100644 xen/arch/riscv/include/asm/bitops.h
create mode 100644 xen/arch/riscv/include/asm/cmpxchg.h
create mode 100644 xen/arch/riscv/include/asm/cpufeature.h
create mode 100644 xen/arch/riscv/include/asm/domain.h
create mode 100644 xen/arch/riscv/include/asm/event.h
create mode 100644 xen/arch/riscv/include/asm/fence.h
create mode 100644 xen/arch/riscv/include/asm/flushtlb.h
create mode 100644 xen/arch/riscv/include/asm/guest_access.h
create mode 100644 xen/arch/riscv/include/asm/guest_atomics.h
create mode 100644 xen/arch/riscv/include/asm/io.h
create mode 100644 xen/arch/riscv/include/asm/irq.h
create mode 100644 xen/arch/riscv/include/asm/monitor.h
create mode 100644 xen/arch/riscv/include/asm/p2m.h
create mode 100644 xen/arch/riscv/include/asm/regs.h
create mode 100644 xen/arch/riscv/include/asm/setup.h
create mode 100644 xen/arch/riscv/include/asm/smp.h
create mode 100644 xen/arch/riscv/include/asm/system.h
create mode 100644 xen/arch/riscv/include/asm/time.h
create mode 100644 xen/arch/riscv/stubs.c
create mode 100644 xen/include/asm-generic/bitops/bitops-bits.h
create mode 100644 xen/include/asm-generic/bitops/ffs.h
create mode 100644 xen/include/asm-generic/bitops/ffz.h
create mode 100644 xen/include/asm-generic/bitops/find-first-bit-set.h
create mode 100644 xen/include/asm-generic/bitops/fls.h
create mode 100644 xen/include/asm-generic/bitops/flsl.h
create mode 100644 xen/include/asm-generic/bitops/hweight.h
create mode 100644 xen/include/asm-generic/bitops/test-bit.h
rename xen/{arch/arm/include/asm => include/asm-generic}/nospec.h (54%)
create mode 100644 xen/lib/find-next-bit.cSignature · 1 line
2.43.0
PATCH v3 1/34 xen/riscv: disable unnecessary configs
This patch disables unnecessary configs for two cases:
1. By utilizing EXTRA_FIXED_RANDCONFIG and risc-fixed-randconfig.yaml file for randconfig builds (GitLab CI jobs).
2. By using tiny64_defconfig for non-randconfig builds.
---
Changes in V3:
- Remove EXTRA_FIXED_RANDCONFIG for non-randconfig jobs.
For non-randconfig jobs, it is sufficient to disable configs by using the defconfig.
- Remove double blank lines in build.yaml file before archlinux-current-gcc-riscv64-debug
---
Changes in V2:
- update the commit message.
- remove xen/arch/riscv/Kconfig changes.
--- .../gitlab-ci/riscv-fixed-randconfig.yaml | 27 +++++++++++++++++++ xen/arch/riscv/configs/tiny64_defconfig | 17 ++++++++++++ 2 files changed, 44 insertions(+)
automation/gitlab-ci/riscv-fixed-randconfig.yaml +27 -0
@@ -5,3 +5,30 @@ CONFIG_EXPERT=y CONFIG_GRANT_TABLE=n CONFIG_MEM_ACCESS=n + CONFIG_COVERAGE=n + CONFIG_SCHED_CREDIT=n + CONFIG_SCHED_CREDIT2=n + CONFIG_SCHED_RTDS=n + CONFIG_SCHED_NULL=n + CONFIG_SCHED_ARINC653=n + CONFIG_TRACEBUFFER=n + CONFIG_HYPFS=n + CONFIG_SPECULATIVE_HARDEN_ARRAY=n + CONFIG_ARGO=n + CONFIG_HYPFS_CONFIG=n + CONFIG_CORE_PARKING=n + CONFIG_DEBUG_TRACE=n + CONFIG_IOREQ_SERVER=n + CONFIG_CRASH_DEBUG=n + CONFIG_KEXEC=n + CONFIG_LIVEPATCH=n + CONFIG_NUMA=n + CONFIG_PERF_COUNTERS=n + CONFIG_HAS_PMAP=n + CONFIG_TRACEBUFFER=n + CONFIG_XENOPROF=n + CONFIG_COMPAT=n + CONFIG_COVERAGE=n + CONFIG_UBSAN=n + CONFIG_NEEDS_LIBELF=n + CONFIG_XSM=n
xen/arch/riscv/configs/tiny64_defconfig +17 -0
@@ -7,6 +7,23 @@ # CONFIG_GRANT_TABLE is not set # CONFIG_SPECULATIVE_HARDEN_ARRAY is not set # CONFIG_MEM_ACCESS is not set +# CONFIG_ARGO is not set +# CONFIG_HYPFS_CONFIG is not set +# CONFIG_CORE_PARKING is not set +# CONFIG_DEBUG_TRACE is not set +# CONFIG_IOREQ_SERVER is not set +# CONFIG_CRASH_DEBUG is not setz +# CONFIG_KEXEC is not set +# CONFIG_LIVEPATCH is not set +# CONFIG_NUMA is not set +# CONFIG_PERF_COUNTERS is not set +# CONFIG_HAS_PMAP is not set +# CONFIG_TRACEBUFFER is not set +# CONFIG_XENOPROF is not set +# CONFIG_COMPAT is not set +# CONFIG_COVERAGE is not set +# CONFIG_UBSAN is not set +# CONFIG_NEEDS_LIBELF is not set CONFIG_RISCV_64=y CONFIG_DEBUG=y
Signature · 1 line
2.43.0
PATCH v3 2/34 xen/riscv: use some asm-generic headers
In reply to Oleksii KurochkoSome headers are the same as asm-generic verions of them so use them instead of arch-specific headers.
---
As [PATCH v6 0/9] Introduce generic headers
(https://lore.kernel.org/xen-devel/[email protected]/)
is not stable, the list in asm/Makefile can be changed, but the changes will be easy.
---
Changes in V3:
- remove monitor.h from the RISC-V asm/Makefile list.
- add Acked-by: Jan Beulich <[email protected]>
---
Changes in V2:
- New commit introduced in V2.
--- xen/arch/riscv/include/asm/Makefile | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 xen/arch/riscv/include/asm/Makefile
xen/arch/riscv/include/asm/Makefile new file +13 -0
@@ -0,0 +1,13 @@ +# SPDX-License-Identifier: GPL-2.0-only +generic-y += altp2m.h +generic-y += device.h +generic-y += div64.h +generic-y += hardirq.h +generic-y += hypercall.h +generic-y += iocap.h +generic-y += numa.h +generic-y += paging.h +generic-y += percpu.h +generic-y += random.h +generic-y += softirq.h +generic-y += vm_event.h
Signature · 1 line
2.43.0
PATCH v3 3/34 xen: add support in public/hvm/save.h for PPC and RISC-V
In reply to Oleksii Kurochko---
Changes in V3:
- update the commit message.
- For PPC and RISC-V nothing to include in public/hvm/save.h, so just comment was added.
---
Changes in V2:
- remove copyright an the top of hvm/save.h as the header write now is a newly introduced empty header.
--- xen/include/public/hvm/save.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
xen/include/public/hvm/save.h +2 -2
@@ -89,8 +89,8 @@ DECLARE_HVM_SAVE_TYPE(END, 0, struct hvm_save_end);#include "../arch-x86/hvm/save.h" #elif defined(__arm__) || defined(__aarch64__)#include "../arch-arm/hvm/save.h" -#elif defined(__powerpc64__) -#include "../arch-ppc.h" +#elif defined(__powerpc64__) || defined(__riscv) +/* no specific header to include */ #else #error "unsupported architecture"#endif
Signature · 1 line
2.43.0
Re: [PATCH v3 03/34] xen: add support in public/hvm/save.h for PPC and RISC-V
Quoted 1 line · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>
Since you change how PPC is handled, this can't go without description (i.e. justification).
Jan
Quoted 13 lines
xen/include/public/hvm/save.h +2
-2@@ -89,8 +89,8 @@ DECLARE_HVM_SAVE_TYPE(END, 0, struct hvm_save_end);#include "../arch-x86/hvm/save.h" #elif defined(__arm__) || defined(__aarch64__)#include "../arch-arm/hvm/save.h" -#elif defined(__powerpc64__) -#include "../arch-ppc.h" +#elif defined(__powerpc64__) || defined(__riscv) +/* no specific header to include */ #else #error "unsupported architecture"#endif
Re: [PATCH v3 03/34] xen: add support in public/hvm/save.h for PPC and RISC-V
Quoted 6 lines · Jan Beulich
Quoted 1 line · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>Since you change how PPC is handled, this can't go without description (i.e.
justification).
I thought adding a comment in the code would be sufficient. I can include something similar in the commit message as well.
~ Oleksii
Quoted 16 lines
Quoted 15 lines
xen/include/public/hvm/save.h +2
-2@@ -89,8 +89,8 @@ DECLARE_HVM_SAVE_TYPE(END, 0, struct hvm_save_end); #include "../arch-x86/hvm/save.h" #elif defined(__arm__) || defined(__aarch64__) #include "../arch-arm/hvm/save.h" -#elif defined(__powerpc64__) -#include "../arch-ppc.h" +#elif defined(__powerpc64__) || defined(__riscv) +/* no specific header to include */ #else #error "unsupported architecture"#endif
PATCH v3 4/34 xen/riscv: introduce cpufeature.h
In reply to Oleksii Kurochko---
Changes in V3:
- add SPDX and footer
- update declaration of cpu_nr_siblings() to return unsigned int instead of int.
- add Acked-by: Jan Beulich <[email protected]>
---
Changes in V2:
- Nothing changed. Only rebase.
--- xen/arch/riscv/include/asm/cpufeature.h | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 xen/arch/riscv/include/asm/cpufeature.h
xen/arch/riscv/include/asm/cpufeature.h new file +23 -0
@@ -0,0 +1,23 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_RISCV_CPUFEATURE_H +#define __ASM_RISCV_CPUFEATURE_H + +#ifndef __ASSEMBLY__ + +static inline unsigned int cpu_nr_siblings (unsigned int cpu) +{ +return 1 ; +} + +#endif /* __ASSEMBLY__ */ + +#endif /* __ASM_RISCV_CPUFEATURE_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
2.43.0
PATCH v3 5/34 xen/riscv: introduce guest_atomics.h
In reply to Oleksii Kurochko---
Changes in V3:
- update the commit message
- drop TODO commit.
- add ASSERT_UNREACHABLE for stubs guest functions.
- Add SPDX & footer
---
Changes in V2:
- Nothing changed. Only rebase.
--- xen/arch/riscv/include/asm/guest_atomics.h | 49 ++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 xen/arch/riscv/include/asm/guest_atomics.h
xen/arch/riscv/include/asm/guest_atomics.h new file +49 -0
@@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_RISCV_GUEST_ATOMICS_H +#define __ASM_RISCV_GUEST_ATOMICS_H + +#define guest_testop (name) \ +static inline int guest_##name(struct domain *d, int nr, volatile void *p) \ +{ \ + (void) d; \ + (void) nr; \ + (void) p; \ + \ + ASSERT_UNREACHABLE(); \ + \ + return 0; \ +} + +#define guest_bitop (name) \ +static inline void guest_##name(struct domain *d, int nr, volatile void *p) \ +{ \ + (void) d; \ + (void) nr; \ + (void) p; \ + ASSERT_UNREACHABLE(); \ +} + +guest_bitop(set_bit) +guest_bitop(clear_bit) +guest_bitop(change_bit) + +#undef guest_bitop + +guest_testop(test_and_set_bit) +guest_testop(test_and_clear_bit) +guest_testop(test_and_change_bit) + +#undef guest_testop + +#define guest_test_bit (d, nr, p) ((void)(d), test_bit(nr, p)) + +#endif /* __ASM_RISCV_GUEST_ATOMICS_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
2.43.0
Re: [PATCH v3 05/34] xen/riscv: introduce guest_atomics.h
Quoted 4 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- update the commit message
There (still) is none - what is the above about?
xen/arch/riscv/include/asm/guest_atomics.h line 10
Quoted 13 lines
xen/arch/riscv/include/asm/guest_atomics.h new file +10
-0@@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_RISCV_GUEST_ATOMICS_H +#define __ASM_RISCV_GUEST_ATOMICS_H + +#define guest_testop (name) \ +static inline int guest_##name(struct domain *d, int nr, volatile void *p) \ +{ \ + (void) d; \ + (void) nr; \ + (void) p; \
What are these and ...
xen/arch/riscv/include/asm/guest_atomics.h line 22
Quoted 11 lines
xen/arch/riscv/include/asm/guest_atomics.h new file +11
-0+ASSERT_UNREACHABLE (); \ + \ +return 0 ; \ +} + +#define guest_bitop (name) \ +static inline void guest_##name(struct domain *d, int nr, volatile void *p) \ +{ \ + (void) d; \ + (void) nr; \ + (void) p; \
... these about? If there's a reason for having them, then (nit) there are stray blanks.
Jan
Re: [PATCH v3 05/34] xen/riscv: introduce guest_atomics.h
Quoted 7 lines · Jan Beulich
Quoted 4 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- update the commit messageThere (still) is none - what is the above about?
Missed something. I'll double check during providing the next patch version.
Quoted 42 lines
Quoted 13 lines
xen/arch/riscv/include/asm/guest_atomics.h new file +5
-0@@ -0,0 +1,49 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_RISCV_GUEST_ATOMICS_H +#define __ASM_RISCV_GUEST_ATOMICS_H + +#define
guest_testop(name)
\
+static inline int guest_##name(struct domain *d, int nr, volatile void *p) \Quoted 8 lines
+{
\
+ (void)
d; \
+ (void)
nr; \
+ (void)
p; \What are these and ...
Quoted 18 lines
+
ASSERT_UNREACHABLE();
\
+
\
+ return
0; \xen/arch/riscv/include/asm/guest_atomics.h new file +3
-0+} + +#define
guest_bitop(name)
\
+static inline void guest_##name(struct domain *d, int nr, volatile void *p) \
+{
\
+ (void)
d; \
Quoted 8 lines
Quoted 4 lines
+ (void)
nr; \
+ (void)
p; \... these about? If there's a reason for having them, then (nit) there
are stray blanks.
It is only one reason for that to show that args are unused for time being.
But I think I can drop these changes.
~ Oleksii
PATCH v3 6/34 xen: avoid generation of empty asm/iommu.h
In reply to Oleksii Kurochko---
Changes in V3:
- new patch.
--- xen/include/xen/iommu.h | 4 ++++ 1 file changed, 4 insertions(+)
xen/include/xen/iommu.h +4 -0
@@ -337,7 +337,9 @@ extern int iommu_add_extra_reserved_device_memory(unsigned long start,extern int iommu_get_extra_reserved_device_memory (iommu_grdm_t *func,void *ctxt); +#ifdef CONFIG_HAS_PASSTHROUGH #include <asm/iommu.h> +#endif #ifndef iommu_call # define iommu_call(ops, fn, args...) ((ops)->fn(args))
@@ -345,7 +347,9 @@ extern int iommu_get_extra_reserved_device_memory(iommu_grdm_t *func,#endif struct domain_iommu { +#ifdef CONFIG_HAS_PASSTHROUGH struct arch_iommu arch; +#endif /* iommu_ops */ const struct iommu_ops *platform_ops;
Signature · 1 line
2.43.0
Re: [PATCH v3 06/34] xen: avoid generation of empty asm/iommu.h
Quoted 1 line · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>
The change looks okay-ish, but again needs a description: You want to explain why you use the absolute minimum of the scopes the two (or, in principle, possibly more) #ifdef-s cover.
Jan
Quoted 22 lines
xen/include/xen/iommu.h +4
-0@@ -337,7 +337,9 @@ extern int iommu_add_extra_reserved_device_memory(unsigned long start,extern int iommu_get_extra_reserved_device_memory (iommu_grdm_t *func,void *ctxt); +#ifdef CONFIG_HAS_PASSTHROUGH #include <asm/iommu.h> +#endif #ifndef iommu_call # define iommu_call(ops, fn, args...) ((ops)->fn(args))@@ -345,7 +347,9 @@ extern int iommu_get_extra_reserved_device_memory(iommu_grdm_t *func,#endif struct domain_iommu { +#ifdef CONFIG_HAS_PASSTHROUGH struct arch_iommu arch; +#endif /* iommu_ops */ const struct iommu_ops *platform_ops;
Re: [PATCH v3 06/34] xen: avoid generation of empty asm/iommu.h
Quoted 6 lines · Jan Beulich
Quoted 1 line · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>The change looks okay-ish, but again needs a description: You want to explain why you use the absolute minimum of the scopes the two (or, in principle, possibly more) #ifdef-s cover.
Sure, I'll add a description to the commit message.
~ Oleksii
Quoted 26 lines
Quoted 25 lines
xen/include/xen/iommu.h +0
-0@@ -337,7 +337,9 @@ extern int iommu_add_extra_reserved_device_memory(unsigned long start,extern int iommu_get_extra_reserved_device_memory(iommu_grdm_t *func,
void *ctxt);
+#ifdefCONFIG_HAS_PASSTHROUGH
#include <asm/iommu.h>
+#endif
#ifndefiommu_call# define iommu_call(ops, fn, args...) ((ops)->fn(args))xen/include/xen/iommu.h +0
-0@@ -345,7 +347,9 @@ extern int iommu_get_extra_reserved_device_memory(iommu_grdm_t *func, #endif
structdomain_iommu{
+#ifdefCONFIG_HAS_PASSTHROUGH
structarch_iommuarch;
+#endif
/*iommu_ops*/
const structiommu_ops*platform_ops;
PATCH v3 7/34 xen/asm-generic: introdure nospec.h
In reply to Oleksii KurochkoThe <asm/nospec.h> header is similar between Arm, PPC, and RISC-V, so it has been moved to asm-generic.
---
Changes in V3:
- new patch.
---
xen/arch/arm/include/asm/Makefile | 1 +
xen/arch/ppc/include/asm/Makefile | 1 +
xen/arch/ppc/include/asm/nospec.h | 15 ---------------
xen/arch/riscv/include/asm/Makefile | 1 +
.../include/asm => include/asm-generic}/nospec.h | 10 +++++-----
5 files changed, 8 insertions(+), 20 deletions(-)
delete mode 100644 xen/arch/ppc/include/asm/nospec.h
rename xen/{arch/arm/include/asm => include/asm-generic}/nospec.h (54%)xen/arch/arm/include/asm/Makefile +1 -0
@@ -3,6 +3,7 @@ generic-y += altp2m.h generic-y += device.h generic-y += hardirq.h generic-y += iocap.h +generic-y += nospec.h generic-y += numa.h generic-y += paging.h generic-y += percpu.h
xen/arch/ppc/include/asm/Makefile +1 -0
@@ -5,6 +5,7 @@ generic-y += div64.h generic-y += hardirq.h generic-y += hypercall.h generic-y += iocap.h +generic-y += nospec.h generic-y += numa.h generic-y += paging.h generic-y += percpu.h
xen/arch/ppc/include/asm/nospec.h deleted +0 -15
@@ -1,15 +0,0 @@ -/* SPDX-License-Identifier: GPL-2.0-only */ -/* From arch/arm/include/asm/nospec.h. */ -#ifndef __ASM_PPC_NOSPEC_H__ -#define __ASM_PPC_NOSPEC_H__ - -static inline bool evaluate_nospec (bool condition) -{ -return condition; -} - -static inline void block_speculation (void ) -{ -} - -#endif /* __ASM_PPC_NOSPEC_H__ */
xen/arch/riscv/include/asm/Makefile +1 -0
@@ -5,6 +5,7 @@ generic-y += div64.h generic-y += hardirq.h generic-y += hypercall.h generic-y += iocap.h +generic-y += nospec.h generic-y += numa.h generic-y += paging.h generic-y += percpu.h
xen/include/asm-generic/nospec.h renamed from xen/arch/arm/include/asm/nospec.h +5 -5
@@ -1,8 +1,8 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. */ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASM_GENERIC_NOSPEC_H +#define _ASM_GENERIC_NOSPEC_H -#ifndef _ASM_ARM_NOSPEC_H -#define _ASM_ARM_NOSPEC_H +#include <xen/stdbool.h> static inline bool evaluate_nospec (bool condition) {
@@ -13,7 +13,7 @@ static inline void block_speculation(void) { } -#endif /* _ASM_ARM_NOSPEC_H */ +#endif /* _ASM_GENERIC_NOSPEC_H */ /* * Local variables:
Signature · 1 line
2.43.0
Re: [PATCH v3 07/34] xen/asm-generic: introdure nospec.h
Quoted 4 lines · Oleksii Kurochko
The <
asm/nospec.h> header is similar between Arm, PPC, and RISC-V, so it has been moved to asm-generic.Signed-off-by Oleksii Kurochko <[email protected]>
A word may want saying though on ...
xen/include/asm-generic/nospec.h line 3
Quoted 8 lines
xen/include/asm-generic/nospec.h renamed from xen/arch/arm/include/asm/nospec.h +3
-2@@ -1,8 +1,8 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. */ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASM_GENERIC_NOSPEC_H +#define _ASM_GENERIC_NOSPEC_H
... the removal of the copyright line.
Jan
Re: [PATCH v3 07/34] xen/asm-generic: introdure nospec.h
Quoted 9 lines · Jan Beulich
Quoted 4 lines · Oleksii Kurochko
The <
asm/nospec.h> header is similar between Arm, PPC, and RISC-V, so it has been moved to asm-generic.Signed-off-by Oleksii Kurochko <[email protected]>Acked-by Jan Beulich <[email protected]>A word may want saying though on ...
Quoted 9 lines
xen/include/asm-generic/nospec.h line 3
Quoted 8 lines
xen/include/asm-generic/nospec.h renamed from xen/arch/arm/include/asm/nospec.h +3
-2@@ -1,8 +1,8 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. */ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASM_GENERIC_NOSPEC_H +#define _ASM_GENERIC_NOSPEC_H... the removal of the copyright line.
That isn't a removal of ARM's copyright line.
The two files are similar enough to trigger git-diff's "this was a rename" logic (see the a vs b paths), despite not being a rename.
It's unfortunate rendering in this case.
~Andrew
Re: [PATCH v3 07/34] xen/asm-generic: introdure nospec.h
Quoted 20 lines · Andrew Cooper
Quoted 9 lines · Jan Beulich
Quoted 4 lines · Oleksii Kurochko
The <
asm/nospec.h> header is similar between Arm, PPC, and RISC-V, so it has been moved to asm-generic.Signed-off-by Oleksii Kurochko <[email protected]>Acked-by Jan Beulich <[email protected]>A word may want saying though on ...
Quoted 9 lines
xen/include/asm-generic/nospec.h line 3
Quoted 8 lines
xen/include/asm-generic/nospec.h renamed from xen/arch/arm/include/asm/nospec.h +3
-2@@ -1,8 +1,8 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. */ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASM_GENERIC_NOSPEC_H +#define _ASM_GENERIC_NOSPEC_H... the removal of the copyright line.
Quoted 6 lines
That isn't a removal of ARM's copyright line.
The two files are similar enough to trigger git-diff's "this was a rename" logic (see the a vs b paths), despite not being a rename.
It's unfortunate rendering in this case.
Hmm, well, might be. If I had done such a change, I surely wouldn't have created the file anew, but rather moved one of the existing instances. Even if it was PPC's that was moved, that was (likely) cloned from Arm's as well.
Jan
Re: [PATCH v3 07/34] xen/asm-generic: introdure nospec.h
In reply to Jan BeulichQuoted 10 lines · Jan Beulich
Quoted 4 lines · Oleksii Kurochko
The <
asm/nospec.h> header is similar between Arm, PPC, and RISC-V, so it has been moved to asm-generic.Signed-off-by Oleksii Kurochko <[email protected]>Acked-by Jan Beulich <[email protected]>A word may want saying though on ...
Quoted 11 lines
xen/include/asm-generic/nospec.h line 3
Quoted 9 lines
xen/include/asm-generic/nospec.h renamed from xen/arch/arm/include/asm/nospec.h +0
-2@@ -1,8 +1,8 @@ -/* SPDX-License-Identifier: GPL-2.0 */ -/* Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved. */
xen/include/asm-generic/nospec.h renamed from xen/arch/arm/include/asm/nospec.h +3
-0+/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef _ASM_GENERIC_NOSPEC_H +#define _ASM_GENERIC_NOSPEC_H... the removal of the copyright line.
It was automatically decided by Git to do it this way.
I'll try to make it generate a new file instead of moving/renaming Arm's nospec.h.
~ Oleksii
Re: [PATCH v3 07/34] xen/asm-generic: introdure nospec.h
In reply to Oleksii KurochkoHi Oleksii,
Quoted 4 lines · Oleksii Kurochko
The <
asm/nospec.h> header is similar between Arm, PPC, and RISC-V, so it has been moved to asm-generic.Signed-off-by Oleksii Kurochko <[email protected]>
Thanks,
Shawn
PATCH v3 8/34 xen/riscv: introduce setup.h
In reply to Oleksii Kurochko---
Changes in V3:
- add SPDX
- add Acked-by: Jan Beulich <[email protected]>
---
Changes in V2:
- Nothing changed. Only rebase.
--- xen/arch/riscv/include/asm/setup.h | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 xen/arch/riscv/include/asm/setup.h
xen/arch/riscv/include/asm/setup.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef __ASM_RISCV_SETUP_H__ +#define __ASM_RISCV_SETUP_H__ + +#define max_init_domid (0) + +#endif /* __ASM_RISCV_SETUP_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
2.43.0
PATCH v3 9/34 xen/riscv: introduce system.h
In reply to Oleksii Kurochko---
Changes in V3:
- Add SPDX
- fix code style issue
- change prototype of local_irq_is_enabled to return bool. update the return code.
- update the code style
---
Changes in V2:
- Nothing changed. Only rebase.
--- xen/arch/riscv/include/asm/system.h | 90 +++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 xen/arch/riscv/include/asm/system.h
xen/arch/riscv/include/asm/system.h new file +90 -0
@@ -0,0 +1,90 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _ASM_RISCV_BARRIER_H +#define _ASM_RISCV_BARRIER_H + +#include <xen/stdbool.h> + +#include <asm/csr.h> + +#ifndef __ASSEMBLY__ + +#define RISCV_FENCE (p, s) \ + __asm__ __volatile__ ( "fence " #p "," #s : : : "memory" ) + +/* These barriers need to enforce ordering on both devices or memory. */ +#define mb () RISCV_FENCE(iorw, iorw) +#define rmb () RISCV_FENCE(ir, ir) +#define wmb () RISCV_FENCE(ow, ow) + +/* These barriers do not need to enforce ordering on devices, just memory. */ +#define smp_mb () RISCV_FENCE(rw, rw) +#define smp_rmb () RISCV_FENCE(r, r) +#define smp_wmb () RISCV_FENCE(w, w) +#define smp_mb__before_atomic () smp_mb() +#define smp_mb__after_atomic () smp_mb() + +/* +#define smp_store_release(p, v) \ +do { \ +compiletime_assert_atomic_type(*p); \ +RISCV_FENCE(rw, w); \ +WRITE_ONCE(*p, v); \ +} while (0) + +#define smp_load_acquire(p) \ +({ \ +typeof(*p) p1 = READ_ONCE(*p); \ +compiletime_assert_atomic_type(*p); \ +RISCV_FENCE(r,rw); \ +p1; \ +}) +*/ + +static inline unsigned long local_save_flags (void ) +{ +return csr_read (sstatus); +} + +static inline void local_irq_enable (void ) +{ +csr_set (sstatus,SSTATUS_SIE ); +} + +static inline void local_irq_disable (void ) +{ +csr_clear (sstatus,SSTATUS_SIE ); +} + +#define local_irq_save (x) \ +({ \ + x = csr_read_clear(CSR_SSTATUS, SSTATUS_SIE); \ + local_irq_disable(); \ +}) + +static inline void local_irq_restore (unsigned long flags) +{ +csr_set (CSR_SSTATUS , flags &SSTATUS_SIE ); +} + +static inline bool local_irq_is_enabled (void ) +{ +unsigned long flags =local_save_flags (); + +return (flags &SSTATUS_SIE ) !=0 ; +} + +#define arch_fetch_and_add (x, v) __sync_fetch_and_add(x, v) + +#endif /* __ASSEMBLY__ */ + +#endif /* _ASM_RISCV_BARRIER_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
2.43.0
Re: [PATCH v3 09/34] xen/riscv: introduce system.h
xen/arch/riscv/include/asm/system.h line 4
Quoted 7 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/system.h new file +4
-0@@ -0,0 +1,90 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _ASM_RISCV_BARRIER_H +#define _ASM_RISCV_BARRIER_H
s/BARRIER/SYSTEM/ ?
With that taken care of (which I'd be happy to do while committing)
Quoted 59 lines
xen/arch/riscv/include/asm/system.h new file +59
-0+#include <xen/stdbool.h> + +#include <asm/csr.h> + +#ifndef __ASSEMBLY__ + +#define RISCV_FENCE (p, s) \ + __asm__ __volatile__ ( "fence " #p "," #s : : : "memory" ) + +/* These barriers need to enforce ordering on both devices or memory. */ +#define mb () RISCV_FENCE(iorw, iorw) +#define rmb () RISCV_FENCE(ir, ir) +#define wmb () RISCV_FENCE(ow, ow) + +/* These barriers do not need to enforce ordering on devices, just memory. */ +#define smp_mb () RISCV_FENCE(rw, rw) +#define smp_rmb () RISCV_FENCE(r, r) +#define smp_wmb () RISCV_FENCE(w, w) +#define smp_mb__before_atomic () smp_mb() +#define smp_mb__after_atomic () smp_mb() + +/* +#define smp_store_release(p, v) \ +do { \ +compiletime_assert_atomic_type(*p); \ +RISCV_FENCE(rw, w); \ +WRITE_ONCE(*p, v); \ +} while (0) + +#define smp_load_acquire(p) \ +({ \ +typeof(*p) p1 = READ_ONCE(*p); \ +compiletime_assert_atomic_type(*p); \ +RISCV_FENCE(r,rw); \ +p1; \ +}) +*/ + +static inline unsigned long local_save_flags (void ) +{ +return csr_read (sstatus); +} + +static inline void local_irq_enable (void ) +{ +csr_set (sstatus,SSTATUS_SIE ); +} + +static inline void local_irq_disable (void ) +{ +csr_clear (sstatus,SSTATUS_SIE ); +} + +#define local_irq_save (x) \ +({ \ + x = csr_read_clear(CSR_SSTATUS, SSTATUS_SIE); \ + local_irq_disable(); \ +}) +
xen/arch/riscv/include/asm/system.h line 74
Quoted 10 lines
xen/arch/riscv/include/asm/system.h new file +10
-0+static inline void local_irq_restore (unsigned long flags) +{ +csr_set (CSR_SSTATUS , flags &SSTATUS_SIE ); +} + +static inline bool local_irq_is_enabled (void ) +{ +unsigned long flags =local_save_flags (); + +return (flags &SSTATUS_SIE ) !=0 ;
Just as a remark - when the resulting type is bool, we generally prefer to omit the "!= 0".
Jan
Re: [PATCH v3 09/34] xen/riscv: introduce system.h
Quoted 10 lines · Jan Beulich
xen/arch/riscv/include/asm/system.h line 4
Quoted 7 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/system.h new file +4
-0@@ -0,0 +1,90 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#ifndef _ASM_RISCV_BARRIER_H +#define _ASM_RISCV_BARRIER_Hs/BARRIER/SYSTEM/ ?
Yes, it should be SYSTEM. Thanks for noticing that.
Quoted 3 lines
With that taken care of (which I'd be happy to do while committing)
Acked-by Jan Beulich <[email protected]>
Thanks a lot. I'll be happy with that.
Quoted 67 lines
Quoted 67 lines
xen/arch/riscv/include/asm/system.h new file +10
-0+#include <xen/stdbool.h> + +#include <asm/csr.h> + +#ifndef __ASSEMBLY__ + +#define RISCV_FENCE (p, s) \ + __asm__ __volatile__ ( "fence " #p "," #s : : : "memory" ) + +/* These barriers need to enforce ordering on both devices or memory. */
xen/arch/riscv/include/asm/system.h new file +5
-0+#define mb () RISCV_FENCE(iorw, iorw) +#define rmb () RISCV_FENCE(ir, ir) +#define wmb () RISCV_FENCE(ow, ow) + +/* These barriers do not need to enforce ordering on devices, just memory. */
xen/arch/riscv/include/asm/system.h new file +49
-0+#define smp_mb () RISCV_FENCE(rw, rw) +#define smp_rmb () RISCV_FENCE(r, r) +#define smp_wmb () RISCV_FENCE(w, w) +#define smp_mb__before_atomic () smp_mb() +#define smp_mb__after_atomic () smp_mb() + +/* +#define smp_store_release(p, v) \ +do { \ +compiletime_assert_atomic_type(*p); \ +RISCV_FENCE(rw, w); \ +WRITE_ONCE(*p, v); \ +} while (0) + +#define smp_load_acquire(p) \ +({ \ +typeof(*p) p1 = READ_ONCE(*p); \ +compiletime_assert_atomic_type(*p); \ +RISCV_FENCE(r,rw); \ +p1; \ +}) +*/ + +static inline unsigned long local_save_flags (void ) +{ + return csr_read(sstatus); +} + +static inline void local_irq_enable (void ) +{ + csr_set(sstatus, SSTATUS_SIE); +} + +static inline void local_irq_disable (void ) +{ + csr_clear(sstatus, SSTATUS_SIE); +} + +#define local_irq_save (x) \ +({ \ + x = csr_read_clear(CSR_SSTATUS, SSTATUS_SIE); \ + local_irq_disable(); \ +}) + +static inline void local_irq_restore (unsigned long flags) +{ +csr_set (CSR_SSTATUS , flags &SSTATUS_SIE ); +} +
Quoted 8 lines
xen/arch/riscv/include/asm/system.h line 74
Quoted 5 lines
xen/arch/riscv/include/asm/system.h new file +5
-0+static inline bool local_irq_is_enabled (void ) +{ + unsigned long flags = local_save_flags(); + + return (flags & SSTATUS_SIE) != 0;Just as a remark - when the resulting type is bool, we generally prefer to omit the "!= 0".
Thanks. I'll take into account that.
~ Oleksii
PATCH v3 10/34 xen/riscv: introduce bitops.h
In reply to Oleksii KurochkoTaken from Linux-6.4.0-rc1
Xen's bitops.h consists of several Linux's headers:
* linux/arch/include/asm/bitops.h:
* The following function were removed as they aren't used in Xen:
* test_and_change_bit
* test_and_set_bit_lock
* clear_bit_unlock
* __clear_bit_unlock
* The following functions were renamed in the way how they are used by common code:
* __test_and_set_bit
* __test_and_clear_bit
* The declaration and implementation of the following functios were updated to make Xen build happy:
* clear_bit
* set_bit
* __test_and_clear_bit
* __test_and_set_bit
* linux/include/asm-generic/bitops/find.h ( only few function declaration were taken, as implementation will be provided by Xen ).
* linux/arch/include/linux/bits.h ( taken only definitions for BIT_MASK, BIT_WORD, BITS_PER_BYTE )
Additionaly, the following bit ops are introduced:
* __ffs
* ffsl
* fls
* flsl
* ffs
* ffz
* find_first_bit_set
* hweight64
* test_bit
Some of the introduced bit operations are included in asm-generic, as they exhibit similarity across multiple architectures.
---
Changes in V3:
- update the commit message
- Introduce the following asm-generic bitops headers:
create mode 100644 xen/arch/riscv/include/asm/bitops.h create mode 100644 xen/include/asm-generic/bitops/bitops-bits.h create mode 100644 xen/include/asm-generic/bitops/ffs.h create mode 100644 xen/include/asm-generic/bitops/ffz.h create mode 100644 xen/include/asm-generic/bitops/find-first-bit-set.h create mode 100644 xen/include/asm-generic/bitops/fls.h create mode 100644 xen/include/asm-generic/bitops/flsl.h create mode 100644 xen/include/asm-generic/bitops/hweight.h create mode 100644 xen/include/asm-generic/bitops/test-bit.h
- switch some bitops functions to asm-generic's versions.
- re-sync some macros with Linux kernel version mentioned in the commit message.
- Xen code style fixes.
---
Changes in V2:
- Nothing changed. Only rebase.
--- xen/arch/riscv/include/asm/bitops.h | 267 ++++++++++++++++++ xen/include/asm-generic/bitops/bitops-bits.h | 10 + xen/include/asm-generic/bitops/ffs.h | 9 + xen/include/asm-generic/bitops/ffz.h | 13 + .../asm-generic/bitops/find-first-bit-set.h | 17 ++ xen/include/asm-generic/bitops/fls.h | 18 ++ xen/include/asm-generic/bitops/flsl.h | 10 + xen/include/asm-generic/bitops/hweight.h | 13 + xen/include/asm-generic/bitops/test-bit.h | 16 ++ 9 files changed, 373 insertions(+) create mode 100644 xen/arch/riscv/include/asm/bitops.h create mode 100644 xen/include/asm-generic/bitops/bitops-bits.h create mode 100644 xen/include/asm-generic/bitops/ffs.h create mode 100644 xen/include/asm-generic/bitops/ffz.h create mode 100644 xen/include/asm-generic/bitops/find-first-bit-set.h create mode 100644 xen/include/asm-generic/bitops/fls.h create mode 100644 xen/include/asm-generic/bitops/flsl.h create mode 100644 xen/include/asm-generic/bitops/hweight.h create mode 100644 xen/include/asm-generic/bitops/test-bit.h
xen/arch/riscv/include/asm/bitops.h new file +267 -0
@@ -0,0 +1,267 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2012 Regents of the University of California */ + +#ifndef _ASM_RISCV_BITOPS_H +#define _ASM_RISCV_BITOPS_H + +#include <asm/system.h> + +#include <asm-generic/bitops/bitops-bits.h> + +/* Based on linux/arch/include/linux/bits.h */ + +#define BIT_MASK (nr) (1UL << ((nr) % BITS_PER_LONG)) +#define BIT_WORD (nr) ((nr) / BITS_PER_LONG) + +#define __set_bit (n,p) set_bit(n,p) +#define __clear_bit (n,p) clear_bit(n,p) + +/* Based on linux/arch/include/asm/bitops.h */ + +#if (BITS_PER_LONG ==64 ) +#define __AMO (op) "amo" #op ".d" +#elif (BITS_PER_LONG ==32 ) +#define __AMO (op) "amo" #op ".w" +#else +#error "Unexpected BITS_PER_LONG" +#endif + +#define __test_and_op_bit_ord (op, mod, nr, addr, ord) \ +({ \ + unsigned long __res, __mask; \ + __mask = BIT_MASK(nr); \ + __asm__ __volatile__ ( \ + __AMO(op) #ord " %0, %2, %1" \ + : "=r" (__res), "+A" (addr[BIT_WORD(nr)]) \ + : "r" (mod(__mask)) \ + : "memory"); \ + ((__res & __mask) != 0); \ +}) + +#define __op_bit_ord (op, mod, nr, addr, ord) \ + __asm__ __volatile__ ( \ + __AMO(op) #ord " zero, %1, %0" \ + : "+A" (addr[BIT_WORD(nr)]) \ + : "r" (mod(BIT_MASK(nr))) \ + : "memory"); + +#define __test_and_op_bit (op, mod, nr, addr) \ + __test_and_op_bit_ord(op, mod, nr, addr, .aqrl) +#define __op_bit (op, mod, nr, addr) \ + __op_bit_ord(op, mod, nr, addr, ) + +/* Bitmask modifiers */ +#define __NOP (x) (x) +#define __NOT (x) (~(x)) + +/** +* __test_and_set_bit - Set a bit and return its old value +* @nr: Bit to set +* @addr: Address to count from +* +* This operation may be reordered on other architectures than x86. +*/ +static inline int __test_and_set_bit (int nr,volatile void *p) +{ +volatile uint32_t *addr = p; + +return __test_and_op_bit (or, __NOP, nr, addr); +} + +/** +* __test_and_clear_bit - Clear a bit and return its old value +* @nr: Bit to clear +* @addr: Address to count from +* +* This operation can be reordered on other architectures other than x86. +*/ +static inline int __test_and_clear_bit (int nr,volatile void *p) +{ +volatile uint32_t *addr = p; + +return __test_and_op_bit (and, __NOT, nr, addr); +} + +/** +* set_bit - Atomically set a bit in memory +* @nr: the bit to set +* @addr: the address to start counting from +* +* Note: there are no guarantees that this function will not be reordered +* on non x86 architectures, so if you are writing portable code, +* make sure not to rely on its reordering guarantees. +* +* Note that @nr may be almost arbitrarily large; this function is not +* restricted to acting on a single-word quantity. +*/ +static inline void set_bit (int nr,volatile void *p) +{ +volatile uint32_t *addr = p; + +__op_bit (or, __NOP, nr, addr); +} + +/** +* clear_bit - Clears a bit in memory +* @nr: Bit to clear +* @addr: Address to start counting from +* +* Note: there are no guarantees that this function will not be reordered +* on non x86 architectures, so if you are writing portable code, +* make sure not to rely on its reordering guarantees. +*/ +static inline void clear_bit (int nr,volatile void *p) +{ +volatile uint32_t *addr = p; + +__op_bit (and, __NOT, nr, addr); +} + +#undef __test_and_op_bit +#undef __op_bit +#undef __NOP +#undef __NOT +#undef __AMO + +#define test_and_set_bit __test_and_set_bit +#define test_and_clear_bit __test_and_clear_bit + +/* Based on linux/include/asm-generic/bitops/find.h */ + +#ifndef find_next_bit +/** +* find_next_bit - find the next set bit in a memory region +* @addr: The address to base the search on +* @offset: The bitnumber to start searching at +* @size: The bitmap size in bits +*/ +extern unsigned long find_next_bit (const unsigned long *addr,unsigned long + size,unsigned long offset); +#endif + +#ifndef find_next_zero_bit +/** +* find_next_zero_bit - find the next cleared bit in a memory region +* @addr: The address to base the search on +* @offset: The bitnumber to start searching at +* @size: The bitmap size in bits +*/ +extern unsigned long find_next_zero_bit (const unsigned long *addr,unsigned +long size,unsigned long offset); +#endif + +/** +* find_first_bit - find the first set bit in a memory region +* @addr: The address to start the search at +* @size: The maximum size to search +* +* Returns the bit number of the first set bit. +*/ +extern unsigned long find_first_bit (const unsigned long *addr, +unsigned long size); + +/** +* find_first_zero_bit - find the first cleared bit in a memory region +* @addr: The address to start the search at +* @size: The maximum size to search +* +* Returns the bit number of the first cleared bit. +*/ +extern unsigned long find_first_zero_bit (const unsigned long *addr, +unsigned long size); + +/** +* ffs - find first bit in word. +* @word: The word to search +* +* Returns 0 if no bit exists, otherwise returns 1-indexed bit location. +*/ +static inline unsigned long __ffs (unsigned long word) +{ +int num =0 ; + +#if BITS_PER_LONG ==64 +if ((word &0xffffffff ) ==0 ) { + num +=32 ; + word >>=32 ; + } +#endif +if ((word &0xffff ) ==0 ) { + num +=16 ; + word >>=16 ; + } +if ((word &0xff ) ==0 ) { + num +=8 ; + word >>=8 ; + } +if ((word &0xf ) ==0 ) { + num +=4 ; + word >>=4 ; + } +if ((word &0x3 ) ==0 ) { + num +=2 ; + word >>=2 ; + } +if ((word &0x1 ) ==0 ) + num +=1 ; +return num; +} + +/** +* ffsl - find first bit in long. +* @word: The word to search +* +* Returns 0 if no bit exists, otherwise returns 1-indexed bit location. +*/ +static inline unsigned int ffsl (unsigned long word) +{ +int num =1 ; + +if (!word) +return 0 ; + +#if BITS_PER_LONG ==64 +if ((word &0xffffffff ) ==0 ) { + num +=32 ; + word >>=32 ; + } +#endif +if ((word &0xffff ) ==0 ) { + num +=16 ; + word >>=16 ; + } +if ((word &0xff ) ==0 ) { + num +=8 ; + word >>=8 ; + } +if ((word &0xf ) ==0 ) { + num +=4 ; + word >>=4 ; + } +if ((word &0x3 ) ==0 ) { + num +=2 ; + word >>=2 ; + } +if ((word &0x1 ) ==0 ) + num +=1 ; +return num; +} + +#include <asm-generic/bitops/fls.h> +#include <asm-generic/bitops/flsl.h> +#include <asm-generic/bitops/ffs.h> +#include <asm-generic/bitops/ffz.h> +#include <asm-generic/bitops/find-first-bit-set.h> +#include <asm-generic/bitops/hweight.h> +#include <asm-generic/bitops/test-bit.h> + +#endif /* _ASM_RISCV_BITOPS_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
xen/include/asm-generic/bitops/bitops-bits.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_BITS_H_ +#define _ASM_GENERIC_BITOPS_BITS_H_ + +#define BITOP_BITS_PER_WORD 32 +#define BITOP_MASK (nr) (1UL << ((nr) % BITOP_BITS_PER_WORD)) +#define BITOP_WORD (nr) ((nr) / BITOP_BITS_PER_WORD) +#define BITS_PER_BYTE 8 + +#endif /* _ASM_GENERIC_BITOPS_BITS_H_ */
xen/include/asm-generic/bitops/ffs.h new file +9 -0
@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_FFS_H_ +#define _ASM_GENERIC_BITOPS_FFS_H_ + +#include <xen/macros.h> + +#define ffs (x) ({ unsigned int t_ = (x); fls(ISOLATE_LSB(t_)); }) + +#endif /* _ASM_GENERIC_BITOPS_FFS_H_ */
xen/include/asm-generic/bitops/ffz.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_FFZ_H_ +#define _ASM_GENERIC_BITOPS_FFZ_H_ + +/* +* ffz - find first zero in word. +* @word: The word to search +* +* Undefined if no zero exists, so code should check against ~0UL first. +*/ +#define ffz (x) __ffs(~(x)) + +#endif /* _ASM_GENERIC_BITOPS_FFZ_H_ */
xen/include/asm-generic/bitops/find-first-bit-set.h new file +17 -0
@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_FIND_FIRST_BIT_SET_H_ +#define _ASM_GENERIC_BITOPS_FIND_FIRST_BIT_SET_H_ + +/** +* find_first_set_bit - find the first set bit in @word +* @word: the word to search +* +* Returns the bit-number of the first set bit (first bit being 0). +* The input must *not* be zero. +*/ +static inline unsigned int find_first_set_bit (unsigned long word) +{ +return ffsl (word) -1 ; +} + +#endif /* _ASM_GENERIC_BITOPS_FIND_FIRST_BIT_SET_H_ */
xen/include/asm-generic/bitops/fls.h new file +18 -0
@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_FLS_H_ +#define _ASM_GENERIC_BITOPS_FLS_H_ + +/** +* fls - find last (most-significant) bit set +* @x: the word to search +* +* This is defined the same way as ffs. +* Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32. +*/ + +static inline int fls (unsigned int x) +{ +return generic_fls (x); +} + +#endif /* _ASM_GENERIC_BITOPS_FLS_H_ */
xen/include/asm-generic/bitops/flsl.h new file +10 -0
@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_FLSL_H_ +#define _ASM_GENERIC_BITOPS_FLSL_H_ + +static inline int flsl (unsigned long x) +{ +return generic_flsl (x); +} + +#endif /* _ASM_GENERIC_BITOPS_FLSL_H_ */
xen/include/asm-generic/bitops/hweight.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_HWEIGHT_H_ +#define _ASM_GENERIC_BITOPS_HWEIGHT_H_ + +/* +* hweightN - returns the hamming weight of a N-bit word +* @x: the word to weigh +* +* The Hamming Weight of a number is the total number of bits set in it. +*/ +#define hweight64 (x) generic_hweight64(x) + +#endif /* _ASM_GENERIC_BITOPS_HWEIGHT_H_ */
xen/include/asm-generic/bitops/test-bit.h new file +16 -0
@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_TESTBIT_H_ +#define _ASM_GENERIC_BITOPS_TESTBIT_H_ + +/** +* test_bit - Determine whether a bit is set +* @nr: bit number to test +* @addr: Address to start counting from +*/ +static inline int test_bit (int nr,const volatile void *addr) +{ +const volatile unsigned int *p = addr; +return 1 & (p[BITOP_WORD (nr)] >> (nr & (BITOP_BITS_PER_WORD -1 ))); +} + +#endif /* _ASM_GENERIC_BITOPS_TESTBIT_H_ */
Signature · 1 line
2.43.0
Re: [PATCH v3 10/34] xen/riscv: introduce bitops.h
Quoted 32 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/bitops.h new file +29
-0@@ -0,0 +1,267 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2012 Regents of the University of California */ + +#ifndef _ASM_RISCV_BITOPS_H +#define _ASM_RISCV_BITOPS_H + +#include <asm/system.h> + +#include <asm-generic/bitops/bitops-bits.h> + +/* Based on linux/arch/include/linux/bits.h */ + +#define BIT_MASK (nr) (1UL << ((nr) % BITS_PER_LONG)) +#define BIT_WORD (nr) ((nr) / BITS_PER_LONG) + +#define __set_bit (n,p) set_bit(n,p) +#define __clear_bit (n,p) clear_bit(n,p) + +/* Based on linux/arch/include/asm/bitops.h */ + +#if (BITS_PER_LONG ==64 ) +#define __AMO (op) "amo" #op ".d" +#elif (BITS_PER_LONG ==32 ) +#define __AMO (op) "amo" #op ".w" +#else +#error "Unexpected BITS_PER_LONG" +#endif + +#define __test_and_op_bit_ord (op, mod, nr, addr, ord) \
xen/arch/riscv/include/asm/bitops.h line 39
Quoted 10 lines
xen/arch/riscv/include/asm/bitops.h new file +10
-0+({ \ +unsigned long __res, __mask; \ + __mask =BIT_MASK (nr); \ + __asm__ __volatile__ ( \ + __AMO(op) #ord " %0, %2, %1" \ + :"=r" (__res),"+A" (addr[BIT_WORD (nr)]) \ + :"r" (mod (__mask)) \ + :"memory" ); \ + ((__res & __mask) !=0 ); \ +})
Despite the taking from Linux I think the overall result wants to be consistent formatting-wise: You switched to blank indentation (which is fine), but you left tabs as padding for the line continuation characters.
xen/arch/riscv/include/asm/bitops.h line 48
Quoted 8 lines
xen/arch/riscv/include/asm/bitops.h new file +8
-0+#define __op_bit_ord (op, mod, nr, addr, ord) \ + __asm__ __volatile__ ( \ + __AMO(op) #ord " zero, %1, %0" \ + : "+A" (addr[BIT_WORD(nr)]) \ + : "r" (mod(BIT_MASK(nr))) \ + : "memory"); + +#define __test_and_op_bit (op, mod, nr, addr) \
(At least) here you even use a mix.
Quoted 69 lines
xen/arch/riscv/include/asm/bitops.h new file +69
-0+ __test_and_op_bit_ord(op, mod, nr, addr, .aqrl) +#define __op_bit (op, mod, nr, addr) \ + __op_bit_ord(op, mod, nr, addr, ) + +/* Bitmask modifiers */ +#define __NOP (x) (x) +#define __NOT (x) (~(x)) + +/** +* __test_and_set_bit - Set a bit and return its old value +* @nr: Bit to set +* @addr: Address to count from +* +* This operation may be reordered on other architectures than x86. +*/ +static inline int __test_and_set_bit (int nr,volatile void *p) +{ +volatile uint32_t *addr = p; + +return __test_and_op_bit (or, __NOP, nr, addr); +} + +/** +* __test_and_clear_bit - Clear a bit and return its old value +* @nr: Bit to clear +* @addr: Address to count from +* +* This operation can be reordered on other architectures other than x86. +*/ +static inline int __test_and_clear_bit (int nr,volatile void *p) +{ +volatile uint32_t *addr = p; + +return __test_and_op_bit (and, __NOT, nr, addr); +} + +/** +* set_bit - Atomically set a bit in memory +* @nr: the bit to set +* @addr: the address to start counting from +* +* Note: there are no guarantees that this function will not be reordered +* on non x86 architectures, so if you are writing portable code, +* make sure not to rely on its reordering guarantees. +* +* Note that @nr may be almost arbitrarily large; this function is not +* restricted to acting on a single-word quantity. +*/ +static inline void set_bit (int nr,volatile void *p) +{ +volatile uint32_t *addr = p; + +__op_bit (or, __NOP, nr, addr); +} + +/** +* clear_bit - Clears a bit in memory +* @nr: Bit to clear +* @addr: Address to start counting from +* +* Note: there are no guarantees that this function will not be reordered +* on non x86 architectures, so if you are writing portable code, +* make sure not to rely on its reordering guarantees. +*/ +static inline void clear_bit (int nr,volatile void *p) +{ +volatile uint32_t *addr = p; + +__op_bit (and, __NOT, nr, addr);
xen/arch/riscv/include/asm/bitops.h line 127
Quoted 10 lines
xen/arch/riscv/include/asm/bitops.h new file +10
-0+} + +#undef __test_and_op_bit +#undef __op_bit +#undef __NOP +#undef __NOT +#undef __AMO + +#define test_and_set_bit __test_and_set_bit +#define test_and_clear_bit __test_and_clear_bit
I realize test-and-change have no present users, despite being made available by Arm and x86, but I think they would better be provided right away, rather than someone introducing a use then needing to fiddle with RISC-V (and apparently also PPC) code.
I'm also puzzled by this aliasing: Aren't there cheaper non-atomic insn forms that could be used for the double-underscore-prefixed variants?
xen/arch/riscv/include/asm/bitops.h line 131
Quoted 3 lines
xen/arch/riscv/include/asm/bitops.h new file +3
-0+/* Based on linux/include/asm-generic/bitops/find.h */ + +#ifndef find_next_bit
What is this to guard against?
Quoted 40 lines
xen/arch/riscv/include/asm/bitops.h new file +40
-0+/** +* find_next_bit - find the next set bit in a memory region +* @addr: The address to base the search on +* @offset: The bitnumber to start searching at +* @size: The bitmap size in bits +*/ +extern unsigned long find_next_bit (const unsigned long *addr,unsigned long + size,unsigned long offset); +#endif + +#ifndef find_next_zero_bit +/** +* find_next_zero_bit - find the next cleared bit in a memory region +* @addr: The address to base the search on +* @offset: The bitnumber to start searching at +* @size: The bitmap size in bits +*/ +extern unsigned long find_next_zero_bit (const unsigned long *addr,unsigned +long size,unsigned long offset); +#endif + +/** +* find_first_bit - find the first set bit in a memory region +* @addr: The address to start the search at +* @size: The maximum size to search +* +* Returns the bit number of the first set bit. +*/ +extern unsigned long find_first_bit (const unsigned long *addr, +unsigned long size); + +/** +* find_first_zero_bit - find the first cleared bit in a memory region +* @addr: The address to start the search at +* @size: The maximum size to search +* +* Returns the bit number of the first cleared bit. +*/ +extern unsigned long find_first_zero_bit (const unsigned long *addr, +unsigned long size);
xen/arch/riscv/include/asm/bitops.h line 181
Quoted 10 lines
xen/arch/riscv/include/asm/bitops.h new file +10
-0+ +/** +* ffs - find first bit in word. +* @word: The word to search +* +* Returns 0 if no bit exists, otherwise returns 1-indexed bit location. +*/ +static inline unsigned long __ffs (unsigned long word) +{ +int num =0 ;
I understand it's this way in Linux, so there may be reasons to keep it like that. Generally though we'd prefer unsigned here, and the type of a variable used for the return value of a function would also better be in sync with the function's return type (which I don't think needs to be "unsigned long" either; "unsigned int" would apparently suffice).
xen/arch/riscv/include/asm/bitops.h line 187
Quoted 5 lines
xen/arch/riscv/include/asm/bitops.h new file +5
-0+#if BITS_PER_LONG ==64 +if ((word &0xffffffff ) ==0 ) { + num +=32 ; + word >>=32 ; + }
You're ending up with neither Xen nor Linux style this way. May I suggest to settle on either?
Quoted 51 lines
xen/arch/riscv/include/asm/bitops.h new file +51
-0+#endif +if ((word &0xffff ) ==0 ) { + num +=16 ; + word >>=16 ; + } +if ((word &0xff ) ==0 ) { + num +=8 ; + word >>=8 ; + } +if ((word &0xf ) ==0 ) { + num +=4 ; + word >>=4 ; + } +if ((word &0x3 ) ==0 ) { + num +=2 ; + word >>=2 ; + } +if ((word &0x1 ) ==0 ) + num +=1 ; +return num; +} + +/** +* ffsl - find first bit in long. +* @word: The word to search +* +* Returns 0 if no bit exists, otherwise returns 1-indexed bit location. +*/ +static inline unsigned int ffsl (unsigned long word) +{ +int num =1 ; + +if (!word) +return 0 ; + +#if BITS_PER_LONG ==64 +if ((word &0xffffffff ) ==0 ) { + num +=32 ; + word >>=32 ; + } +#endif +if ((word &0xffff ) ==0 ) { + num +=16 ; + word >>=16 ; + } +if ((word &0xff ) ==0 ) { + num +=8 ; + word >>=8 ; + } +if ((word &0xf ) ==0 ) { + num +=4 ;
xen/arch/riscv/include/asm/bitops.h line 248
Quoted 10 lines
xen/arch/riscv/include/asm/bitops.h new file +10
-0+ word >>=4 ; + } +if ((word &0x3 ) ==0 ) { + num +=2 ; + word >>=2 ; + } +if ((word &0x1 ) ==0 ) + num +=1 ; +return num; +}
What's RISC-V-specific about the above? IOW why ...
xen/arch/riscv/include/asm/bitops.h line 253
Quoted 4 lines
xen/arch/riscv/include/asm/bitops.h new file +4
-0+#include <asm-generic/bitops/fls.h> +#include <asm-generic/bitops/flsl.h> +#include <asm-generic/bitops/ffs.h> +#include <asm-generic/bitops/ffz.h>
... can't those two also come from respective generic headers?
xen/include/asm-generic/bitops/bitops-bits.h line 6
Quoted 9 lines
xen/include/asm-generic/bitops/bitops-bits.h new file +6
-0@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_BITS_H_ +#define _ASM_GENERIC_BITOPS_BITS_H_ + +#define BITOP_BITS_PER_WORD 32 +#define BITOP_MASK (nr) (1UL << ((nr) % BITOP_BITS_PER_WORD))
Why 1UL and not just 1U, when bits per word is 32?
xen/include/asm-generic/bitops/bitops-bits.h line 10
Quoted 5 lines
xen/include/asm-generic/bitops/bitops-bits.h new file +4
-0+#define BITOP_WORD (nr) ((nr) / BITOP_BITS_PER_WORD) +#define BITS_PER_BYTE 8 + +#endif /* _ASM_GENERIC_BITOPS_BITS_H_ */
Nit: I did comment on such before (and there's at least one more further down).
Quoted 19 lines
xen/include/asm-generic/bitops/ffs.h new file +9
-0@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_FFS_H_ +#define _ASM_GENERIC_BITOPS_FFS_H_ + +#include <xen/macros.h> + +#define ffs (x) ({ unsigned int t_ = (x); fls(ISOLATE_LSB(t_)); }) + +#endif /* _ASM_GENERIC_BITOPS_FFS_H_ */ xen/include/asm-generic/bitops/ffz.h new file +1
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */
xen/include/asm-generic/bitops/ffz.h line 11
Quoted 10 lines
xen/include/asm-generic/bitops/ffz.h new file +10
-0+#ifndef _ASM_GENERIC_BITOPS_FFZ_H_ +#define _ASM_GENERIC_BITOPS_FFZ_H_ + +/* +* ffz - find first zero in word. +* @word: The word to search +* +* Undefined if no zero exists, so code should check against ~0UL first. +*/ +#define ffz (x) __ffs(~(x))
For a generic header I'd like to see consistency: ffz() may expand to ffs(), and __ffz() may expand to __ffs(). A mix like you have it above wants at least explaining in the description. (I don't understand anyway why both ffs() and __ffs() would be needed. We don't have any __ffs() on x86 afaics.)
xen/include/asm-generic/bitops/find-first-bit-set.h
Quoted 2 lines
xen/include/asm-generic/bitops/find-first-bit-set.h new file +0
-0
This file name, if it really needs to be this long, wants to match ...
xen/include/asm-generic/bitops/find-first-bit-set.h line 12
Quoted 13 lines
xen/include/asm-generic/bitops/find-first-bit-set.h new file +12
-0@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_FIND_FIRST_BIT_SET_H_ +#define _ASM_GENERIC_BITOPS_FIND_FIRST_BIT_SET_H_ + +/** +* find_first_set_bit - find the first set bit in @word +* @word: the word to search +* +* Returns the bit-number of the first set bit (first bit being 0). +* The input must *not* be zero. +*/ +static inline unsigned int find_first_set_bit (unsigned long word)
... the function implemented herein.
Quoted 9 lines
xen/include/asm-generic/bitops/fls.h new file +6
-0@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_FLS_H_ +#define _ASM_GENERIC_BITOPS_FLS_H_ + +/** +* fls - find last (most-significant) bit set
xen/include/asm-generic/bitops/fls.h line 16
Quoted 10 lines
xen/include/asm-generic/bitops/fls.h new file +10
-0+* @x: the word to search +* +* This is defined the same way as ffs. +* Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32. +*/ + +static inline int fls (unsigned int x) +{ +return generic_fls (x); +}
Seing this, why would e.g. ffsl() not use generic_ffsl() then?
Quoted 6 lines
xen/include/asm-generic/bitops/hweight.h new file +3
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_HWEIGHT_H_ +#define _ASM_GENERIC_BITOPS_HWEIGHT_H_
xen/include/asm-generic/bitops/hweight.h line 13
Quoted 10 lines
xen/include/asm-generic/bitops/hweight.h new file +10
-0+ +/* +* hweightN - returns the hamming weight of a N-bit word +* @x: the word to weigh +* +* The Hamming Weight of a number is the total number of bits set in it. +*/ +#define hweight64 (x) generic_hweight64(x) + +#endif /* _ASM_GENERIC_BITOPS_HWEIGHT_H_ */
Do we really need this? An arch not having suitable insns (RISC-V has, iirc) can easily have this one #define (or the ip to four ones when also covering the other widths) in its asm header.
Quoted 5 lines
xen/include/asm-generic/bitops/test-bit.h new file +2
-0@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_TESTBIT_H_
xen/include/asm-generic/bitops/test-bit.h line 12
Quoted 10 lines
xen/include/asm-generic/bitops/test-bit.h new file +10
-0+#define _ASM_GENERIC_BITOPS_TESTBIT_H_ + +/** +* test_bit - Determine whether a bit is set +* @nr: bit number to test +* @addr: Address to start counting from +*/ +static inline int test_bit (int nr,const volatile void *addr) +{ +const volatile unsigned int *p = addr;
With BITOP_BITS_PER_WORD I think you really mean uint32_t here. Also you want to make sure asm-generic/bitops/bitops-bits.h is really in use here, or else an arch overriding / not using that header may end up screwed.
Jan
Quoted 5 lines
xen/include/asm-generic/bitops/test-bit.h new file +4
-0+ return 1 & (p[BITOP_WORD(nr)] >> (nr & (BITOP_BITS_PER_WORD - 1))); +} + +#endif /* _ASM_GENERIC_BITOPS_TESTBIT_H_ */
Re: [PATCH v3 10/34] xen/riscv: introduce bitops.h
Quoted 40 lines · Jan Beulich
Quoted 39 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/bitops.h new file +36
-0@@ -0,0 +1,267 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* Copyright (C) 2012 Regents of the University of California */ + +#ifndef _ASM_RISCV_BITOPS_H +#define _ASM_RISCV_BITOPS_H + +#include <asm/system.h> + +#include <asm-generic/bitops/bitops-bits.h> + +/* Based on linux/arch/include/linux/bits.h */ + +#define BIT_MASK (nr) (1UL << ((nr) % BITS_PER_LONG)) +#define BIT_WORD (nr) ((nr) / BITS_PER_LONG) + +#define __set_bit (n,p) set_bit(n,p) +#define __clear_bit (n,p) clear_bit(n,p) + +/* Based on linux/arch/include/asm/bitops.h */ + +#if (BITS_PER_LONG ==64 ) +#define __AMO (op) "amo" #op ".d" +#elif (BITS_PER_LONG ==32 ) +#define __AMO (op) "amo" #op ".w" +#else +#error "Unexpected BITS_PER_LONG" +#endif + +#define __test_and_op_bit_ord (op, mod, nr, addr, ord) \ +({ \ + unsigned long __res, __mask; \ + __mask = BIT_MASK(nr); \ + __asm__ __volatile__ ( \ + __AMO(op) #ord " %0, %2, %1" \ + : "=r" (__res), "+A" (addr[BIT_WORD(nr)]) \ + : "r" (mod(__mask)) \
Quoted 8 lines
xen/arch/riscv/include/asm/bitops.h line 39
Quoted 3 lines
xen/arch/riscv/include/asm/bitops.h new file +3
-0+ : "memory"); \ + ((__res & __mask) != 0); \ +})Despite the taking from Linux I think the overall result wants to be consistent formatting-wise: You switched to blank indentation (which is fine), but you left tabs as padding for the line continuation characters.
I think it is because of my IDE. I will be consistent in next patch version.
Thanks.
Quoted 93 lines
xen/arch/riscv/include/asm/bitops.h line 48
Quoted 9 lines
xen/arch/riscv/include/asm/bitops.h new file +8
-0+#define __op_bit_ord (op, mod, nr, addr, ord) \ + __asm__ __volatile__ ( \ + __AMO(op) #ord " zero, %1, %0" \ + : "+A" (addr[BIT_WORD(nr)]) \ + : "r" (mod(BIT_MASK(nr))) \ + : "memory"); + +#define __test_and_op_bit (op, mod, nr, addr) \(At least) here you even use a mix.
Quoted 81 lines
xen/arch/riscv/include/asm/bitops.h new file +14
-0+ __test_and_op_bit_ord(op, mod, nr, addr, .aqrl) +#define __op_bit (op, mod, nr, addr) \ + __op_bit_ord(op, mod, nr, addr, ) + +/* Bitmask modifiers */ +#define __NOP (x) (x) +#define __NOT (x) (~(x)) + +/** +* __test_and_set_bit - Set a bit and return its old value +* @nr: Bit to set +* @addr: Address to count from +* +* This operation may be reordered on other architectures than x86.
+ */xen/arch/riscv/include/asm/bitops.h new file +13
-0+static inline int __test_and_set_bit (int nr,volatile void *p) +{ + volatile uint32_t *addr = p; + + return __test_and_op_bit(or, __NOP, nr, addr); +} + +/** +* __test_and_clear_bit - Clear a bit and return its old value +* @nr: Bit to clear +* @addr: Address to count from +* +* This operation can be reordered on other architectures other than x86.
+ */xen/arch/riscv/include/asm/bitops.h new file +13
-0+static inline int __test_and_clear_bit (int nr,volatile void *p) +{ + volatile uint32_t *addr = p; + + return __test_and_op_bit(and, __NOT, nr, addr); +} + +/** +* set_bit - Atomically set a bit in memory +* @nr: the bit to set +* @addr: the address to start counting from +* +* Note: there are no guarantees that this function will not be reordered
+ * on non x86 architectures, so if you are writing portable code,
+ * make sure not to rely on its reordering guarantees.
+ *
+ * Note that @nr may be almost arbitrarily large; this function is not
+ * restricted to acting on a single-word quantity.
+ */xen/arch/riscv/include/asm/bitops.h new file +13
-0+static inline void set_bit (int nr,volatile void *p) +{ + volatile uint32_t *addr = p; + + __op_bit(or, __NOP, nr, addr); +} + +/** +* clear_bit - Clears a bit in memory +* @nr: Bit to clear +* @addr: Address to start counting from +* +* Note: there are no guarantees that this function will not be reordered
+ * on non x86 architectures, so if you are writing portable code,
+ * make sure not to rely on its reordering guarantees.
+ */xen/arch/riscv/include/asm/bitops.h new file +12
-0+static inline void clear_bit (int nr,volatile void *p) +{ + volatile uint32_t *addr = p; + + __op_bit(and, __NOT, nr, addr); +} + +#undef __test_and_op_bit +#undef __op_bit +#undef __NOP +#undef __NOT +#undef __AMO
Quoted 8 lines
xen/arch/riscv/include/asm/bitops.h line 127
Quoted 3 lines
xen/arch/riscv/include/asm/bitops.h new file +3
-0+ +#define test_and_set_bit __test_and_set_bit +#define test_and_clear_bit __test_and_clear_bitI realize test-and-change have no present users, despite being made available by Arm and x86, but I think they would better be provided right away, rather than someone introducing a use then needing to fiddle with RISC-V (and apparently also PPC) code.
Sure, it makes sense. I'll add test-and-change too.
Quoted 4 lines
I'm also puzzled by this aliasing: Aren't there cheaper non-atomic insn forms that could be used for the double-underscore-prefixed variants?
It will be cheaper, but I assume that this API should be safe in the case of SMP where different CPUs can access the same variable or similar cases with simultaneous access to the variable.
Quoted 6 lines
xen/arch/riscv/include/asm/bitops.h line 131
Quoted 4 lines
xen/arch/riscv/include/asm/bitops.h new file +3
-0+/* Based on linux/include/asm-generic/bitops/find.h */ + +#ifndef find_next_bitWhat is this to guard against?
This was copied from Linux, but in case of Xen it can be dropped.
Quoted 67 lines
Quoted 54 lines
xen/arch/riscv/include/asm/bitops.h new file +7
-0+/** +* find_next_bit - find the next set bit in a memory region +* @addr: The address to base the search on +* @offset: The bitnumber to start searching at +* @size: The bitmap size in bits +*/ +extern unsigned long find_next_bit(const unsigned long *addr,unsigned long
+ size, unsigned long offset);xen/arch/riscv/include/asm/bitops.h new file +5
-0+#endif + +#ifndef find_next_zero_bit +/** +* find_next_zero_bit - find the next cleared bit in a memory region
+ * @addr: The address to base the search on
+ * @offset: The bitnumber to start searching at
+ * @size: The bitmap size in bits
+ */
+extern unsigned long find_next_zero_bit(const unsigned long *addr, unsigned
+ long size, unsigned long offset);xen/arch/riscv/include/asm/bitops.h new file +14
-0+#endif + +/** +* find_first_bit - find the first set bit in a memory region +* @addr: The address to start the search at +* @size: The maximum size to search +* +* Returns the bit number of the first set bit. +*/ +extern unsigned long find_first_bit (const unsigned long *addr, + unsigned long size); + +/** +* find_first_zero_bit - find the first cleared bit in a memory region
+ * @addr: The address to start the search at
+ * @size: The maximum size to search
+ *
+ * Returns the bit number of the first cleared bit.
+ */
+extern unsigned long find_first_zero_bit(const unsigned long *addr,
+ unsigned long size);xen/arch/riscv/include/asm/bitops.h new file +6
-0+ +/** +* ffs - find first bit in word. +* @word: The word to search +* +* Returns 0 if no bit exists, otherwise returns 1-indexed bit location.
+ */xen/arch/riscv/include/asm/bitops.h line 181
Quoted 3 lines
xen/arch/riscv/include/asm/bitops.h new file +3
-0+static inline unsigned long __ffs (unsigned long word) +{ + int num = 0;I understand it's this way in Linux, so there may be reasons to keep it
like that. Generally though we'd prefer unsigned here, and the type of
a variable used for the return value of a function would also better be
in sync with the function's return type (which I don't think needs to be "unsigned long" either; "unsigned int" would apparently suffice).
Quoted 8 lines
Quoted 5 lines
+#if
BITS_PER_LONG== 64
+ if ((word &0xffffffff) == 0) {
+ num += 32;
+ word >>= 32;
+ }You're ending up with neither Xen nor Linux style this way. May I suggest to settle on either?
Will it fine to rework header from Linux to Xen style? Does it make sense?
I think this file can be reworked to Xen style as I don't expect that it will be changed since it will be merged.
Quoted 66 lines
Quoted 53 lines
xen/arch/riscv/include/asm/bitops.h new file +27
-0+#endif + if ((word & 0xffff) == 0) { + num += 16; + word >>= 16; + } + if ((word & 0xff) == 0) { + num += 8; + word >>= 8; + } + if ((word & 0xf) == 0) { + num += 4; + word >>= 4; + } + if ((word & 0x3) == 0) { + num += 2; + word >>= 2; + } + if ((word & 0x1) == 0) + num += 1; + return num; +} + +/** +* ffsl - find first bit in long. +* @word: The word to search +* +* Returns 0 if no bit exists, otherwise returns 1-indexed bit location.
+ */xen/arch/riscv/include/asm/bitops.h new file +23
-0+static inline unsigned int ffsl (unsigned long word) +{ + int num = 1; + + if (!word) + return 0; + +#if BITS_PER_LONG ==64 + if ((word & 0xffffffff) == 0) { + num += 32; + word >>= 32; + } +#endif + if ((word & 0xffff) == 0) { + num += 16; + word >>= 16; + } + if ((word & 0xff) == 0) { + num += 8; + word >>= 8; + } + if ((word & 0xf) == 0) { + num += 4;xen/arch/riscv/include/asm/bitops.h line 248
Quoted 10 lines
xen/arch/riscv/include/asm/bitops.h new file +10
-0+ word >>= 4; + } + if ((word & 0x3) == 0) { + num += 2; + word >>= 2; + } + if ((word & 0x1) == 0) + num += 1; + return num; +}What's RISC-V-specific about the above? IOW why ...
Quoted 6 lines
xen/arch/riscv/include/asm/bitops.h line 253
Quoted 4 lines
xen/arch/riscv/include/asm/bitops.h new file +4
-0+#include <asm-generic/bitops/fls.h> +#include <asm-generic/bitops/flsl.h> +#include <asm-generic/bitops/ffs.h> +#include <asm-generic/bitops/ffz.h> ... can't those two also come from respective generic headers?
Sure it can. Originally, I don't introduce it as generic headers because RISC-V is only one who isn using C generic version.
I found that there is already present such generic function in xen/bitops.h. I think it makes sense to re-use them.
Quoted 13 lines
Quoted 11 lines
xen/include/asm-generic/bitops/bitops-bits.h new file +6
-0@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_BITS_H_ +#define _ASM_GENERIC_BITOPS_BITS_H_ + +#define BITOP_BITS_PER_WORD 32 +#define BITOP_MASK (nr) (1UL << ((nr) %
BITOP_BITS_PER_WORD))Why 1UL and not just 1U, when bits per word is 32?
There is no specific reason, should 1U. ( I originally used BITOPS_BITS_PER_LONG ) and with introduction of asm-generic bitops decided to follow what other archs provide.
Regarding to the second part of the question, I don't understand it fully. Considering BITOP_BIT_PER_WORD definition for other archs ( ARM and PPC ) it is expected that word is 32 bits.
Quoted 9 lines
xen/include/asm-generic/bitops/bitops-bits.h line 10
Quoted 6 lines
xen/include/asm-generic/bitops/bitops-bits.h new file +4
-0+#define BITOP_WORD (nr) ((nr) / BITOP_BITS_PER_WORD) +#define BITS_PER_BYTE 8 + +#endif /* _ASM_GENERIC_BITOPS_BITS_H_ */ Nit: I did comment on such before (and there's at least one more further down).
Thanks.
I'll add a newline.
Quoted 31 lines
Quoted 31 lines
xen/include/asm-generic/bitops/ffs.h new file +9
-0@@ -0,0 +1,9 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_FFS_H_ +#define _ASM_GENERIC_BITOPS_FFS_H_ + +#include <xen/macros.h> + +#define ffs (x) ({ unsigned int t_ = (x); fls(ISOLATE_LSB(t_)); }) + +#endif /* _ASM_GENERIC_BITOPS_FFS_H_ */ xen/include/asm-generic/bitops/ffz.h new file +9
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_FFZ_H_ +#define _ASM_GENERIC_BITOPS_FFZ_H_ + +/* +* ffz - find first zero in word. +* @word: The word to search +* +* Undefined if no zero exists, so code should check against ~0UL first.
+ */
Quoted 8 lines
Quoted 1 line
+#define ffz(x) __ffs(~(x))
For a generic header I'd like to see consistency:
ffz()may expand toffs(), and__ffz()may expand to__ffs(). A mix like you have it above
wants at least explaining in the description. (I don't understand anyway why bothffs()and__ffs()would be needed. We don't have any__ffs()on x86 afaics.)
Then it looks to me that ffs() should be used instead. ffz() was defined with __ffs() because Arm and PPC are defined so.
Quoted 7 lines
xen/include/asm-generic/bitops/find-first-bit-set.h
Quoted 3 lines
xen/include/asm-generic/bitops/find-first-bit-set.h new file +0
-0This file name, if it really needs to be this long, wants to match
...
Quoted 16 lines
Quoted 10 lines
xen/include/asm-generic/bitops/find-first-bit-set.h new file +9
-0@@ -0,0 +1,17 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_FIND_FIRST_BIT_SET_H_ +#define _ASM_GENERIC_BITOPS_FIND_FIRST_BIT_SET_H_ + +/** +* find_first_set_bit - find the first set bit in @word +* @word: the word to search +* +* Returns the bit-number of the first set bit (first bit being Quoted 4 lines
0).
+ * The input must *not* be zero.
+ */
+static inline unsigned intfind_first_set_bit(unsigned long word)... the function implemented herein.
Thanks. I'll update the file name.
Quoted 55 lines
Quoted 10 lines
xen/include/asm-generic/bitops/fls.h new file +6
-0@@ -0,0 +1,18 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_FLS_H_ +#define _ASM_GENERIC_BITOPS_FLS_H_ + +/** +* fls - find last (most-significant) bit set xen/include/asm-generic/bitops/fls.h line 16
Quoted 10 lines
xen/include/asm-generic/bitops/fls.h new file +10
-0+* @x: the word to search +* +* This is defined the same way as ffs. +* Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32. +*/ + +static inline int fls (unsigned int x) +{ + return generic_fls(x); +}Seing this, why would e.g.
ffsl()not usegeneric_ffsl()then?Quoted 14 lines
xen/include/asm-generic/bitops/hweight.h new file +9
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_HWEIGHT_H_ +#define _ASM_GENERIC_BITOPS_HWEIGHT_H_ + +/* +* hweightN - returns the hamming weight of a N-bit word +* @x: the word to weigh +* +* The Hamming Weight of a number is the total number of bits set in it.
+ */xen/include/asm-generic/bitops/hweight.h line 13
Quoted 3 lines
xen/include/asm-generic/bitops/hweight.h new file +3
-0+#define hweight64 (x) generic_hweight64(x) + +#endif /* _ASM_GENERIC_BITOPS_HWEIGHT_H_ */ Do we really need this? An arch not having suitable insns (RISC-V has,
iirc) can easily have this one #define (or the ip to four ones when also covering the other widths) in its asm header.Quoted 9 lines
xen/include/asm-generic/bitops/test-bit.h new file +6
-0@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_TESTBIT_H_ +#define _ASM_GENERIC_BITOPS_TESTBIT_H_ + +/** +* test_bit - Determine whether a bit is set
Quoted 8 lines
xen/include/asm-generic/bitops/test-bit.h line 12
Quoted 6 lines
xen/include/asm-generic/bitops/test-bit.h new file +6
-0+* @nr: bit number to test +* @addr: Address to start counting from +*/ +static inline int test_bit (int nr,const volatile void *addr) +{ + const volatile unsigned int *p = addr;With
BITOP_BITS_PER_WORDI think you really meanuint32_there.
Isn't it the same: 'unsigned int' and 'uint32_t'?
Quoted 3 lines
Also you want to make sure
asm-generic/bitops/bitops-bits.his really in use here, or else an arch overriding / not using that header may end up screwed.
I am not really understand what do you mean. Could you please explain a little bit more.
~ Oleksii
Quoted 10 lines
Jan
Quoted 6 lines
xen/include/asm-generic/bitops/test-bit.h new file +1
-0+ return 1 & (p[BITOP_WORD(nr)] >> (nr & (BITOP_BITS_PER_WORD -1)));
xen/include/asm-generic/bitops/test-bit.h new file +3
-0+} + +#endif /* _ASM_GENERIC_BITOPS_TESTBIT_H_ */
Re: [PATCH v3 10/34] xen/riscv: introduce bitops.h
Quoted 9 lines · Oleksii
Quoted 8 lines · Jan Beulich
xen/arch/riscv/include/asm/bitops.h line 127
Quoted 2 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/bitops.h new file +2
-0+#define test_and_set_bit __test_and_set_bit +#define test_and_clear_bit __test_and_clear_bitI realize test-and-change have no present users, despite being made available by Arm and x86, but I think they would better be provided right away, rather than someone introducing a use then needing to fiddle with RISC-V (and apparently also PPC) code.
Quoted 8 lines
Sure, it makes sense. I'll add test-and-change too.
Quoted 3 lines
I'm also puzzled by this aliasing: Aren't there cheaper non-atomic insn forms that could be used for the double-underscore-prefixed variants?
It will be cheaper, but I assume that this API should be safe in the case of SMP where different CPUs can access the same variable or similar cases with simultaneous access to the variable.
Of course, that's what test_and_...() are for. __test_and_...() are for cases where there's no concurrency, when hence the cheaper forms can be used. Thus my asking about the aliasing done above.
Quoted 6 lines
Quoted 6 lines
Quoted 5 lines
+#if
BITS_PER_LONG== 64
+ if ((word &0xffffffff) == 0) {
+ num += 32;
+ word >>= 32;
+ }
Quoted 7 lines
Quoted 2 lines
You're ending up with neither Xen nor Linux style this way. May I suggest to settle on either?
Will it fine to rework header from Linux to Xen style? Does it make sense?
I think this file can be reworked to Xen style as I don't expect that it will be changed since it will be merged.
You may keep Linux style or fully switch to Xen style - which one is largely up to you. All I'm asking is to avoid introducing further mixed-style source files.
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
xen/include/asm-generic/bitops/bitops-bits.h new file +1
-0@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ Quoted 8 lines
Quoted 6 lines
xen/include/asm-generic/bitops/bitops-bits.h new file +5
-0+#ifndef _ASM_GENERIC_BITOPS_BITS_H_ +#define _ASM_GENERIC_BITOPS_BITS_H_ + +#define BITOP_BITS_PER_WORD 32 +#define BITOP_MASK (nr) (1UL << ((nr) %
BITOP_BITS_PER_WORD))Why 1UL and not just 1U, when bits per word is 32?
Quoted 7 lines
There is no specific reason, should 1U. ( I originally used
BITOPS_BITS_PER_LONG) and with introduction of asm-generic bitops decided to follow what other archs provide.Regarding to the second part of the question, I don't understand it fully. Considering
BITOP_BIT_PER_WORDdefinition for other archs ( ARM and PPC ) it is expected that word is 32 bits.
The 2nd part was explaining why I'm asking. It wasn't another question.
Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
xen/include/asm-generic/bitops/test-bit.h new file +6
-0@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_TESTBIT_H_ +#define _ASM_GENERIC_BITOPS_TESTBIT_H_ + +/** +* test_bit - Determine whether a bit is set Quoted 8 lines
xen/include/asm-generic/bitops/test-bit.h line 12
Quoted 6 lines
xen/include/asm-generic/bitops/test-bit.h new file +6
-0+* @nr: bit number to test +* @addr: Address to start counting from +*/ +static inline int test_bit (int nr,const volatile void *addr) +{ + const volatile unsigned int *p = addr;With
BITOP_BITS_PER_WORDI think you really meanuint32_there.
Quoted 1 line
Isn't it the same: 'unsigned int' and '
uint32_t'?
No, or else there wouldn't have been a need to introduce uint<N>_t (and others) in C99. It just so happens that right now all architectures Xen can be built for have sizeof(int) == 4 and CHAR_BITS == 8. In an arch- specific header I would see this as less of an issue, but in a generic header we'd better avoid encoding wrong assumptions. The one assumption we generally make is that sizeof(int) >= 4 and CHAR_BITS >= 8 (albeit I bet really in various places we assume CHAR_BITS == 8).
Quoted 5 lines
Quoted 3 lines
Also you want to make sure
asm-generic/bitops/bitops-bits.his really in use here, or else an arch overriding / not using that header may end up screwed.I am not really understand what do you mean. Could you please explain a little bit more.
Whichever type you use here, it needs to be in sync with BITOP_BITS_PER_WORD. Hence you want to include the _local_ bitops-bits.h here, such that in case of an inconsistent override by an arch the compiler would complain about the two differring #define-s. (IOW an arch overriding BITOP_BITS_PER_WORD cannot re-use this header as-is.)
The same may, btw, be true for others of the new headers you add - the same #include would therefore be needed there as well.
Jan
Re: [PATCH v3 10/34] xen/riscv: introduce bitops.h
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Oleksii
Quoted 10 lines · Jan Beulich
xen/arch/riscv/include/asm/bitops.h line 127
Quoted 2 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/bitops.h new file +2
-0+#define test_and_set_bit __test_and_set_bit +#define test_and_clear_bit __test_and_clear_bitI realize test-and-change have no present users, despite being made
available by Arm and x86, but I think they would better be provided
right away, rather than someone introducing a use then needing to fiddle with RISC-V (and apparently also PPC) code.Sure, it makes sense. I'll add test-and-change too.
Quoted 4 lines
I'm also puzzled by this aliasing: Aren't there cheaper non- atomic
insn forms that could be used for the double-underscore-prefixed variants?
Quoted 8 lines
Quoted 4 lines
It will be cheaper, but I assume that this API should be safe in the
case of SMP where different CPUs can access the same variable or similar cases with simultaneous access to the variable.Of course, that's what test_and_...() are for. __test_and_...() are for cases where there's no concurrency, when hence the cheaper forms can be used. Thus my asking about the aliasing done above.
Then it makes sense to update __test_and...() to use non-atomic insn. I'll do that in the next patch version.
Thanks for explanation.
Quoted 16 lines
Quoted 7 lines
Quoted 7 lines
Quoted 6 lines
+#if
BITS_PER_LONG== 64
+ if ((word &0xffffffff) == 0) {
+ num += 32;
+ word >>= 32;
+ }Quoted 8 lines
Quoted 2 lines
You're ending up with neither Xen nor Linux style this way. May I suggest to settle on either?
Will it fine to rework header from Linux to Xen style? Does it make sense?
I think this file can be reworked to Xen style as I don't expect that
it will be changed since it will be merged.
Quoted 3 lines
You may keep Linux style or fully switch to Xen style - which one is largely up to you. All I'm asking is to avoid introducing further mixed-style source files.
I'll be consistent in code style.
Quoted 44 lines
Quoted 13 lines
Quoted 13 lines
Quoted 11 lines
xen/include/asm-generic/bitops/bitops-bits.h new file +6
-0@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_BITS_H_ +#define _ASM_GENERIC_BITOPS_BITS_H_ + +#define BITOP_BITS_PER_WORD 32 +#define BITOP_MASK (nr) (1UL << ((nr) %
BITOP_BITS_PER_WORD))Why 1UL and not just 1U, when bits per word is 32?
Quoted 8 lines
There is no specific reason, should 1U. ( I originally used
BITOPS_BITS_PER_LONG) and with introduction of asm-generic bitops decided to follow what other archs provide.Regarding to the second part of the question, I don't understand it fully. Considering
BITOP_BIT_PER_WORDdefinition for other archs ( ARM
and PPC ) it is expected that word is 32 bits.The 2nd part was explaining why I'm asking. It wasn't another question.
Quoted 17 lines
Quoted 9 lines
Quoted 9 lines
xen/include/asm-generic/bitops/test-bit.h new file +6
-0@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_TESTBIT_H_ +#define _ASM_GENERIC_BITOPS_TESTBIT_H_ + +/** +* test_bit - Determine whether a bit is set Quoted 8 lines
xen/include/asm-generic/bitops/test-bit.h line 12
Quoted 6 lines
xen/include/asm-generic/bitops/test-bit.h new file +6
-0+* @nr: bit number to test +* @addr: Address to start counting from +*/ +static inline int test_bit (int nr,const volatile void *addr) +{ + const volatile unsigned int *p = addr;With
BITOP_BITS_PER_WORDI think you really meanuint32_there.Quoted 1 line
Isn't it the same: 'unsigned int' and '
uint32_t'?
Quoted 13 lines
No, or else there wouldn't have been a need to introduce uint<N>_t (and
others) in C99. It just so happens that right now all architectures Xen
can be built for have sizeof(int) == 4 andCHAR_BITS== 8. In an arch-
specific header I would see this as less of an issue, but in a generic
header we'd better avoid encoding wrong assumptions. The one assumption
we generally make is that sizeof(int) >= 4 andCHAR_BITS>= 8 (albeit I
bet really in various places we assumeCHAR_BITS== 8).
In this case we have to switch to uint<N>_t.
Thanks for the explanation. I'll update this part of code in the next patch version.
Quoted 15 lines
Quoted 7 lines
Quoted 4 lines
Also you want to make sure
asm-generic/bitops/bitops-bits.his really in use here, or else an arch overriding / not using that header may end up screwed.I am not really understand what do you mean. Could you please explain a
little bit more.Whichever type you use here, it needs to be in sync with
BITOP_BITS_PER_WORD. Hence you want to include the _local_ bitops-bits.h
here, such that in case of an inconsistent override by an arch the compiler would complain about the two differring #define-s. (IOW an arch overridingBITOP_BITS_PER_WORDcannot re-use this header as-is.)
Quoted 3 lines
The same may, btw, be true for others of the new headers you add - the
same #include would therefore be needed there as well.
Now it clear to me.
It seems like BITOP_BITS_PER_WORD, BITOP_MASK, BITOP_WORD, and BITS_PER_BYTE are defined in {arm, ppc, riscv}/include/asm/bitops.h. I expected that any architecture planning to use asm- generic/bitops/bitops-bits.h would include it at the beginning of <arch>/include/asm/bitops.h, similar to what is done for RISC-V:
#ifndef _ASM_RISCV_BITOPS_H
#define _ASM_RISCV_BITOPS_H
#include <asm/system.h> #include <asm-generic/bitops/bitops-bits.h> ...
But in this case, to allow architecture overrides macros, it is necessary to update asm-generic/bitops/bitops-bits.h:
#ifndef BITOP_BITS_PER_WORD
#define BITOP_BITS_PER_WORD 32
#endif ...
Therefore, if an architecture needs to override something, it will add #define ... before #include <asm-generic/bitops/bitops-bits.h>.
Does it make sense?
~ Oleksii
Re: [PATCH v3 10/34] xen/riscv: introduce bitops.h
Quoted 76 lines · Oleksii
Quoted 22 lines · Jan Beulich
Quoted 19 lines · Oleksii
Quoted 10 lines · Jan Beulich
Quoted 9 lines · Oleksii Kurochko
xen/include/asm-generic/bitops/test-bit.h new file +6
-0@@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_TESTBIT_H_ +#define _ASM_GENERIC_BITOPS_TESTBIT_H_ + +/** +* test_bit - Determine whether a bit is set Quoted 8 lines
xen/include/asm-generic/bitops/test-bit.h line 12
Quoted 6 lines
xen/include/asm-generic/bitops/test-bit.h new file +6
-0+* @nr: bit number to test +* @addr: Address to start counting from +*/ +static inline int test_bit (int nr,const volatile void *addr) +{ + const volatile unsigned int *p = addr;With
BITOP_BITS_PER_WORDI think you really meanuint32_there.Quoted 1 line
Isn't it the same: 'unsigned int' and '
uint32_t'?Quoted 13 lines
No, or else there wouldn't have been a need to introduce uint<N>_t (and
others) in C99. It just so happens that right now all architectures Xen
can be built for have sizeof(int) == 4 andCHAR_BITS== 8. In an arch-
specific header I would see this as less of an issue, but in a generic
header we'd better avoid encoding wrong assumptions. The one assumption
we generally make is that sizeof(int) >= 4 andCHAR_BITS>= 8 (albeit I
bet really in various places we assumeCHAR_BITS== 8).In this case we have to switch to uint<N>_t.
Thanks for the explanation. I'll update this part of code in the next patch version.Quoted 15 lines
Quoted 7 lines
Quoted 4 lines
Also you want to make sure
asm-generic/bitops/bitops-bits.his really in use here, or else an arch overriding / not using that header may end up screwed.I am not really understand what do you mean. Could you please explain a
little bit more.Whichever type you use here, it needs to be in sync with
BITOP_BITS_PER_WORD. Hence you want to include the _local_ bitops-bits.h
here, such that in case of an inconsistent override by an arch the compiler would complain about the two differring #define-s. (IOW an arch overridingBITOP_BITS_PER_WORDcannot re-use this header as-is.)Quoted 3 lines
The same may, btw, be true for others of the new headers you add - the
same #include would therefore be needed there as well.Now it clear to me.
It seems like
BITOP_BITS_PER_WORD,BITOP_MASK,BITOP_WORD, andBITS_PER_BYTEare defined in {arm, ppc,riscv}/include/asm/bitops.h. I expected that any architecture planning to use asm-generic/bitops/bitops-bits.hwould include it at the beginning of <arch>/include/asm/bitops.h, similar to what is done for RISC-V:#ifndef _ASM_RISCV_BITOPS_H #define _ASM_RISCV_BITOPS_H #include <asm/system.h> #include <asm-generic/bitops/bitops-bits.h> ...But in this case, to allow architecture overrides macros, it is necessary to update
asm-generic/bitops/bitops-bits.h:
Quoted 8 lines
#ifndef BITOP_BITS_PER_WORD #define BITOP_BITS_PER_WORD 32 #endif...
Therefore, if an architecture needs to override something, it will add #define ... before #include <asm-generic/bitops/bitops-bits.h>.Does it make sense?
Sure. But then the arch also needs to provide a corresponding typedef (and bitops-bits.h the fallback one), for use wherever you use any of those #define-s.
Jan
Re: [PATCH v3 10/34] xen/riscv: introduce bitops.h
Quoted 52 lines
Quoted 52 lines
Quoted 21 lines
Quoted 9 lines
Quoted 6 lines
Also you want to make sure
asm-generic/bitops/bitops-bits.his
really in use here, or else an arch overriding / not using that
header may end up screwed.I am not really understand what do you mean. Could you please explain a
little bit more.Whichever type you use here, it needs to be in sync with
BITOP_BITS_PER_WORD. Hence you want to include the _local_ bitops-bits.h
here, such that in case of an inconsistent override by an arch the
compiler would complain about the two differring #define-s. (IOW an
arch overridingBITOP_BITS_PER_WORDcannot re-use this header as- is.)Quoted 4 lines
The same may, btw, be true for others of the new headers you add -
the
same #include would therefore be needed there as well.Now it clear to me.
It seems like
BITOP_BITS_PER_WORD,BITOP_MASK,BITOP_WORD, andBITS_PER_BYTEare defined in {arm, ppc,riscv}/include/asm/bitops.h.
I expected that any architecture planning to use asm-generic/bitops/bitops-bits.hwould include it at the beginning of <arch>/include/asm/bitops.h, similar to what is done for RISC-V:
#ifndef_ASM_RISCV_BITOPS_H
#define_ASM_RISCV_BITOPS_H
#include <asm/system.h>
#include <asm-generic/bitops/bitops-bits.h>
...But in this case, to allow architecture overrides macros, it is necessary to update
asm-generic/bitops/bitops-bits.h:
#ifndefBITOP_BITS_PER_WORD
#define BITOP_BITS_PER_WORD 32
#endif
...
Therefore, if an architecture needs to override something, it will add
#define ... before #include <asm-generic/bitops/bitops-bits.h>.
Quoted 5 lines
Quoted 1 line
Does it make sense?
Sure. But then the arch also needs to provide a corresponding typedef (and
bitops-bits.hthe fallback one), for use wherever you use any of those #define-s.
Which one typedef is needed to provide? <asm-generic/bitops/bitops-bits.h> contains only macros.
~ Oleksii
Re: [PATCH v3 10/34] xen/riscv: introduce bitops.h
Quoted 52 lines · Oleksii
Quoted 52 lines
Quoted 52 lines
Quoted 21 lines
Quoted 9 lines
Quoted 6 lines
Also you want to make sure
asm-generic/bitops/bitops-bits.his
really in use here, or else an arch overriding / not using that
header may end up screwed.I am not really understand what do you mean. Could you please explain a
little bit more.Whichever type you use here, it needs to be in sync with
BITOP_BITS_PER_WORD. Hence you want to include the _local_ bitops-bits.h
here, such that in case of an inconsistent override by an arch the
compiler would complain about the two differring #define-s. (IOW an
arch overridingBITOP_BITS_PER_WORDcannot re-use this header as- is.)Quoted 4 lines
The same may, btw, be true for others of the new headers you add -
the
same #include would therefore be needed there as well.Now it clear to me.
It seems like
BITOP_BITS_PER_WORD,BITOP_MASK,BITOP_WORD, andBITS_PER_BYTEare defined in {arm, ppc,riscv}/include/asm/bitops.h.
I expected that any architecture planning to use asm-generic/bitops/bitops-bits.hwould include it at the beginning of <arch>/include/asm/bitops.h, similar to what is done for RISC-V:
#ifndef_ASM_RISCV_BITOPS_H
#define_ASM_RISCV_BITOPS_H
#include <asm/system.h>
#include <asm-generic/bitops/bitops-bits.h>
...But in this case, to allow architecture overrides macros, it is necessary to update
asm-generic/bitops/bitops-bits.h:
#ifndefBITOP_BITS_PER_WORD
#define BITOP_BITS_PER_WORD 32
#endif
...
Therefore, if an architecture needs to override something, it will add
#define ... before #include <asm-generic/bitops/bitops-bits.h>.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
Does it make sense?
Sure. But then the arch also needs to provide a corresponding typedef (and
bitops-bits.hthe fallback one), for use wherever you use any of those #define-s.Which one typedef is needed to provide? <
asm-generic/bitops/bitops-bits.h> contains only macros.
A new one, to replace where right now you use "unsigned int" and I initially said you need to use "uint32_t" instead. With what you said earlier, uint32_t won't work there (anymore).
Jan
Re: [PATCH v3 10/34] xen/riscv: introduce bitops.h
Quoted 70 lines · Jan Beulich
Quoted 69 lines · Oleksii
Quoted 69 lines
Quoted 62 lines
Quoted 27 lines
Quoted 8 lines
Quoted 8 lines
Also you want to make sure asm-generic/bitops/bitops-
bits.h
is
really in use here, or else an arch overriding / not using
that
header may end up screwed.Quoted 4 lines
I am not really understand what do you mean. Could you please
explain a
little bit more.Whichever type you use here, it needs to be in sync with
BITOP_BITS_PER_WORD. Hence you want to include the _local_ bitops-bits.h
here, such that in case of an inconsistent override by an arch
the
compiler would complain about the two differring #define-s. (IOW
an
arch overridingBITOP_BITS_PER_WORDcannot re-use this header as-
is.)Quoted 5 lines
The same may, btw, be true for others of the new headers you add
-
the
same #include would therefore be needed there as well.Now it clear to me.
It seems like
BITOP_BITS_PER_WORD,BITOP_MASK,BITOP_WORD, andBITS_PER_BYTEare defined in {arm, ppc,riscv}/include/asm/bitops.h.
I expected that any architecture planning to use asm-generic/bitops/bitops-bits.hwould include it at the beginning of
<arch>/include/asm/bitops.h, similar to what is done for RISC- V:
#ifndef_ASM_RISCV_BITOPS_H
#define_ASM_RISCV_BITOPS_H
#include <asm/system.h>
#include <asm-generic/bitops/bitops-bits.h>
...But in this case, to allow architecture overrides macros, it is necessary to update
asm-generic/bitops/bitops-bits.h:
#ifndefBITOP_BITS_PER_WORD
#define BITOP_BITS_PER_WORD 32
#endif
...
Therefore, if an architecture needs to override something, it will
add
#define ... before #include <asm-generic/bitops/bitops-bits.h>.Quoted 1 line
Does it make sense?
Sure. But then the arch also needs to provide a corresponding typedef
(andbitops-bits.hthe fallback one), for use wherever you use any of
those #define-s.
Quoted 6 lines
Quoted 2 lines
Which one typedef is needed to provide? <
asm-generic/bitops/bitops-bits.h> contains only macros.A new one, to replace where right now you use "unsigned int" and I initially said you need to use "
uint32_t" instead. With what you said earlier,uint32_twon't work there (anymore).
Wouldn't it be enough just to "#include <xen/types.h>" in headers where "uint32_t" is used?
~ Olkesii
Re: [PATCH v3 10/34] xen/riscv: introduce bitops.h
Quoted 71 lines · Oleksii
Quoted 70 lines · Jan Beulich
Quoted 69 lines · Oleksii
Quoted 69 lines
Quoted 62 lines
Quoted 27 lines
Quoted 8 lines
Quoted 8 lines
Also you want to make sure asm-generic/bitops/bitops-
bits.h
is
really in use here, or else an arch overriding / not using
that
header may end up screwed.Quoted 4 lines
I am not really understand what do you mean. Could you please
explain a
little bit more.Whichever type you use here, it needs to be in sync with
BITOP_BITS_PER_WORD. Hence you want to include the _local_ bitops-bits.h
here, such that in case of an inconsistent override by an arch
the
compiler would complain about the two differring #define-s. (IOW
an
arch overridingBITOP_BITS_PER_WORDcannot re-use this header as-
is.)Quoted 5 lines
The same may, btw, be true for others of the new headers you add
-
the
same #include would therefore be needed there as well.Now it clear to me.
It seems like
BITOP_BITS_PER_WORD,BITOP_MASK,BITOP_WORD, andBITS_PER_BYTEare defined in {arm, ppc,riscv}/include/asm/bitops.h.
I expected that any architecture planning to use asm-generic/bitops/bitops-bits.hwould include it at the beginning of
<arch>/include/asm/bitops.h, similar to what is done for RISC- V:
#ifndef_ASM_RISCV_BITOPS_H
#define_ASM_RISCV_BITOPS_H
#include <asm/system.h>
#include <asm-generic/bitops/bitops-bits.h>
...But in this case, to allow architecture overrides macros, it is necessary to update
asm-generic/bitops/bitops-bits.h:
#ifndefBITOP_BITS_PER_WORD
#define BITOP_BITS_PER_WORD 32
#endif
...
Therefore, if an architecture needs to override something, it will
add
#define ... before #include <asm-generic/bitops/bitops-bits.h>.Quoted 1 line
Does it make sense?
Sure. But then the arch also needs to provide a corresponding typedef
(andbitops-bits.hthe fallback one), for use wherever you use any of
those #define-s.
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
Which one typedef is needed to provide? <
asm-generic/bitops/bitops-bits.h> contains only macros.A new one, to replace where right now you use "unsigned int" and I initially said you need to use "
uint32_t" instead. With what you said earlier,uint32_twon't work there (anymore).Wouldn't it be enough just to "#include <
xen/types.h>" in headers where "uint32_t" is used?
No, my point wasn't to make uint32_t available. We need a _separate_ typedef which matches the #define-s. Otherwise, if an arch defines BITOP_BITS_PER_WORD to, say, 64, this generic code would do the wrong thing.
Jan
Re: [PATCH v3 10/34] xen/riscv: introduce bitops.h
Quoted 91 lines · Jan Beulich
Quoted 90 lines · Oleksii
Quoted 89 lines · Jan Beulich
Quoted 74 lines · Oleksii
Quoted 74 lines
Quoted 73 lines
Quoted 30 lines
Quoted 8 lines
Quoted 8 lines
Also you want to make sure asm-generic/bitops/bitops-
bits.h
is
really in use here, or else an arch overriding / not using
that
header may end up screwed.Quoted 4 lines
I am not really understand what do you mean. Could you please
explain a
little bit more.Whichever type you use here, it needs to be in sync with
BITOP_BITS_PER_WORD. Hence you want to include the _local_
bitops-bits.h
here, such that in case of an inconsistent override by an arch
the
compiler would complain about the two differring #define- s.
(IOW
an
arch overridingBITOP_BITS_PER_WORDcannot re-use this header
as-
is.)Quoted 6 lines
The same may, btw, be true for others of the new headers you
add
-
the
same #include would therefore be needed there as well.Now it clear to me.
It seems like
BITOP_BITS_PER_WORD,BITOP_MASK,BITOP_WORD, andBITS_PER_BYTEare defined in {arm, ppc,riscv}/include/asm/bitops.h.
I expected that any architecture planning to use asm-generic/bitops/bitops-bits.hwould include it at the beginning
of
<arch>/include/asm/bitops.h, similar to what is done for RISC-
V:
#ifndef_ASM_RISCV_BITOPS_H
#define_ASM_RISCV_BITOPS_H
#include <asm/system.h>
#include <asm-generic/bitops/bitops-bits.h>
...But in this case, to allow architecture overrides macros, it is
necessary to updateasm-generic/bitops/bitops-bits.h:
#ifndefBITOP_BITS_PER_WORD
#define BITOP_BITS_PER_WORD 32
#endif
...
Therefore, if an architecture needs to override something, it
will
add
#define ... before #include <asm-generic/bitops/bitops-bits.h>.Does it make sense?
Quoted 8 lines
Quoted 6 lines
Sure. But then the arch also needs to provide a corresponding typedef
(andbitops-bits.hthe fallback one), for use wherever you use
any of
those #define-s.Which one typedef is needed to provide? <
asm-generic/bitops/bitops-bits.h> contains only macros.A new one, to replace where right now you use "unsigned int" and I
initially said you need to use "uint32_t" instead. With what you said
earlier,uint32_twon't work there (anymore).
Quoted 8 lines
Quoted 3 lines
Wouldn't it be enough just to "#include <
xen/types.h>" in headers where
"uint32_t" is used?No, my point wasn't to make
uint32_tavailable. We need a _separate_ typedef which matches the #define-s. Otherwise, if an arch definesBITOP_BITS_PER_WORDto, say, 64, this generic code would do the wrong thing.
Oh, yeah this is true.
We have to introduce in bitops-bits.h:
typedef uint_32t bitops_type;
And then use it in function such as test_bit:
static inline int test_bit(int nr, const volatile void *addr)
{
const volatile bitops_type *p = addr;
return 1 & (p[BITOP_WORD(nr)] >> (nr & (BITOP_BITS_PER_WORD - 1)));
}
Thanks for clarification.
~ Oleksii
Re: [PATCH v3 10/34] xen/riscv: introduce bitops.h
Quoted 96 lines · Oleksii
Quoted 95 lines · Jan Beulich
Quoted 93 lines · Oleksii
Quoted 81 lines · Jan Beulich
Quoted 80 lines · Oleksii
Quoted 80 lines
Quoted 72 lines
Quoted 30 lines
Quoted 8 lines
Quoted 8 lines
Also you want to make sure asm-generic/bitops/bitops-
bits.h
is
really in use here, or else an arch overriding / not using
that
header may end up screwed.Quoted 4 lines
I am not really understand what do you mean. Could you please
explain a
little bit more.Whichever type you use here, it needs to be in sync with
BITOP_BITS_PER_WORD. Hence you want to include the _local_
bitops-bits.h
here, such that in case of an inconsistent override by an arch
the
compiler would complain about the two differring #define- s.
(IOW
an
arch overridingBITOP_BITS_PER_WORDcannot re-use this header
as-
is.)Quoted 6 lines
The same may, btw, be true for others of the new headers you
add
-
the
same #include would therefore be needed there as well.Now it clear to me.
It seems like
BITOP_BITS_PER_WORD,BITOP_MASK,BITOP_WORD, andBITS_PER_BYTEare defined in {arm, ppc,riscv}/include/asm/bitops.h.
I expected that any architecture planning to use asm-generic/bitops/bitops-bits.hwould include it at the beginning
of
<arch>/include/asm/bitops.h, similar to what is done for RISC-
V:
#ifndef_ASM_RISCV_BITOPS_H
#define_ASM_RISCV_BITOPS_H
#include <asm/system.h>
#include <asm-generic/bitops/bitops-bits.h>
...But in this case, to allow architecture overrides macros, it is
necessary to updateasm-generic/bitops/bitops-bits.h:
#ifndefBITOP_BITS_PER_WORD
#define BITOP_BITS_PER_WORD 32
#endif
...
Therefore, if an architecture needs to override something, it
will
add
#define ... before #include <asm-generic/bitops/bitops-bits.h>.Quoted 1 line
Does it make sense?
Sure. But then the arch also needs to provide a corresponding typedef
(andbitops-bits.hthe fallback one), for use wherever you use
any of
those #define-s.Quoted 8 lines
Quoted 2 lines
Which one typedef is needed to provide? <
asm-generic/bitops/bitops-bits.h> contains only macros.A new one, to replace where right now you use "unsigned int" and I
initially said you need to use "uint32_t" instead. With what you said
earlier,uint32_twon't work there (anymore).Wouldn't it be enough just to "#include <
xen/types.h>" in headers where
"uint32_t" is used?
Quoted 8 lines
Quoted 4 lines
No, my point wasn't to make
uint32_tavailable. We need a _separate_ typedef which matches the #define-s. Otherwise, if an arch definesBITOP_BITS_PER_WORDto, say, 64, this generic code would do the wrong thing.Oh, yeah this is true.
We have to introduce in
bitops-bits.h:typedef uint_32t bitops_type;
Perhaps e.g.
typedef uint32_t bitops_uint_t;
though.
Jan
Quoted 11 lines
And then use it in function such as
test_bit:static inline int test_bit(int nr, const volatile void *addr) { const volatile bitops_type *p = addr; return 1 & (p[BITOP_WORD(nr)] >> (nr & (BITOP_BITS_PER_WORD - 1))); }Thanks for clarification.
~ Oleksii
Re: [PATCH v3 10/34] xen/riscv: introduce bitops.h
In reply to Oleksii Kurochkoxen/include/asm-generic/bitops/bitops-bits.h line 8
Quoted 11 lines · Oleksii Kurochko
xen/include/asm-generic/bitops/bitops-bits.h new file +8
-0@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_BITS_H_ +#define _ASM_GENERIC_BITOPS_BITS_H_ + +#define BITOP_BITS_PER_WORD 32 +#define BITOP_MASK (nr) (1UL << ((nr) % BITOP_BITS_PER_WORD)) +#define BITOP_WORD (nr) ((nr) / BITOP_BITS_PER_WORD) +#define BITS_PER_BYTE 8
Btw, I can't spot a use of BITS_PER_BYTE. Why do you add it? And if it really needed adding, it surely wouldn't belong here.
Jan
Re: [PATCH v3 10/34] xen/riscv: introduce bitops.h
Quoted 16 lines · Jan Beulich
xen/include/asm-generic/bitops/bitops-bits.h line 8
Quoted 12 lines · Oleksii Kurochko
xen/include/asm-generic/bitops/bitops-bits.h new file +6
-0@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_BITS_H_ +#define _ASM_GENERIC_BITOPS_BITS_H_ + +#define BITOP_BITS_PER_WORD 32 +#define BITOP_MASK (nr) (1UL << ((nr) %
BITOP_BITS_PER_WORD))xen/include/asm-generic/bitops/bitops-bits.h new file +2
-0+#define BITOP_WORD (nr) ((nr) / BITOP_BITS_PER_WORD) +#define BITS_PER_BYTE 8Btw, I can't spot a use of
BITS_PER_BYTE. Why do you add it? And if it really needed adding, it surely wouldn't belong here.
It is used in common/bitmap.c and ns16550.c, and inside some arch code, but it is not used by RISC-V right now.
Would it be better to define it in config.h?
~ Oleksii
Re: [PATCH v3 10/34] xen/riscv: introduce bitops.h
Quoted 17 lines · Oleksii
Quoted 16 lines · Jan Beulich
xen/include/asm-generic/bitops/bitops-bits.h line 8
Quoted 12 lines · Oleksii Kurochko
xen/include/asm-generic/bitops/bitops-bits.h new file +6
-0@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_BITS_H_ +#define _ASM_GENERIC_BITOPS_BITS_H_ + +#define BITOP_BITS_PER_WORD 32 +#define BITOP_MASK (nr) (1UL << ((nr) %
BITOP_BITS_PER_WORD))xen/include/asm-generic/bitops/bitops-bits.h new file +2
-0+#define BITOP_WORD (nr) ((nr) / BITOP_BITS_PER_WORD) +#define BITS_PER_BYTE 8Btw, I can't spot a use of
BITS_PER_BYTE. Why do you add it? And if it really needed adding, it surely wouldn't belong here.
Quoted 4 lines
It is used in
common/bitmap.candns16550.c, and inside some arch code, but it is not used by RISC-V right now.Would it be better to define it in
config.h?
Yes, perhaps. Imo this shouldn't have a "generic" fallback; every arch should explicitly state this (along with e.g. BITS_PER_LONG).
Jan
Re: [PATCH v3 10/34] xen/riscv: introduce bitops.h
Quoted 23 lines · Jan Beulich
Quoted 22 lines · Oleksii
Quoted 17 lines · Jan Beulich
xen/include/asm-generic/bitops/bitops-bits.h line 8
Quoted 12 lines · Oleksii Kurochko
xen/include/asm-generic/bitops/bitops-bits.h new file +6
-0@@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef _ASM_GENERIC_BITOPS_BITS_H_ +#define _ASM_GENERIC_BITOPS_BITS_H_ + +#define BITOP_BITS_PER_WORD 32 +#define BITOP_MASK (nr) (1UL << ((nr) %
BITOP_BITS_PER_WORD))xen/include/asm-generic/bitops/bitops-bits.h new file +2
-0+#define BITOP_WORD (nr) ((nr) / BITOP_BITS_PER_WORD) +#define BITS_PER_BYTE 8Btw, I can't spot a use of
BITS_PER_BYTE. Why do you add it? And if
it really needed adding, it surely wouldn't belong here.It is used in
common/bitmap.candns16550.c, and inside some arch code,
but it is not used by RISC-V right now.
Quoted 5 lines
Quoted 1 line
Would it be better to define it in
config.h?Yes, perhaps. Imo this shouldn't have a "generic" fallback; every arch
should explicitly state this (along with e.g.BITS_PER_LONG).
Got it. Thanks.
~ Oleksii
PATCH v3 11/34 xen/riscv: introduce flushtlb.h
In reply to Oleksii Kurochko---
Changes in V3:
- add SPDX & footer
- add Acked-by: Jan Beulich <[email protected]>
---
Changes in V2:
- Nothing changed. Only rebase.
--- xen/arch/riscv/include/asm/flushtlb.h | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 xen/arch/riscv/include/asm/flushtlb.h
xen/arch/riscv/include/asm/flushtlb.h new file +33 -0
@@ -0,0 +1,33 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_RISCV_FLUSHTLB_H__ +#define __ASM_RISCV_FLUSHTLB_H__ + +#include <xen/cpumask.h> + +/* +* Filter the given set of CPUs, removing those that definitely flushed their +* TLB since @page_timestamp. +*/ +/* XXX lazy implementation just doesn't clear anything.... */ +static inline void tlbflush_filter (cpumask_t *mask,uint32_t page_timestamp) {} + +#define tlbflush_current_time () (0) + +static inline void page_set_tlbflush_timestamp (struct page_info *page) +{ +BUG (); +} + +/* Flush specified CPUs' TLBs */ +void arch_flush_tlb_mask (const cpumask_t *mask); + +#endif /* __ASM_RISCV_FLUSHTLB_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
2.43.0
PATCH v3 12/34 xen/riscv: introduce smp.h
In reply to Oleksii Kurochko---
Changes in V3:
- drop cpu_is_offline() as it was moved to xen/smp.h.
- add SPDX.
- drop unnessary #ifdef.
- fix "No new line"
- update the commit message
---
Changes in V2:
- Nothing changed. Only rebase.
--- xen/arch/riscv/include/asm/smp.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 xen/arch/riscv/include/asm/smp.h
xen/arch/riscv/include/asm/smp.h new file +28 -0
@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_RISCV_SMP_H +#define __ASM_RISCV_SMP_H + +#include <xen/cpumask.h> +#include <xen/percpu.h> + +DECLARE_PER_CPU (cpumask_var_t, cpu_sibling_mask); +DECLARE_PER_CPU (cpumask_var_t, cpu_core_mask); + +#define cpu_is_offline (cpu) unlikely(!cpu_online(cpu)) + +/* +* Do we, for platform reasons, need to actually keep CPUs online when we +* would otherwise prefer them to be off? +*/ +#define park_offline_cpus false + +#endif + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
2.43.0
Re: [PATCH v3 12/34] xen/riscv: introduce smp.h
Quoted 4 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- dropcpu_is_offline()as it was moved toxen/smp.h.
Hmm.
Quoted 4 lines
- add SPDX.
- drop unnessary #ifdef.
- fix "No new line"
- update the commit message
And another hmm.
Quoted 4 lines
xen/arch/riscv/include/asm/smp.h new file +1
-0@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-only */
xen/arch/riscv/include/asm/smp.h line 11
Quoted 10 lines
xen/arch/riscv/include/asm/smp.h new file +10
-0+#ifndef __ASM_RISCV_SMP_H +#define __ASM_RISCV_SMP_H + +#include <xen/cpumask.h> +#include <xen/percpu.h> + +DECLARE_PER_CPU (cpumask_var_t, cpu_sibling_mask); +DECLARE_PER_CPU (cpumask_var_t, cpu_core_mask); + +#define cpu_is_offline (cpu) unlikely(!cpu_online(cpu))
This clearly wasn't dropped (yet).
Jan
Re: [PATCH v3 12/34] xen/riscv: introduce smp.h
Quoted 6 lines · Jan Beulich
Quoted 4 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- dropcpu_is_offline()as it was moved toxen/smp.h.
Quoted 8 lines
Hmm.
Quoted 4 lines
- add SPDX.
- drop unnessary #ifdef.
- fix "No new line"
- update the commit messageAnd another hmm.
It was removed word "asm/" before smp.h, but yes it is not correct to write commit "message" should be "title".
I'll be more precise next time.
Quoted 17 lines
Quoted 5 lines
xen/arch/riscv/include/asm/smp.h new file +1
-0@@ -0,0 +1,28 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ xen/arch/riscv/include/asm/smp.h line 11
Quoted 10 lines
xen/arch/riscv/include/asm/smp.h new file +10
-0+#ifndef __ASM_RISCV_SMP_H +#define __ASM_RISCV_SMP_H + +#include <xen/cpumask.h> +#include <xen/percpu.h> + +DECLARE_PER_CPU (cpumask_var_t, cpu_sibling_mask); +DECLARE_PER_CPU (cpumask_var_t, cpu_core_mask); + +#define cpu_is_offline (cpu) unlikely(!cpu_online(cpu))This clearly wasn't dropped (yet).
It looks like it was rebasing issue.
I'll handle that in the next patch version.
Thanks.
~ Oleksii
PATCH v3 13/34 xen/riscv: introduce cmpxchg.h
In reply to Oleksii KurochkoThe header was taken from Linux kernl 6.4.0-rc1.
Addionally, were updated:
* add emulation of {cmp}xchg for 1/2 byte types
* replace tabs with spaces
* replace __* varialbed with *__
---
Changes in V3:
- update the commit message
- add emulation of {cmp}xchg_... for 1 and 2 bytes types
---
Changes in V2:
- update the comment at the top of the header.
- change xen/lib.h to xen/bug.h.
- sort inclusion of headers properly.
--- xen/arch/riscv/include/asm/cmpxchg.h | 496 +++++++++++++++++++++++++++ 1 file changed, 496 insertions(+) create mode 100644 xen/arch/riscv/include/asm/cmpxchg.h
xen/arch/riscv/include/asm/cmpxchg.h new file +496 -0
@@ -0,0 +1,496 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2014 Regents of the University of California */ + +#ifndef _ASM_RISCV_CMPXCHG_H +#define _ASM_RISCV_CMPXCHG_H + +#include <xen/compiler.h> +#include <xen/lib.h> + +#include <asm/fence.h> +#include <asm/io.h> +#include <asm/system.h> + +#define __xchg_relaxed (ptr, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(new) new__ = (new); \ + __typeof__(*(ptr)) ret__; \ + switch (size) \ + { \ + case 4: \ + asm volatile( \ + " amoswap.w %0, %2, %1\n" \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory" ); \ + break; \ + case 8: \ + asm volatile( \ + " amoswap.d %0, %2, %1\n" \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory" ); \ + break; \ + default: \ + ASSERT_UNREACHABLE(); \ + } \ + ret__; \ +}) + +#define xchg_relaxed (ptr, x) \ +({ \ + __typeof__(*(ptr)) x_ = (x); \ + (__typeof__(*(ptr))) __xchg_relaxed((ptr), x_, sizeof(*(ptr))); \ +}) + +#define __xchg_acquire (ptr, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(new) new__ = (new); \ + __typeof__(*(ptr)) ret__; \ + switch (size) \ + { \ + case 4: \ + asm volatile( \ + " amoswap.w %0, %2, %1\n" \ + RISCV_ACQUIRE_BARRIER \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory" ); \ + break; \ + case 8: \ + asm volatile( \ + " amoswap.d %0, %2, %1\n" \ + RISCV_ACQUIRE_BARRIER \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory" ); \ + break; \ + default: \ + ASSERT_UNREACHABLE(); \ + } \ + ret__; \ +}) + +#define xchg_acquire (ptr, x) \ +({ \ + __typeof__(*(ptr)) x_ = (x); \ + (__typeof__(*(ptr))) __xchg_acquire((ptr), x_, sizeof(*(ptr))); \ +}) + +#define __xchg_release (ptr, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(new) new__ = (new); \ + __typeof__(*(ptr)) ret__; \ + switch (size) \ + { \ + case 4: \ + asm volatile ( \ + RISCV_RELEASE_BARRIER \ + " amoswap.w %0, %2, %1\n" \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory"); \ + break; \ + case 8: \ + asm volatile ( \ + RISCV_RELEASE_BARRIER \ + " amoswap.d %0, %2, %1\n" \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory"); \ + break; \ + default: \ + ASSERT_UNREACHABLE(); \ + } \ + ret__; \ +}) + +#define xchg_release (ptr, x) \ +({ \ + __typeof__(*(ptr)) x_ = (x); \ + (__typeof__(*(ptr))) __xchg_release((ptr), x_, sizeof(*(ptr))); \ +}) + +static always_inline uint32_t __xchg_case_4(volatile uint32_t *ptr, +uint32_t new) +{ + __typeof__(*(ptr)) ret; + + asmvolatile ( +" amoswap.w.aqrl %0, %2, %1\n" + :"=r" (ret),"+A" (*ptr) + :"r" (new) + :"memory" ); + +return ret; +} + +static always_inline uint64_t __xchg_case_8(volatile uint64_t *ptr, +uint64_t new) +{ + __typeof__(*(ptr)) ret; + + asmvolatile ( \ +" amoswap.d.aqrl %0, %2, %1\n" \ + :"=r" (ret),"+A" (*ptr) \ + :"r" (new) \ + :"memory" ); \ + +return ret; +} + +static always_inline unsigned short __cmpxchg_case_2 (volatile uint32_t *ptr, +uint32_t old, +uint32_t new); + +static always_inline unsigned short __cmpxchg_case_1 (volatile uint32_t *ptr, +uint32_t old, +uint32_t new); + +static inline unsigned long __xchg (volatile void *ptr,unsigned long x,int size) +{ +switch (size) { +case 1 : +return __cmpxchg_case_1 (ptr, (uint32_t )-1 , x); +case 2 : +return __cmpxchg_case_2 (ptr, (uint32_t )-1 , x); +case 4 : +return __xchg_case_4 (ptr, x); +case 8 : +return __xchg_case_8 (ptr, x); +default : +ASSERT_UNREACHABLE (); + } + +return -1 ; +} + +#define xchg (ptr,x) \ +({ \ + __typeof__(*(ptr)) ret__; \ + ret__ = (__typeof__(*(ptr))) \ + __xchg((ptr), (unsigned long)(x), sizeof(*(ptr))); \ + ret__; \ +}) + +#define xchg32 (ptr, x) \ +({ \ + BUILD_BUG_ON(sizeof(*(ptr)) != 4); \ + xchg((ptr), (x)); \ +}) + +#define xchg64 (ptr, x) \ +({ \ + BUILD_BUG_ON(sizeof(*(ptr)) != 8); \ + xchg((ptr), (x)); \ +}) + +/* +* Atomic compare and exchange. Compare OLD with MEM, if identical, +* store NEW in MEM. Return the initial value in MEM. Success is +* indicated by comparing RETURN with OLD. +*/ +#define __cmpxchg_relaxed (ptr, old, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(*(ptr)) __old = (old); \ + __typeof__(*(ptr)) new__ = (new); \ + __typeof__(*(ptr)) ret__; \ + register unsigned int __rc; \ + switch (size) \ + { \ + case 4: \ + asm volatile( \ + "0: lr.w %0, %2\n" \ + " bne %0, %z3, 1f\n" \ + " sc.w %1, %z4, %2\n" \ + " bnez %1, 0b\n" \ + "1:\n" \ + : "=&r" (ret__), "=&r" (__rc), "+A" (*ptr__) \ + : "rJ" (__old), "rJ" (new__) \ + : "memory"); \ + break; \ + case 8: \ + asm volatile( \ + "0: lr.d %0, %2\n" \ + " bne %0, %z3, 1f\n" \ + " sc.d %1, %z4, %2\n" \ + " bnez %1, 0b\n" \ + "1:\n" \ + : "=&r" (ret__), "=&r" (__rc), "+A" (*ptr__) \ + : "rJ" (__old), "rJ" (new__) \ + : "memory"); \ + break; \ + default: \ + ASSERT_UNREACHABLE(); \ + } \ + ret__; \ +}) + +#define cmpxchg_relaxed (ptr, o, n) \ +({ \ + __typeof__(*(ptr)) o_ = (o); \ + __typeof__(*(ptr)) n_ = (n); \ + (__typeof__(*(ptr))) __cmpxchg_relaxed((ptr), \ + o_, n_, sizeof(*(ptr))); \ +}) + +#define __cmpxchg_acquire (ptr, old, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(*(ptr)) __old = (old); \ + __typeof__(*(ptr)) new__ = (new); \ + __typeof__(*(ptr)) ret__; \ + register unsigned int __rc; \ + switch (size) \ + { \ + case 4: \ + asm volatile( \ + "0: lr.w %0, %2\n" \ + " bne %0, %z3, 1f\n" \ + " sc.w %1, %z4, %2\n" \ + " bnez %1, 0b\n" \ + RISCV_ACQUIRE_BARRIER \ + "1:\n" \ + : "=&r" (ret__), "=&r" (__rc), "+A" (*ptr__) \ + : "rJ" (__old), "rJ" (new__) \ + : "memory"); \ + break; \ + case 8: \ + asm volatile( \ + "0: lr.d %0, %2\n" \ + " bne %0, %z3, 1f\n" \ + " sc.d %1, %z4, %2\n" \ + " bnez %1, 0b\n" \ + RISCV_ACQUIRE_BARRIER \ + "1:\n" \ + : "=&r" (ret__), "=&r" (__rc), "+A" (*ptr__) \ + : "rJ" (__old), "rJ" (new__) \ + : "memory"); \ + break; \ + default: \ + ASSERT_UNREACHABLE(); \ + } \ + ret__; \ +}) + +#define cmpxchg_acquire (ptr, o, n) \ +({ \ + __typeof__(*(ptr)) o_ = (o); \ + __typeof__(*(ptr)) n_ = (n); \ + (__typeof__(*(ptr))) __cmpxchg_acquire((ptr), o_, n_, sizeof(*(ptr))); \ +}) + +#define __cmpxchg_release (ptr, old, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(*(ptr)) __old = (old); \ + __typeof__(*(ptr)) new__ = (new); \ + __typeof__(*(ptr)) ret__; \ + register unsigned int __rc; \ + switch (size) \ + { \ + case 4: \ + asm volatile ( \ + RISCV_RELEASE_BARRIER \ + "0: lr.w %0, %2\n" \ + " bne %0, %z3, 1f\n" \ + " sc.w %1, %z4, %2\n" \ + " bnez %1, 0b\n" \ + "1:\n" \ + : "=&r" (ret__), "=&r" (__rc), "+A" (*ptr__) \ + : "rJ" (__old), "rJ" (new__) \ + : "memory" ); \ + break; \ + case 8: \ + asm volatile ( \ + RISCV_RELEASE_BARRIER \ + "0: lr.d %0, %2\n" \ + " bne %0, %z3, 1f\n" \ + " sc.d %1, %z4, %2\n" \ + " bnez %1, 0b\n" \ + "1:\n" \ + : "=&r" (ret__), "=&r" (__rc), "+A" (*ptr__) \ + : "rJ" (__old), "rJ" (new__) \ + : "memory" ); \ + break; \ + default: \ + ASSERT_UNREACHABLE(); \ + } \ + ret__; \ +}) + +#define cmpxchg_release (ptr, o, n) \ +({ \ + __typeof__(*(ptr)) _o_ = (o); \ + __typeof__(*(ptr)) _n_ = (n); \ + (__typeof__(*(ptr))) __cmpxchg_release((ptr), _o_, _n_, sizeof(*(ptr))); \ +}) + +static always_inline uint32_t __cmpxchg_case_4(volatile uint32_t *ptr, +uint32_t old, +uint32_t new) +{ +uint32_t ret; + registeruint32_t rc; + + asmvolatile ( +"0: lr.w %0, %2\n" +" bne %0, %z3, 1f\n" +" sc.w.rl %1, %z4, %2\n" +" bnez %1, 0b\n" +" fence rw, rw\n" +"1:\n" + :"=&r" (ret),"=&r" (rc),"+A" (*ptr) + :"rJ" (old),"rJ" (new) + :"memory" ); + +return ret; +} + +static always_inline uint64_t __cmpxchg_case_8(volatile uint64_t *ptr, +uint64_t old, +uint64_t new) +{ +uint64_t ret; + registeruint32_t rc; + + asmvolatile ( +"0: lr.d %0, %2\n" +" bne %0, %z3, 1f\n" +" sc.d.rl %1, %z4, %2\n" +" bnez %1, 0b\n" +" fence rw, rw\n" +"1:\n" + :"=&r" (ret),"=&r" (rc),"+A" (*ptr) + :"rJ" (old),"rJ" (new) + :"memory" ); + +return ret; +} + +#define __emulate_cmpxchg_case1_2 (ptr, new, read_func, cmpxchg_func, swap_byte_mask_base)\ +({ \ + __typeof__(*(ptr)) read_val; \ + __typeof__(*(ptr)) swapped_new; \ + __typeof__(*(ptr)) ret; \ + __typeof__(*(ptr)) new_ = (__typeof__(*(ptr)))new; \ + \ + __typeof__(ptr) aligned_ptr = (__typeof__(ptr))((unsigned long)ptr & ~3); \ + __typeof__(*(ptr)) mask_off = ((unsigned long)ptr & 3) * 8; \ + __typeof__(*(ptr)) mask = \ + (__typeof__(*(ptr)))swap_byte_mask_base << mask_off; \ + __typeof__(*(ptr)) masked_new = (new_ << mask_off) & mask; \ + \ + do { \ + read_val = read_func(aligned_ptr); \ + swapped_new = read_val & ~mask; \ + swapped_new |= masked_new; \ + ret = cmpxchg_func(aligned_ptr, read_val, swapped_new); \ + } while ( ret != read_val ); \ + \ + ret = MASK_EXTR(swapped_new, mask); \ + ret; \ +}) + +static always_inline unsigned short __cmpxchg_case_2 (volatile uint32_t *ptr, +uint32_t old, +uint32_t new) +{ + (void ) old; + +if (((unsigned long )ptr &3 ) ==3 ) + { +#ifdef CONFIG_64BIT +return __emulate_cmpxchg_case1_2 ((uint64_t *)ptr, new, + readq, __cmpxchg_case_8,0xffffU ); +#else +#error "add emulation support of cmpxchg for CONFIG_32BIT" +#endif + } +else +return __emulate_cmpxchg_case1_2 ((uint32_t *)ptr, new, + readl, __cmpxchg_case_4,0xffffU ); +} + +static always_inline unsigned short __cmpxchg_case_1 (volatile uint32_t *ptr, +uint32_t old, +uint32_t new) +{ + (void ) old; + +return __emulate_cmpxchg_case1_2 ((uint32_t *)ptr, new, + readl, __cmpxchg_case_4,0xffU ); +} + +static always_inline unsigned long __cmpxchg (volatile void *ptr, +unsigned long old, +unsigned long new, +int size) +{ +switch (size) + { +case 1 : +return __cmpxchg_case_1 (ptr, old, new); +case 2 : +return __cmpxchg_case_2 (ptr, old, new); +case 4 : +return __cmpxchg_case_4 (ptr, old, new); +case 8 : +return __cmpxchg_case_8 (ptr, old, new); +default : +ASSERT_UNREACHABLE (); + } + +return old; +} + +#define cmpxchg (ptr, o, n) \ +({ \ + __typeof__(*(ptr)) ret__; \ + ret__ = (__typeof__(*(ptr))) \ + __cmpxchg((ptr), (unsigned long)(o), (unsigned long)(n), \ + sizeof(*(ptr))); \ + ret__; \ +}) + +#define cmpxchg_local (ptr, o, n) \ + (__cmpxchg_relaxed((ptr), (o), (n), sizeof(*(ptr)))) + +#define cmpxchg32 (ptr, o, n) \ +({ \ + BUILD_BUG_ON(sizeof(*(ptr)) != 4); \ + cmpxchg((ptr), (o), (n)); \ +}) + +#define cmpxchg32_local (ptr, o, n) \ +({ \ + BUILD_BUG_ON(sizeof(*(ptr)) != 4); \ + cmpxchg_relaxed((ptr), (o), (n)) \ +}) + +#define cmpxchg64 (ptr, o, n) \ +({ \ + BUILD_BUG_ON(sizeof(*(ptr)) != 8); \ + cmpxchg((ptr), (o), (n)); \ +}) + +#define cmpxchg64_local (ptr, o, n) \ +({ \ + BUILD_BUG_ON(sizeof(*(ptr)) != 8); \ + cmpxchg_relaxed((ptr), (o), (n)); \ +}) + +#endif /* _ASM_RISCV_CMPXCHG_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
2.43.0
Re: [PATCH v3 13/34] xen/riscv: introduce cmpxchg.h
Quoted 11 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/cmpxchg.h new file +8
-0@@ -0,0 +1,496 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2014 Regents of the University of California */ + +#ifndef _ASM_RISCV_CMPXCHG_H +#define _ASM_RISCV_CMPXCHG_H + +#include <xen/compiler.h> +#include <xen/lib.h>
xen/arch/riscv/include/asm/cmpxchg.h line 18
Quoted 10 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +10
-0+ +#include <asm/fence.h> +#include <asm/io.h> +#include <asm/system.h> + +#define __xchg_relaxed (ptr, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(new) new__ = (new); \ + __typeof__(*(ptr)) ret__; \
I expect the types of new and *ptr want to actually match. Which you then want to enforce, so that issues at use sites would either be reported by the compiler, or be permitted by a type conversion of new.
xen/arch/riscv/include/asm/cmpxchg.h line 20
Quoted 2 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +2
-0+switch (size) \ + { \
Nit: Hard tab left here. (Also again you want to either stick to Linux style or fully switch to Xen style.)
xen/arch/riscv/include/asm/cmpxchg.h line 23
Quoted 3 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +3
-0+case 4 : \ + asmvolatile ( \ + " amoswap.w %0, %2, %1\n" \
I don't think a leading tab (or leading whitespace in general) is needed in single-line-output asm()s. The trailing \n also isn't needed if I'm not mistaken.
xen/arch/riscv/include/asm/cmpxchg.h line 36
Quoted 13 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +13
-0+ : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory" ); \ +break ; \ +case 8 : \ + asmvolatile ( \ +" amoswap.d %0, %2, %1\n" \ + :"=r" (ret__),"+A" (*ptr__) \ + :"r" (new__) \ + :"memory" ); \ +break ; \ +default : \ +ASSERT_UNREACHABLE (); \
If at all possible this wants to trigger a build failure, not a runtime one.
xen/arch/riscv/include/asm/cmpxchg.h line 44
Quoted 8 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +8
-0+ } \ + ret__; \ +}) + +#define xchg_relaxed (ptr, x) \ +({ \ + __typeof__(*(ptr)) x_ = (x); \ + (__typeof__(*(ptr))) __xchg_relaxed((ptr), x_, sizeof(*(ptr))); \
Nit: Stray blank after cast. For readability I'd also suggest to drop parentheses in cases like the first argument passed to __xchg_relaxed() here.
xen/arch/riscv/include/asm/cmpxchg.h line 45
Quoted 1 line
xen/arch/riscv/include/asm/cmpxchg.h new file +1
-0+})
For both: What does "relaxed" describe? I'm asking because it's not really clear whether the memory clobbers are actually needed.
Quoted 18 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +18
-0+#define __xchg_acquire (ptr, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(new) new__ = (new); \ + __typeof__(*(ptr)) ret__; \ + switch (size) \ + { \ + case 4: \ + asm volatile( \ + " amoswap.w %0, %2, %1\n" \ + RISCV_ACQUIRE_BARRIER \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory" ); \ + break; \ + case 8: \ + asm volatile( \ + " amoswap.d %0, %2, %1\n" \
xen/arch/riscv/include/asm/cmpxchg.h line 74
Quoted 10 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +10
-0+ RISCV_ACQUIRE_BARRIER \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ +: " memory" ); \ +break; \ +default: \ +ASSERT_UNREACHABLE(); \ +} \ +ret__; \ +})
If I'm not mistaken this differs from __xchg_relaxed() only in the use of RISCV_ACQUIRE_BARRIER, and ...
Quoted 24 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +24
-0+#define xchg_acquire (ptr, x) \ +({ \ + __typeof__(*(ptr)) x_ = (x); \ + (__typeof__(*(ptr))) __xchg_acquire((ptr), x_, sizeof(*(ptr))); \ +}) + +#define __xchg_release (ptr, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(new) new__ = (new); \ + __typeof__(*(ptr)) ret__; \ + switch (size) \ + { \ + case 4: \ + asm volatile ( \ + RISCV_RELEASE_BARRIER \ + " amoswap.w %0, %2, %1\n" \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory"); \ + break; \ + case 8: \ + asm volatile ( \ + RISCV_RELEASE_BARRIER \
xen/arch/riscv/include/asm/cmpxchg.h line 109
Quoted 10 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +10
-0+ " amoswap.d %0, %2, %1\n" \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory"); \ +break ; \ +default : \ +ASSERT_UNREACHABLE (); \ + } \ + ret__; \ +})
this only in the use of RISCV_RELEASE_BARRIER. If so they likely want folding, to limit redundancy and make eventual updating easier. (Same for the cmpxchg helper further down, as it seems.)
Quoted 27 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +27
-0+#define xchg_release (ptr, x) \ +({ \ + __typeof__(*(ptr)) x_ = (x); \ + (__typeof__(*(ptr))) __xchg_release((ptr), x_, sizeof(*(ptr))); \ +}) + +static always_inline uint32_t __xchg_case_4(volatile uint32_t *ptr, +uint32_t new) +{ + __typeof__(*(ptr)) ret; + + asmvolatile ( +" amoswap.w.aqrl %0, %2, %1\n" + :"=r" (ret),"+A" (*ptr) + :"r" (new) + :"memory" ); + +return ret; +} + +static always_inline uint64_t __xchg_case_8(volatile uint64_t *ptr, +uint64_t new) +{ + __typeof__(*(ptr)) ret; + + asmvolatile ( \ + " amoswap.d.aqrl %0, %2, %1\n" \
xen/arch/riscv/include/asm/cmpxchg.h line 147
Quoted 10 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +10
-0+ : "=r" (ret), "+A" (*ptr) \ + : "r" (new) \ + : "memory" ); \ + +return ret; +} + +static always_inline unsigned short __cmpxchg_case_2 (volatile uint32_t *ptr, +uint32_t old, +uint32_t new);
Don't you consistently mean uint16_t here (incl the return type) and ...
xen/arch/riscv/include/asm/cmpxchg.h line 151
Quoted 3 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +3
-0+static always_inline unsigned short __cmpxchg_case_1 (volatile uint32_t *ptr, +uint32_t old, +uint32_t new);
... uint8_t here?
xen/arch/riscv/include/asm/cmpxchg.h line 159
Quoted 7 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +7
-0+static inline unsigned long __xchg (volatile void *ptr,unsigned long x,int size) +{ +switch (size) { +case 1 : +return __cmpxchg_case_1 (ptr, (uint32_t )-1 , x); +case 2 : +return __cmpxchg_case_2 (ptr, (uint32_t )-1 , x);
How are these going to work? You'll compare against ~0, and if the value in memory isn't ~0, memory won't be updated; you will only (correctly) return the value found in memory.
Or wait - looking at __cmpxchg_case_{1,2}() far further down, you ignore "old" there. Which apparently means they'll work for the use here, but not for the use in __cmpxchg().
Quoted 20 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +20
-0+case 4 : +return __xchg_case_4 (ptr, x); +case 8 : +return __xchg_case_8 (ptr, x); +default : +ASSERT_UNREACHABLE (); + } + +return -1 ; +} + +#define xchg (ptr,x) \ +({ \ + __typeof__(*(ptr)) ret__; \ + ret__ = (__typeof__(*(ptr))) \ + __xchg((ptr), (unsigned long)(x), sizeof(*(ptr))); \ + ret__; \ +}) + +#define xchg32 (ptr, x) \
xen/arch/riscv/include/asm/cmpxchg.h line 189
Quoted 10 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +10
-0+({ \ +BUILD_BUG_ON (sizeof (*(ptr)) !=4 ); \ +xchg ((ptr), (x)); \ +}) + +#define xchg64 (ptr, x) \ +({ \ + BUILD_BUG_ON(sizeof(*(ptr)) != 8); \ + xchg((ptr), (x)); \ +})
What are these two (and their cmpxchg counterparts) needed for?
xen/arch/riscv/include/asm/cmpxchg.h line 199
Quoted 9 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +9
-0+/* +* Atomic compare and exchange. Compare OLD with MEM, if identical, +* store NEW in MEM. Return the initial value in MEM. Success is +* indicated by comparing RETURN with OLD. +*/ +#define __cmpxchg_relaxed (ptr, old, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(*(ptr)) __old = (old); \
Leftover leading underscores?
xen/arch/riscv/include/asm/cmpxchg.h line 194
Quoted 1 line
xen/arch/riscv/include/asm/cmpxchg.h new file +1
-0+ __typeof__(*(ptr)) new__ = (new); \
Related to my earlier comment on types needing to be compatible - see how here you're using "ptr" throughout.
xen/arch/riscv/include/asm/cmpxchg.h line 196
Quoted 2 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +2
-0+ __typeof__(*(ptr)) ret__; \ + registerunsigned int __rc; \
More leftover leading underscores?
xen/arch/riscv/include/asm/cmpxchg.h line 409
Quoted 11 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +11
-0+static always_inline unsigned short __cmpxchg_case_2 (volatile uint32_t *ptr, +uint32_t old, +uint32_t new) +{ + (void ) old; + +if (((unsigned long )ptr &3 ) ==3 ) + { +#ifdef CONFIG_64BIT +return __emulate_cmpxchg_case1_2 ((uint64_t *)ptr, new, + readq, __cmpxchg_case_8,0xffffU );
What if ((unsigned long)ptr & 7) == 7 (which is a sub-case of what the if() above checks for? Isn't it more reasonable to require aligned 16-bit quantities here? Or if mis-aligned addresses are okay, you could as well emulate using __cmpxchg_case_4().
Also you shouldn't be casting away volatile (here and below). Avoiding the casts (by suitable using volatile void * parameter types) would likely be best.
Jan
Re: [PATCH v3 13/34] xen/riscv: introduce cmpxchg.h
Quoted 19 lines · Jan Beulich
Quoted 18 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/cmpxchg.h new file +15
-0@@ -0,0 +1,496 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* Copyright (C) 2014 Regents of the University of California */ + +#ifndef _ASM_RISCV_CMPXCHG_H +#define _ASM_RISCV_CMPXCHG_H + +#include <xen/compiler.h> +#include <xen/lib.h> + +#include <asm/fence.h> +#include <asm/io.h> +#include <asm/system.h> + +#define __xchg_relaxed (ptr, new, size) \ +({ \
Quoted 8 lines
xen/arch/riscv/include/asm/cmpxchg.h line 18
Quoted 3 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +3
-0+ __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(new) new__ = (new); \ + __typeof__(*(ptr)) ret__; \I expect the types of new and *ptr want to actually match. Which you then want to enforce, so that issues at use sites would either be reported by the compiler, or be permitted by a type conversion of new.
I am OK to make the same type for new and ret__, but it looks like __xchg_relaxed() is used only inside xchg_relaxed() where 'new' is declared with the same type as *ptr.
Quoted 6 lines
xen/arch/riscv/include/asm/cmpxchg.h line 20
Quoted 3 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +2
-0+ switch (size) \ + { \Nit: Hard tab left here. (Also again you want to either stick to Linux style or fully switch to Xen style.)
Thanks. I'll update that.
Quoted 8 lines
xen/arch/riscv/include/asm/cmpxchg.h line 23
Quoted 4 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +3
-0+ case 4: \ + asm volatile( \ + " amoswap.w %0, %2, %1\n" \I don't think a leading tab (or leading whitespace in general) is needed in single-line-output asm()s. The trailing \n also isn't needed if I'm not mistaken.
I just wanted to align it with "=r", but for sure a leading tab or whitespace can be dropped.
Quoted 15 lines
Quoted 4 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +3
-0+ : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ +: " memory" ); \ xen/arch/riscv/include/asm/cmpxchg.h line 36
Quoted 10 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +10
-0+ break; \ + case 8: \ + asm volatile( \ + " amoswap.d %0, %2, %1\n" \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory" ); \ + break; \ + default: \ + ASSERT_UNREACHABLE(); \
Quoted 3 lines
If at all possible this wants to trigger a build failure, not a runtime
one.
I'll update that with BUILD_BUG_ON(size > 8);
Quoted 14 lines
Quoted 10 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +8
-0+ } \ + ret__; \ +}) + +#define xchg_relaxed (ptr, x) \ +({ \ + __typeof__(*(ptr)) x_ = (x); \ + (__typeof__(*(ptr))) __xchg_relaxed((ptr), x_,sizeof(*(ptr))); \
Nit: Stray blank after cast. For readability I'd also suggest to drop parentheses in cases like the first argument passed to
__xchg_relaxed()here.
Thanks. I'll take that into account.
Quoted 70 lines
Quoted 2 lines
+})
For both: What does "relaxed" describe? I'm asking because it's not really clear whether the memory clobbers are actually needed.
Quoted 18 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +18
-0+#define __xchg_acquire (ptr, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(new) new__ = (new); \ + __typeof__(*(ptr)) ret__; \ + switch (size) \ + { \ + case 4: \ + asm volatile( \ + " amoswap.w %0, %2, %1\n" \ + RISCV_ACQUIRE_BARRIER \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory" ); \ + break; \ + case 8: \ + asm volatile( \ + " amoswap.d %0, %2, %1\n" \xen/arch/riscv/include/asm/cmpxchg.h line 74
Quoted 10 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +10
-0+ RISCV_ACQUIRE_BARRIER \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ +: " memory" ); \ +break; \ +default: \ +ASSERT_UNREACHABLE(); \ +} \ +ret__; \ +})If I'm not mistaken this differs from
__xchg_relaxed()only in the use
ofRISCV_ACQUIRE_BARRIER, and ...Quoted 31 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +4
-0+#define xchg_acquire (ptr, x) \ +({ \ + __typeof__(*(ptr)) x_ = (x); \ + (__typeof__(*(ptr))) __xchg_acquire((ptr), x_,sizeof(*(ptr))); \
xen/arch/riscv/include/asm/cmpxchg.h new file +26
-0+}) + +#define __xchg_release (ptr, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(new) new__ = (new); \ + __typeof__(*(ptr)) ret__; \ + switch (size) \ + { \ + case 4: \ + asm volatile ( \ + RISCV_RELEASE_BARRIER \ + " amoswap.w %0, %2, %1\n" \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory"); \ + break; \ + case 8: \ + asm volatile ( \ + RISCV_RELEASE_BARRIER \ + " amoswap.d %0, %2, %1\n" \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory"); \ + break; \ + default: \
Quoted 8 lines
Quoted 4 lines
+
ASSERT_UNREACHABLE(); \
+ } \
+ret__; \
+})this only in the use of
RISCV_RELEASE_BARRIER. If so they likely want folding, to limit redundancy and make eventual updating easier. (Same for the cmpxchg helper further down, as it seems.)
Yes, you are right. The difference is only in RISCV_RELEASE_BARRIER and it is an absence of RISCV_RELEASE_BARRIER is a reason why we have "relaxed" versions.
I am not sure that I understand what you mean by folding here. Do you mean that there is no any sense to have to separate macros and it is needed only one with RISCV_RELEASE_BARRIER?
Quoted 47 lines
Quoted 39 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +4
-0+#define xchg_release (ptr, x) \ +({ \ + __typeof__(*(ptr)) x_ = (x); \ + (__typeof__(*(ptr))) __xchg_release((ptr), x_,sizeof(*(ptr))); \
xen/arch/riscv/include/asm/cmpxchg.h new file +3
-0+}) + +static always_inline uint32_t __xchg_case_4(volatile uint32_t*ptr,
+uint32_tnew)xen/arch/riscv/include/asm/cmpxchg.h new file +13
-0+{ + __typeof__(*(ptr)) ret; + + asm volatile ( + " amoswap.w.aqrl %0, %2, %1\n" + : "=r" (ret), "+A" (*ptr) + : "r" (new) + : "memory" ); + + return ret; +} + +static always_inline uint64_t __xchg_case_8(volatile uint64_t*ptr,
+uint64_tnew)xen/arch/riscv/include/asm/cmpxchg.h new file +13
-0+{ + __typeof__(*(ptr)) ret; + + asm volatile( \ + " amoswap.d.aqrl %0, %2, %1\n" \ + : "=r" (ret), "+A" (*ptr) \ + : "r" (new) \ + : "memory" ); \ + + return ret; +} + +static always_inline unsigned short __cmpxchg_case_2(volatileQuoted 4 lines
uint32_t*ptr,
+uint32_told, +uint32_tnew);Don't you consistently mean
uint16_there (incl the return type) and
...
Quoted 7 lines
Quoted 5 lines
+static
always_inlineunsigned short __cmpxchg_case_1(volatileuint32_t*ptr,
+uint32_told, +uint32_tnew);...
uint8_there?
The idea was that we emulate __cmpxchg_case_1 and __cmpxchg_case_2 using 4 bytes cmpxchg and __cmpxchg_case_4 expects uint32_t.
Quoted 16 lines
Quoted 9 lines
+static inline unsigned long
__xchg(volatile void *ptr, unsigned long x, int size)
+{
+ switch (size) {
+ case 1:
+ return__cmpxchg_case_1(ptr, (uint32_t)-1, x); + case 2:
+ return__cmpxchg_case_2(ptr, (uint32_t)-1, x);How are these going to work? You'll compare against ~0, and if the value
in memory isn't ~0, memory won't be updated; you will only (correctly)
return the value found in memory.
Quoted 5 lines
Or wait - looking at __cmpxchg_case_{1,2}() far further down, you ignore
"old" there. Which apparently means they'll work for the use here, but
not for the use in__cmpxchg().
Yes, the trick is that old is ignored and is read in __emulate_cmpxchg_case1_2() before __cmpxchg_case_4 is called:
do {
read_val = read_func(aligned_ptr);
swapped_new = read_val & ~mask;
swapped_new |= masked_new;
ret = cmpxchg_func(aligned_ptr, read_val, swapped_new);
} while ( ret != read_val ); read_val it is 'old'.
But now I am not 100% sure that it is correct for __cmpxchg...
Quoted 25 lines
Quoted 25 lines
+ case 4:
+ return__xchg_case_4(ptr, x);
+ case 8:
+ return__xchg_case_8(ptr, x);
+ default:
+ASSERT_UNREACHABLE();
+ }xen/arch/riscv/include/asm/cmpxchg.h new file +17
-0+ + return -1; +} + +#define xchg (ptr,x) \ +({ \ + __typeof__(*(ptr)) ret__; \ + ret__ = (__typeof__(*(ptr))) \ + __xchg((ptr), (unsigned long)(x), sizeof(*(ptr))); \ + ret__; \ +}) + +#define xchg32 (ptr, x) \ +({ \ + BUILD_BUG_ON(sizeof(*(ptr)) != 4); \ + xchg((ptr), (x)); \ +})
Quoted 8 lines
xen/arch/riscv/include/asm/cmpxchg.h line 189
Quoted 6 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +6
-0+ +#define xchg64 (ptr, x) \ +({ \ + BUILD_BUG_ON(sizeof(*(ptr)) != 8); \ + xchg((ptr), (x)); \ +})What are these two (and their cmpxchg counterparts) needed for?
It was copied from Linux, but it looks like they can be really dropped, I can't find where it is used, so I'll drop them.
Quoted 16 lines
xen/arch/riscv/include/asm/cmpxchg.h line 199
Quoted 11 lines
+/*
+ * Atomic compare and exchange. Compare OLD with MEM, if identical,
+ * store NEW in MEM. Return the initial value in MEM. Success is
+ * indicated by comparing RETURN with OLD.
+ */xen/arch/riscv/include/asm/cmpxchg.h new file +4
-0+#define __cmpxchg_relaxed (ptr, old, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(*(ptr)) __old = (old); \Leftover leading underscores?
Quoted 1 line
+ __typeof__(*(ptr))
new__= (new); \
Quoted 7 lines
Related to my earlier comment on types needing to be compatible - see how here you're using "ptr" throughout.
Quoted 2 lines
+ __typeof__(*(ptr))
ret__; \
+ register unsigned int__rc; \More leftover leading underscores?
Missed to drop underscores. Thanks. I'll drop them in next version.
Quoted 13 lines
Quoted 13 lines
+static
always_inlineunsigned short __cmpxchg_case_2(volatileuint32_t*ptr,
+uint32_told, +uint32_tnew)xen/arch/riscv/include/asm/cmpxchg.h new file +8
-0+{ + (void) old; + + if (((unsigned long)ptr & 3) == 3) + { +#ifdef CONFIG_64BIT + return __emulate_cmpxchg_case1_2((uint64_t *)ptr, new, + readq, __cmpxchg_case_8,
Quoted 8 lines
Quoted 1 line
0xffffU);What if ((unsigned long)ptr & 7) == 7 (which is a sub-case of what the
if()above checks for? Isn't it more reasonable to require aligned 16-bit quantities here? Or if mis-aligned addresses are okay, you could
as well emulate using__cmpxchg_case_4().
Yes, it will be more reasonable. I'll use IS_ALIGNED instead.
Quoted 5 lines
Also you shouldn't be casting away volatile (here and below). Avoiding
the casts (by suitable using volatile void * parameter types) would likely be best.
Thanks. I'll update the function prototype.
~ Oleksii
Re: [PATCH v3 13/34] xen/riscv: introduce cmpxchg.h
Quoted 16 lines · Oleksii
Quoted 15 lines · Jan Beulich
Quoted 13 lines · Oleksii Kurochko
+ : "=r" (
ret__), "+A" (*ptr__) \
+ : "r" (new__) \
+ : "memory" ); \
+ break; \
+ case 8: \
+ asm volatile( \
+ " amoswap.d %0, %2, %1\n" \
+ : "=r" (ret__), "+A" (*ptr__) \
+ : "r" (new__) \
+ : "memory" ); \
+ break; \
+ default: \
+ASSERT_UNREACHABLE(); \
Quoted 4 lines
Quoted 3 lines
If at all possible this wants to trigger a build failure, not a runtime
one.I'll update that with
BUILD_BUG_ON(size > 8);
What about size accidentally being e.g. 5? I'm also not sure you'll be able to use BUILD_BUG_ON() here: That'll depend on what use sites there are. And if all present ones are okay in this regard, you'd still set out a trap for someone else to fall into later. We have a common approach for this, which currently is under re-work. See
https://lists.xen.org/archives/html/xen-devel/2024-01/msg01115.html.
Quoted 93 lines
Quoted 5 lines
Quoted 5 lines
+ } \
+ret__; \xen/arch/riscv/include/asm/cmpxchg.h new file +3
-0+}) + +#define xchg_relaxed (ptr, x) \Quoted 8 lines
Quoted 4 lines
+({ \
+ __typeof__(*(ptr)) x_ = (x); \
+ (__typeof__(*(ptr)))__xchg_relaxed((ptr), x_, sizeof(*(ptr))); \Nit: Stray blank after cast. For readability I'd also suggest to drop parentheses in cases like the first argument passed to
__xchg_relaxed()here.Thanks. I'll take that into account.
Quoted 70 lines
Quoted 2 lines
+})
For both: What does "relaxed" describe? I'm asking because it's not really clear whether the memory clobbers are actually needed.
Quoted 18 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +18
-0+#define __xchg_acquire (ptr, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(new) new__ = (new); \ + __typeof__(*(ptr)) ret__; \ + switch (size) \ + { \ + case 4: \ + asm volatile( \ + " amoswap.w %0, %2, %1\n" \ + RISCV_ACQUIRE_BARRIER \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory" ); \ + break; \ + case 8: \ + asm volatile( \ + " amoswap.d %0, %2, %1\n" \xen/arch/riscv/include/asm/cmpxchg.h line 74
Quoted 10 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +10
-0+ RISCV_ACQUIRE_BARRIER \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ +: " memory" ); \ +break; \ +default: \ +ASSERT_UNREACHABLE(); \ +} \ +ret__; \ +})If I'm not mistaken this differs from
__xchg_relaxed()only in the use
ofRISCV_ACQUIRE_BARRIER, and ...Quoted 31 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +4
-0+#define xchg_acquire (ptr, x) \ +({ \ + __typeof__(*(ptr)) x_ = (x); \ + (__typeof__(*(ptr))) __xchg_acquire((ptr), x_,sizeof(*(ptr))); \
xen/arch/riscv/include/asm/cmpxchg.h new file +26
-0+}) + +#define __xchg_release (ptr, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(new) new__ = (new); \ + __typeof__(*(ptr)) ret__; \ + switch (size) \ + { \ + case 4: \ + asm volatile ( \ + RISCV_RELEASE_BARRIER \ + " amoswap.w %0, %2, %1\n" \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory"); \ + break; \ + case 8: \ + asm volatile ( \ + RISCV_RELEASE_BARRIER \ + " amoswap.d %0, %2, %1\n" \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory"); \ + break; \ + default: \Quoted 8 lines
Quoted 4 lines
+
ASSERT_UNREACHABLE(); \
+ } \
+ret__; \
+})this only in the use of
RISCV_RELEASE_BARRIER. If so they likely want folding, to limit redundancy and make eventual updating easier. (Same for the cmpxchg helper further down, as it seems.)
Quoted 7 lines
Yes, you are right. The difference is only in
RISCV_RELEASE_BARRIERand it is an absence ofRISCV_RELEASE_BARRIERis a reason why we have "relaxed" versions.I am not sure that I understand what you mean by folding here. Do you mean that there is no any sense to have to separate macros and it is needed only one with
RISCV_RELEASE_BARRIER?
No. You should parameterize the folded common macro for the derived macros to simply pass in the barriers needed, with empty macro arguments indicating "this barrier not needed".
Quoted 52 lines
Quoted 52 lines
Quoted 38 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +4
-0+#define xchg_release (ptr, x) \ +({ \ + __typeof__(*(ptr)) x_ = (x); \ + (__typeof__(*(ptr))) __xchg_release((ptr), x_,sizeof(*(ptr))); \
xen/arch/riscv/include/asm/cmpxchg.h new file +3
-0+}) + +static always_inline uint32_t __xchg_case_4(volatile uint32_t*ptr,
+uint32_tnew)xen/arch/riscv/include/asm/cmpxchg.h new file +13
-0+{ + __typeof__(*(ptr)) ret; + + asm volatile ( + " amoswap.w.aqrl %0, %2, %1\n" + : "=r" (ret), "+A" (*ptr) + : "r" (new) + : "memory" ); + + return ret; +} + +static always_inline uint64_t __xchg_case_8(volatile uint64_t*ptr,
+uint64_tnew)xen/arch/riscv/include/asm/cmpxchg.h new file +13
-0+{ + __typeof__(*(ptr)) ret; + + asm volatile( \ + " amoswap.d.aqrl %0, %2, %1\n" \ + : "=r" (ret), "+A" (*ptr) \ + : "r" (new) \ + : "memory" ); \ + + return ret; +} + +static always_inline unsigned short __cmpxchg_case_2(volatileQuoted 4 lines
uint32_t*ptr,
+uint32_told, +uint32_tnew);Don't you consistently mean
uint16_there (incl the return type) and
...Quoted 5 lines
+static
always_inlineunsigned short __cmpxchg_case_1(volatileuint32_t*ptr,
+uint32_told, +uint32_tnew);
Quoted 3 lines
Quoted 1 line
...
uint8_there?The idea was that we emulate
__cmpxchg_case_1and__cmpxchg_case_2using 4 bytes cmpxchg and__cmpxchg_case_4expectsuint32_t.
I consider this wrong. The functions would better be type-correct.
Quoted 28 lines
Quoted 15 lines
Quoted 8 lines
+static inline unsigned long
__xchg(volatile void *ptr, unsigned long x, int size)
+{
+ switch (size) {
+ case 1:
+ return__cmpxchg_case_1(ptr, (uint32_t)-1, x); + case 2:
+ return__cmpxchg_case_2(ptr, (uint32_t)-1, x);How are these going to work? You'll compare against ~0, and if the value
in memory isn't ~0, memory won't be updated; you will only (correctly)
return the value found in memory.Quoted 5 lines
Or wait - looking at __cmpxchg_case_{1,2}() far further down, you ignore
"old" there. Which apparently means they'll work for the use here, but
not for the use in__cmpxchg().Yes, the trick is that old is ignored and is read in
__emulate_cmpxchg_case1_2()before__cmpxchg_case_4is called:do { read_val = read_func(aligned_ptr); swapped_new = read_val & ~mask; swapped_new |= masked_new; ret = cmpxchg_func(aligned_ptr, read_val, swapped_new); } while ( ret != read_val );
Quoted 3 lines
read_valit is 'old'.But now I am not 100% sure that it is correct for
__cmpxchg...
It just can't be correct - you can't ignore "old" there. I think you want simple cmpxchg primitives, which xchg then uses in a loop (while cmpxchg uses them plainly).
Quoted 20 lines
Quoted 12 lines
Quoted 12 lines
+static
always_inlineunsigned short __cmpxchg_case_2(volatileuint32_t*ptr,
+uint32_told, +uint32_tnew)xen/arch/riscv/include/asm/cmpxchg.h new file +8
-0+{ + (void) old; + + if (((unsigned long)ptr & 3) == 3) + { +#ifdef CONFIG_64BIT + return __emulate_cmpxchg_case1_2((uint64_t *)ptr, new, + readq, __cmpxchg_case_8,Quoted 8 lines
Quoted 1 line
0xffffU);What if ((unsigned long)ptr & 7) == 7 (which is a sub-case of what the
if()above checks for? Isn't it more reasonable to require aligned 16-bit quantities here? Or if mis-aligned addresses are okay, you could
as well emulate using__cmpxchg_case_4().
Quoted 1 line
Yes, it will be more reasonable. I'll use
IS_ALIGNEDinstead.
Not sure I get your use of "instead" here correctly. There's more to change here than just the if() condition.
Jan
Re: [PATCH v3 13/34] xen/riscv: introduce cmpxchg.h
Quoted 22 lines · Jan Beulich
Quoted 16 lines · Oleksii
Quoted 15 lines · Jan Beulich
Quoted 13 lines · Oleksii Kurochko
+ : "=r" (
ret__), "+A" (*ptr__) \
+ : "r" (new__) \
+ : "memory" ); \
+ break; \
+ case 8: \
+ asm volatile( \
+ " amoswap.d %0, %2, %1\n" \
+ : "=r" (ret__), "+A" (*ptr__) \
+ : "r" (new__) \
+ : "memory" ); \
+ break; \
+ default: \
+ASSERT_UNREACHABLE(); \Quoted 4 lines
Quoted 3 lines
If at all possible this wants to trigger a build failure, not a runtime
one.I'll update that with
BUILD_BUG_ON(size > 8);
Quoted 8 lines
What about size accidentally being e.g. 5? I'm also not sure you'll be
able to useBUILD_BUG_ON()here: That'll depend on what use sites there
are. And if all present ones are okay in this regard, you'd still set out a trap for someone else to fall into later. We have a common approach for this, which currently is under re-work. See
https://lists.xen.org/archives/html/xen-devel/2024-01/msg01115.html.
Thanks. I'll use that.
Quoted 109 lines
Quoted 103 lines
Quoted 14 lines
Quoted 10 lines
+ } \
+ret__; \xen/arch/riscv/include/asm/cmpxchg.h new file +6
-0+}) + +#define xchg_relaxed (ptr, x) \ +({ \ + __typeof__(*(ptr)) x_ = (x); \ + (__typeof__(*(ptr))) __xchg_relaxed((ptr), x_,sizeof(*(ptr))); \
Nit: Stray blank after cast. For readability I'd also suggest to drop parentheses in cases like the first argument passed to
__xchg_relaxed()here.Thanks. I'll take that into account.
Quoted 74 lines
Quoted 2 lines
+})
For both: What does "relaxed" describe? I'm asking because it's not
really clear whether the memory clobbers are actually needed.Quoted 18 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +18
-0+#define __xchg_acquire (ptr, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(new) new__ = (new); \ + __typeof__(*(ptr)) ret__; \ + switch (size) \ + { \ + case 4: \ + asm volatile( \ + " amoswap.w %0, %2, %1\n" \ + RISCV_ACQUIRE_BARRIER \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory" ); \ + break; \ + case 8: \ + asm volatile( \ + " amoswap.d %0, %2, %1\n" \xen/arch/riscv/include/asm/cmpxchg.h line 74
Quoted 10 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +10
-0+ RISCV_ACQUIRE_BARRIER \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ +: " memory" ); \ +break; \ +default: \ +ASSERT_UNREACHABLE(); \ +} \ +ret__; \ +})If I'm not mistaken this differs from
__xchg_relaxed()only in the
use
ofRISCV_ACQUIRE_BARRIER, and ...Quoted 33 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +4
-0+#define xchg_acquire (ptr, x) \ +({ \ + __typeof__(*(ptr)) x_ = (x); \ + (__typeof__(*(ptr))) __xchg_acquire((ptr), x_,sizeof(*(ptr))); \
xen/arch/riscv/include/asm/cmpxchg.h new file +28
-0+}) + +#define __xchg_release (ptr, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(new) new__ = (new); \ + __typeof__(*(ptr)) ret__; \ + switch (size) \ + { \ + case 4: \ + asm volatile ( \ + RISCV_RELEASE_BARRIER \ + " amoswap.w %0, %2, %1\n" \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory"); \ + break; \ + case 8: \ + asm volatile ( \ + RISCV_RELEASE_BARRIER \ + " amoswap.d %0, %2, %1\n" \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory"); \ + break; \ + default: \ + ASSERT_UNREACHABLE(); \ + } \Quoted 8 lines
Quoted 2 lines
+
ret__; \
+})this only in the use of
RISCV_RELEASE_BARRIER. If so they likely want
folding, to limit redundancy and make eventual updating easier. (Same
for the cmpxchg helper further down, as it seems.)Yes, you are right. The difference is only in
RISCV_RELEASE_BARRIERand
it is an absence ofRISCV_RELEASE_BARRIERis a reason why we have "relaxed" versions.Quoted 5 lines
I am not sure that I understand what you mean by folding here. Do you
mean that there is no any sense to have to separate macros and it is
needed only one withRISCV_RELEASE_BARRIER?
Quoted 3 lines
No. You should parameterize the folded common macro for the derived macros to simply pass in the barriers needed, with empty macro arguments indicating "this barrier not needed".
Now it makes sense to me. Thank you for explanation.
Quoted 101 lines
Quoted 56 lines
Quoted 56 lines
Quoted 39 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +4
-0+#define xchg_release (ptr, x) \ +({ \ + __typeof__(*(ptr)) x_ = (x); \ + (__typeof__(*(ptr))) __xchg_release((ptr), x_,sizeof(*(ptr))); \
xen/arch/riscv/include/asm/cmpxchg.h new file +3
-0+}) + +static always_inline uint32_t __xchg_case_4(volatile uint32_t*ptr,
+uint32_tnew)xen/arch/riscv/include/asm/cmpxchg.h new file +13
-0+{ + __typeof__(*(ptr)) ret; + + asm volatile ( + " amoswap.w.aqrl %0, %2, %1\n" + : "=r" (ret), "+A" (*ptr) + : "r" (new) + : "memory" ); + + return ret; +} + +static always_inline uint64_t __xchg_case_8(volatile uint64_t*ptr,
+uint64_tnew)xen/arch/riscv/include/asm/cmpxchg.h new file +13
-0+{ + __typeof__(*(ptr)) ret; + + asm volatile( \ + " amoswap.d.aqrl %0, %2, %1\n" \ + : "=r" (ret), "+A" (*ptr) \ + : "r" (new) \ + : "memory" ); \ + + return ret; +} + +static always_inline unsigned short __cmpxchg_case_2(volatileQuoted 5 lines
uint32_t*ptr,
+uint32_told,
+uint32_tnew);Don't you consistently mean
uint16_there (incl the return type) and
...Quoted 6 lines
+static
always_inlineunsigned short __cmpxchg_case_1(volatileuint32_t*ptr,
+uint32_told,
+uint32_tnew);Quoted 3 lines
Quoted 1 line
...
uint8_there?The idea was that we emulate
__cmpxchg_case_1and__cmpxchg_case_2using 4 bytes cmpxchg and__cmpxchg_case_4expectsuint32_t.I consider this wrong. The functions would better be type-correct.
Quoted 39 lines
Quoted 17 lines
Quoted 9 lines
+static inline unsigned long __xchg(volatile void *ptr, unsigned
long x, int size)
+{
+ switch (size) {
+ case 1:
+ return__cmpxchg_case_1(ptr, (uint32_t)-1, x); + case 2:
+ return__cmpxchg_case_2(ptr, (uint32_t)-1, x);How are these going to work? You'll compare against ~0, and if the
value
in memory isn't ~0, memory won't be updated; you will only (correctly)
return the value found in memory.Quoted 6 lines
Or wait - looking at __cmpxchg_case_{1,2}() far further down, you ignore
"old" there. Which apparently means they'll work for the use here,
but
not for the use in__cmpxchg().Yes, the trick is that old is ignored and is read in
__emulate_cmpxchg_case1_2()before__cmpxchg_case_4is called:
do
{
read_val=read_func(aligned_ptr);
swapped_new=read_val&
~mask;
swapped_new|=masked_new;
ret =cmpxchg_func(aligned_ptr, read_val, swapped_new);
} while ( ret !=read_val
);read_valit is 'old'.
Quoted 5 lines
Quoted 1 line
But now I am not 100% sure that it is correct for
__cmpxchg...It just can't be correct - you can't ignore "old" there. I think you want simple cmpxchg primitives, which xchg then uses in a loop (while cmpxchg uses them plainly).
But xchg doesn't require 'old' value, so it should be ignored in some way by cmpxchg.
Quoted 26 lines
Quoted 26 lines
Quoted 26 lines
Quoted 15 lines
+static
always_inlineunsigned short __cmpxchg_case_2(volatileuint32_t*ptr,
+uint32_told,
+uint32_tnew)xen/arch/riscv/include/asm/cmpxchg.h new file +8
-0+{ + (void) old; + + if (((unsigned long)ptr & 3) == 3) + { +#ifdef CONFIG_64BIT + return __emulate_cmpxchg_case1_2((uint64_t *)ptr, new, + readq,Quoted 2 lines
__cmpxchg_case_8,0xffffU);What if ((unsigned long)ptr & 7) == 7 (which is a sub-case of what
theif()above checks for? Isn't it more reasonable to require aligned
16-bit quantities here? Or if mis-aligned addresses are okay, you could
as well emulate using__cmpxchg_case_4().
Quoted 4 lines
Quoted 1 line
Yes, it will be more reasonable. I'll use
IS_ALIGNEDinstead.Not sure I get your use of "instead" here correctly. There's more to change here than just the
if()condition.
I meant something like:
if ( IS_ALIGNED(ptr, 16) )
__emulate_cmpxchg_case1_2(...);
else
assert_failed("ptr isn't aligned\n");I have to check if it is necessary to have an mis-aligned address for CAS intstuctions.
If mis-aligned address is okay then it looks like we can use always __cmpxchng_case_4 without checking if a ptr is ALIGNED or not. Or I started to loose something...
~ Oleksii
Re: [PATCH v3 13/34] xen/riscv: introduce cmpxchg.h
Quoted 43 lines · Oleksii
Quoted 42 lines · Jan Beulich
Quoted 41 lines · Oleksii
Quoted 18 lines · Jan Beulich
Quoted 9 lines · Oleksii Kurochko
+static inline unsigned long __xchg(volatile void *ptr, unsigned
long x, int size)
+{
+ switch (size) {
+ case 1:
+ return__cmpxchg_case_1(ptr, (uint32_t)-1, x); + case 2:
+ return__cmpxchg_case_2(ptr, (uint32_t)-1, x);How are these going to work? You'll compare against ~0, and if the
value
in memory isn't ~0, memory won't be updated; you will only (correctly)
return the value found in memory.Quoted 6 lines
Or wait - looking at __cmpxchg_case_{1,2}() far further down, you ignore
"old" there. Which apparently means they'll work for the use here,
but
not for the use in__cmpxchg().Yes, the trick is that old is ignored and is read in
__emulate_cmpxchg_case1_2()before__cmpxchg_case_4is called:
do
{
read_val=read_func(aligned_ptr);
swapped_new=read_val&
~mask;
swapped_new|=masked_new;
ret =cmpxchg_func(aligned_ptr, read_val, swapped_new);
} while ( ret !=read_val
);read_valit is 'old'.
Quoted 7 lines
Quoted 5 lines
Quoted 1 line
But now I am not 100% sure that it is correct for
__cmpxchg...It just can't be correct - you can't ignore "old" there. I think you want simple cmpxchg primitives, which xchg then uses in a loop (while cmpxchg uses them plainly).
But xchg doesn't require 'old' value, so it should be ignored in some way by cmpxchg.
Well, no. If you have only cmpxchg, I think your only choice is - as said - to read the old value and then loop over cmpxchg until that succeeds. Not really different from other operations which need emulating using cmpxchg.
Quoted 27 lines
Quoted 27 lines
Quoted 26 lines
Quoted 17 lines
Quoted 14 lines
+static
always_inlineunsigned short __cmpxchg_case_2(volatileuint32_t*ptr,
+uint32_told,
+uint32_tnew)xen/arch/riscv/include/asm/cmpxchg.h new file +8
-0+{ + (void) old; + + if (((unsigned long)ptr & 3) == 3) + { +#ifdef CONFIG_64BIT + return __emulate_cmpxchg_case1_2((uint64_t *)ptr, new, + readq,Quoted 2 lines
__cmpxchg_case_8,0xffffU);Quoted 8 lines
What if ((unsigned long)ptr & 7) == 7 (which is a sub-case of what
theif()above checks for? Isn't it more reasonable to require aligned
16-bit quantities here? Or if mis-aligned addresses are okay, you could
as well emulate using__cmpxchg_case_4().Yes, it will be more reasonable. I'll use
IS_ALIGNEDinstead.
Quoted 8 lines
Quoted 2 lines
Not sure I get your use of "instead" here correctly. There's more to change here than just the
if()condition.I meant something like:
if (
IS_ALIGNED(ptr, 16))__emulate_cmpxchg_case1_2(...); else assert_failed("ptr isn't aligned\n");
Except that you'd better not use assert_failed() directly anywhere, and the above is easier as
ASSERT(IS_ALIGNED(ptr, 16));
__emulate_cmpxchg_case1_2(...);anyway (leaving aside that I guess you mean 2, not 16).
Jan
Re: [PATCH v3 13/34] xen/riscv: introduce cmpxchg.h
Quoted 53 lines · Jan Beulich
Quoted 52 lines · Oleksii
Quoted 51 lines · Jan Beulich
Quoted 43 lines · Oleksii
Quoted 19 lines · Jan Beulich
Quoted 9 lines · Oleksii Kurochko
+static inline unsigned long __xchg(volatile void *ptr, unsigned
long x, int size)
+{
+ switch (size) {
+ case 1:
+ return__cmpxchg_case_1(ptr, (uint32_t)-1, x); + case 2:
+ return__cmpxchg_case_2(ptr, (uint32_t)-1, x);How are these going to work? You'll compare against ~0, and if
the
value
in memory isn't ~0, memory won't be updated; you will only (correctly)
return the value found in memory.Quoted 7 lines
Or wait - looking at __cmpxchg_case_{1,2}() far further down, you
ignore
"old" there. Which apparently means they'll work for the use here,
but
not for the use in__cmpxchg().Yes, the trick is that old is ignored and is read in
__emulate_cmpxchg_case1_2()before__cmpxchg_case_4is called:
do
{
read_val=read_func(aligned_ptr);
swapped_new=read_val&
~mask;
swapped_new|=masked_new;
ret =cmpxchg_func(aligned_ptr, read_val, swapped_new);
} while ( ret !=read_val
);read_valit is 'old'.Quoted 1 line
But now I am not 100% sure that it is correct for
__cmpxchg...It just can't be correct - you can't ignore "old" there. I think you
want simple cmpxchg primitives, which xchg then uses in a loop (while
cmpxchg uses them plainly).
Quoted 8 lines
Quoted 3 lines
But xchg doesn't require 'old' value, so it should be ignored in some
way by cmpxchg.Well, no. If you have only cmpxchg, I think your only choice is - as said - to read the old value and then loop over cmpxchg until that succeeds. Not really different from other operations which need emulating using cmpxchg.
Then it looks like the main error in __emulate_cmpxchg_case1_2 is that I read the value each time, so read_val = read_func(aligned_ptr); should be before the do {...} while(). Also, it would be better to rename it to old_val or just old.
Quoted 42 lines
Quoted 33 lines
Quoted 33 lines
Quoted 32 lines
Quoted 23 lines
Quoted 17 lines
+static
always_inlineunsigned short
__cmpxchg_case_2(volatileuint32_t*ptr,
+uint32_t
old,
+uint32_t
new)xen/arch/riscv/include/asm/cmpxchg.h new file +7
-0+{ + (void) old; + + if (((unsigned long)ptr & 3) == 3) + { +#ifdef CONFIG_64BIT + return __emulate_cmpxchg_case1_2((uint64_t *)ptr,Quoted 4 lines
new,
+ readq,__cmpxchg_case_8,0xffffU);What if ((unsigned long)ptr & 7) == 7 (which is a sub-case of
Quoted 8 lines
what
theif()above checks for? Isn't it more reasonable to require aligned
16-bit quantities here? Or if mis-aligned addresses are okay, you
could
as well emulate using__cmpxchg_case_4().Yes, it will be more reasonable. I'll use
IS_ALIGNEDinstead.Quoted 8 lines
Quoted 2 lines
Not sure I get your use of "instead" here correctly. There's more to change here than just the
if()condition.I meant something like:
if (
IS_ALIGNED(ptr, 16))
__emulate_cmpxchg_case1_2(...);
else
assert_failed("ptr isn't aligned\n");
Quoted 7 lines
Except that you'd better not use
assert_failed()directly anywhere, and the above is easier as
ASSERT(IS_ALIGNED(ptr, 16));
__emulate_cmpxchg_case1_2(...);anyway (leaving aside that I guess you mean 2, not 16).
Yeah, it should be 2. Thanks.
~ Oleksii
Re: [PATCH v3 13/34] xen/riscv: introduce cmpxchg.h
In reply to Jan BeulichQuoted 64 lines · Jan Beulich
Quoted 18 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +18
-0+#define __xchg_acquire (ptr, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(new) new__ = (new); \ + __typeof__(*(ptr)) ret__; \ + switch (size) \ + { \ + case 4: \ + asm volatile( \ + " amoswap.w %0, %2, %1\n" \ + RISCV_ACQUIRE_BARRIER \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory" ); \ + break; \ + case 8: \ + asm volatile( \ + " amoswap.d %0, %2, %1\n" \xen/arch/riscv/include/asm/cmpxchg.h line 74
Quoted 10 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +10
-0+ RISCV_ACQUIRE_BARRIER \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ +: " memory" ); \ +break; \ +default: \ +ASSERT_UNREACHABLE(); \ +} \ +ret__; \ +})If I'm not mistaken this differs from
__xchg_relaxed()only in the use
ofRISCV_ACQUIRE_BARRIER, and ...Quoted 31 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +4
-0+#define xchg_acquire (ptr, x) \ +({ \ + __typeof__(*(ptr)) x_ = (x); \ + (__typeof__(*(ptr))) __xchg_acquire((ptr), x_,sizeof(*(ptr))); \
xen/arch/riscv/include/asm/cmpxchg.h new file +26
-0+}) + +#define __xchg_release (ptr, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(new) new__ = (new); \ + __typeof__(*(ptr)) ret__; \ + switch (size) \ + { \ + case 4: \ + asm volatile ( \ + RISCV_RELEASE_BARRIER \ + " amoswap.w %0, %2, %1\n" \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory"); \ + break; \ + case 8: \ + asm volatile ( \ + RISCV_RELEASE_BARRIER \ + " amoswap.d %0, %2, %1\n" \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory"); \ + break; \ + default: \
Quoted 8 lines
Quoted 4 lines
+
ASSERT_UNREACHABLE(); \
+ } \
+ret__; \
+})this only in the use of
RISCV_RELEASE_BARRIER. If so they likely want folding, to limit redundancy and make eventual updating easier. (Same for the cmpxchg helper further down, as it seems.)
Also the difference is in where to place barrier before or after atomic instruction. I am not sure that we can easily folded this macros.
~ Oleksii
Re: [PATCH v3 13/34] xen/riscv: introduce cmpxchg.h
Quoted 73 lines · Oleksii
Quoted 64 lines · Jan Beulich
Quoted 18 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +18
-0+#define __xchg_acquire (ptr, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(new) new__ = (new); \ + __typeof__(*(ptr)) ret__; \ + switch (size) \ + { \ + case 4: \ + asm volatile( \ + " amoswap.w %0, %2, %1\n" \ + RISCV_ACQUIRE_BARRIER \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory" ); \ + break; \ + case 8: \ + asm volatile( \ + " amoswap.d %0, %2, %1\n" \xen/arch/riscv/include/asm/cmpxchg.h line 74
Quoted 10 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +10
-0+ RISCV_ACQUIRE_BARRIER \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ +: " memory" ); \ +break; \ +default: \ +ASSERT_UNREACHABLE(); \ +} \ +ret__; \ +})If I'm not mistaken this differs from
__xchg_relaxed()only in the use
ofRISCV_ACQUIRE_BARRIER, and ...Quoted 31 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +4
-0+#define xchg_acquire (ptr, x) \ +({ \ + __typeof__(*(ptr)) x_ = (x); \ + (__typeof__(*(ptr))) __xchg_acquire((ptr), x_,sizeof(*(ptr))); \
xen/arch/riscv/include/asm/cmpxchg.h new file +26
-0+}) + +#define __xchg_release (ptr, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(new) new__ = (new); \ + __typeof__(*(ptr)) ret__; \ + switch (size) \ + { \ + case 4: \ + asm volatile ( \ + RISCV_RELEASE_BARRIER \ + " amoswap.w %0, %2, %1\n" \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory"); \ + break; \ + case 8: \ + asm volatile ( \ + RISCV_RELEASE_BARRIER \ + " amoswap.d %0, %2, %1\n" \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory"); \ + break; \ + default: \Quoted 8 lines
Quoted 4 lines
+
ASSERT_UNREACHABLE(); \
+ } \
+ret__; \
+})this only in the use of
RISCV_RELEASE_BARRIER. If so they likely want folding, to limit redundancy and make eventual updating easier. (Same for the cmpxchg helper further down, as it seems.)
Quoted 2 lines
Also the difference is in where to place barrier before or after atomic instruction. I am not sure that we can easily folded this macros.
The folded macro would have two barrier parameters - on for acquire, one for release.
Jan
Re: [PATCH v3 13/34] xen/riscv: introduce cmpxchg.h
Quoted 77 lines · Jan Beulich
Quoted 76 lines · Oleksii
Quoted 75 lines · Jan Beulich
Quoted 18 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +18
-0+#define __xchg_acquire (ptr, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(new) new__ = (new); \ + __typeof__(*(ptr)) ret__; \ + switch (size) \ + { \ + case 4: \ + asm volatile( \ + " amoswap.w %0, %2, %1\n" \ + RISCV_ACQUIRE_BARRIER \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory" ); \ + break; \ + case 8: \ + asm volatile( \ + " amoswap.d %0, %2, %1\n" \xen/arch/riscv/include/asm/cmpxchg.h line 74
Quoted 10 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +10
-0+ RISCV_ACQUIRE_BARRIER \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ +: " memory" ); \ +break; \ +default: \ +ASSERT_UNREACHABLE(); \ +} \ +ret__; \ +})If I'm not mistaken this differs from
__xchg_relaxed()only in the
use
ofRISCV_ACQUIRE_BARRIER, and ...Quoted 25 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +4
-0+#define xchg_acquire (ptr, x) \ +({ \ + __typeof__(*(ptr)) x_ = (x); \ + (__typeof__(*(ptr))) __xchg_acquire((ptr), x_,sizeof(*(ptr))); \
xen/arch/riscv/include/asm/cmpxchg.h new file +20
-0+}) + +#define __xchg_release (ptr, new, size) \ +({ \ + __typeof__(ptr) ptr__ = (ptr); \ + __typeof__(new) new__ = (new); \ + __typeof__(*(ptr)) ret__; \ + switch (size) \ + { \ + case 4: \ + asm volatile ( \ + RISCV_RELEASE_BARRIER \ + " amoswap.w %0, %2, %1\n" \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory"); \ + break; \ + case 8: \ + asm volatile ( \ + RISCV_RELEASE_BARRIER \xen/arch/riscv/include/asm/cmpxchg.h line 109
Quoted 10 lines
xen/arch/riscv/include/asm/cmpxchg.h new file +10
-0+ " amoswap.d %0, %2, %1\n" \ + : "=r" (ret__), "+A" (*ptr__) \ + : "r" (new__) \ + : "memory"); \ + break; \ + default: \ + ASSERT_UNREACHABLE(); \ + } \ + ret__; \ +})this only in the use of
RISCV_RELEASE_BARRIER. If so they likely want
folding, to limit redundancy and make eventual updating easier. (Same
for the cmpxchg helper further down, as it seems.)
Quoted 7 lines
Quoted 3 lines
Also the difference is in where to place barrier before or after atomic
instruction. I am not sure that we can easily folded this macros.The folded macro would have two barrier parameters - on for acquire, one
for release.
Yes, in such case it will work.
Thanks.
~ Oleksii
PATCH v3 14/34 xen/riscv: introduce io.h
In reply to Oleksii KurochkoThe header taken form Linux 6.4.0-rc1 and is based on arch/riscv/include/asm/mmio.h.
Addionally, to the header was added definions of ioremap_*().
---
Changes in V3:
- re-sync with linux kernel
- update the commit message
---
Changes in V2:
- Nothing changed. Only rebase.
--- xen/arch/riscv/include/asm/io.h | 142 ++++++++++++++++++++++++++++++++ 1 file changed, 142 insertions(+) create mode 100644 xen/arch/riscv/include/asm/io.h
xen/arch/riscv/include/asm/io.h new file +142 -0
@@ -0,0 +1,142 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* {read,write}{b,w,l,q} based on arch/arm64/include/asm/io.h +* which was based on arch/arm/include/io.h +* +* Copyright (C) 1996-2000 Russell King +* Copyright (C) 2012 ARM Ltd. +* Copyright (C) 2014 Regents of the University of California +*/ + + +#ifndef _ASM_RISCV_IO_H +#define _ASM_RISCV_IO_H + +#include <asm/byteorder.h> + +/* +* The RISC-V ISA doesn't yet specify how to query or modify PMAs, so we can't +* change the properties of memory regions. This should be fixed by the +* upcoming platform spec. +*/ +#define ioremap_nocache (addr, size) ioremap((addr), (size)) +#define ioremap_wc (addr, size) ioremap((addr), (size)) +#define ioremap_wt (addr, size) ioremap((addr), (size)) + +/* Generic IO read/write. These perform native-endian accesses. */ +#define __raw_writeb __raw_writeb +static inline void __raw_writeb (u8 val,volatile void __iomem *addr) +{ + asmvolatile ("sb %0, 0(%1)" : :"r" (val),"r" (addr)); +} + +#define __raw_writew __raw_writew +static inline void __raw_writew (u16 val,volatile void __iomem *addr) +{ + asmvolatile ("sh %0, 0(%1)" : :"r" (val),"r" (addr)); +} + +#define __raw_writel __raw_writel +static inline void __raw_writel (u32 val,volatile void __iomem *addr) +{ + asmvolatile ("sw %0, 0(%1)" : :"r" (val),"r" (addr)); +} + +#ifdef CONFIG_64BIT +#define __raw_writeq __raw_writeq +static inline void __raw_writeq (u64 val,volatile void __iomem *addr) +{ + asmvolatile ("sd %0, 0(%1)" : :"r" (val),"r" (addr)); +} +#endif + +#define __raw_readb __raw_readb +static inline u8 __raw_readb (const volatile void __iomem *addr) +{ +u8 val; + + asmvolatile ("lb %0, 0(%1)" :"=r" (val) :"r" (addr)); +return val; +} + +#define __raw_readw __raw_readw +static inline u16 __raw_readw (const volatile void __iomem *addr) +{ +u16 val; + + asmvolatile ("lh %0, 0(%1)" :"=r" (val) :"r" (addr)); +return val; +} + +#define __raw_readl __raw_readl +static inline u32 __raw_readl (const volatile void __iomem *addr) +{ +u32 val; + + asmvolatile ("lw %0, 0(%1)" :"=r" (val) :"r" (addr)); +return val; +} + +#ifdef CONFIG_64BIT +#define __raw_readq __raw_readq +static inline u64 __raw_readq (const volatile void __iomem *addr) +{ +u64 val; + + asmvolatile ("ld %0, 0(%1)" :"=r" (val) :"r" (addr)); +return val; +} +#endif + +/* +* Unordered I/O memory access primitives. These are even more relaxed than +* the relaxed versions, as they don't even order accesses between successive +* operations to the I/O regions. +*/ +#define readb_cpu (c) ({ u8 __r = __raw_readb(c); __r; }) +#define readw_cpu (c) ({ u16 __r = le16_to_cpu((__force __le16)__raw_readw(c)); __r; }) +#define readl_cpu (c) ({ u32 __r = le32_to_cpu((__force __le32)__raw_readl(c)); __r; }) + +#define writeb_cpu (v,c) ((void)__raw_writeb((v),(c))) +#define writew_cpu (v,c) ((void)__raw_writew((__force u16)cpu_to_le16(v),(c))) +#define writel_cpu (v,c) ((void)__raw_writel((__force u32)cpu_to_le32(v),(c))) + +#ifdef CONFIG_64BIT +#define readq_cpu (c) ({ u64 __r = le64_to_cpu((__force __le64)__raw_readq(c)); __r; }) +#define writeq_cpu (v,c) ((void)__raw_writeq((__force u64)cpu_to_le64(v),(c))) +#endif + +/* +* I/O memory access primitives. Reads are ordered relative to any +* following Normal memory access. Writes are ordered relative to any prior +* Normal memory access. The memory barriers here are necessary as RISC-V +* doesn't define any ordering between the memory space and the I/O space. +*/ +#define __io_br () do {} while (0) +#define __io_ar (v) __asm__ __volatile__ ("fence i,r" : : : "memory"); +#define __io_bw () __asm__ __volatile__ ("fence w,o" : : : "memory"); +#define __io_aw () do { } while (0) + +#define readb (c) ({ u8 __v; __io_br(); __v = readb_cpu(c); __io_ar(__v); __v; }) +#define readw (c) ({ u16 __v; __io_br(); __v = readw_cpu(c); __io_ar(__v); __v; }) +#define readl (c) ({ u32 __v; __io_br(); __v = readl_cpu(c); __io_ar(__v); __v; }) + +#define writeb (v,c) ({ __io_bw(); writeb_cpu((v),(c)); __io_aw(); }) +#define writew (v,c) ({ __io_bw(); writew_cpu((v),(c)); __io_aw(); }) +#define writel (v,c) ({ __io_bw(); writel_cpu((v),(c)); __io_aw(); }) + +#ifdef CONFIG_64BIT +#define readq (c) ({ u64 __v; __io_br(); __v = readq_cpu(c); __io_ar(__v); __v; }) +#define writeq (v,c) ({ __io_bw(); writeq_cpu((v),(c)); __io_aw(); }) +#endif + +#endif /* _ASM_RISCV_IO_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
2.43.0
Re: [PATCH v3 14/34] xen/riscv: introduce io.h
Quoted 17 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/io.h new file +14
-0@@ -0,0 +1,142 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* {read,write}{b,w,l,q} based on arch/arm64/include/asm/io.h +* which was based on arch/arm/include/io.h +* +* Copyright (C) 1996-2000 Russell King +* Copyright (C) 2012 ARM Ltd. +* Copyright (C) 2014 Regents of the University of California +*/ + + +#ifndef _ASM_RISCV_IO_H +#define _ASM_RISCV_IO_H +
xen/arch/riscv/include/asm/io.h line 24
Quoted 10 lines
xen/arch/riscv/include/asm/io.h new file +10
-0+#include <asm/byteorder.h> + +/* +* The RISC-V ISA doesn't yet specify how to query or modify PMAs, so we can't +* change the properties of memory regions. This should be fixed by the +* upcoming platform spec. +*/ +#define ioremap_nocache (addr, size) ioremap((addr), (size)) +#define ioremap_wc (addr, size) ioremap((addr), (size)) +#define ioremap_wt (addr, size) ioremap((addr), (size))
Nit: No need for the inner parentheses.
Quoted 72 lines
xen/arch/riscv/include/asm/io.h new file +72
-0+/* Generic IO read/write. These perform native-endian accesses. */ +#define __raw_writeb __raw_writeb +static inline void __raw_writeb (u8 val,volatile void __iomem *addr) +{ + asmvolatile ("sb %0, 0(%1)" : :"r" (val),"r" (addr)); +} + +#define __raw_writew __raw_writew +static inline void __raw_writew (u16 val,volatile void __iomem *addr) +{ + asmvolatile ("sh %0, 0(%1)" : :"r" (val),"r" (addr)); +} + +#define __raw_writel __raw_writel +static inline void __raw_writel (u32 val,volatile void __iomem *addr) +{ + asmvolatile ("sw %0, 0(%1)" : :"r" (val),"r" (addr)); +} + +#ifdef CONFIG_64BIT +#define __raw_writeq __raw_writeq +static inline void __raw_writeq (u64 val,volatile void __iomem *addr) +{ + asmvolatile ("sd %0, 0(%1)" : :"r" (val),"r" (addr)); +} +#endif + +#define __raw_readb __raw_readb +static inline u8 __raw_readb (const volatile void __iomem *addr) +{ +u8 val; + + asmvolatile ("lb %0, 0(%1)" :"=r" (val) :"r" (addr)); +return val; +} + +#define __raw_readw __raw_readw +static inline u16 __raw_readw (const volatile void __iomem *addr) +{ +u16 val; + + asmvolatile ("lh %0, 0(%1)" :"=r" (val) :"r" (addr)); +return val; +} + +#define __raw_readl __raw_readl +static inline u32 __raw_readl (const volatile void __iomem *addr) +{ +u32 val; + + asmvolatile ("lw %0, 0(%1)" :"=r" (val) :"r" (addr)); +return val; +} + +#ifdef CONFIG_64BIT +#define __raw_readq __raw_readq +static inline u64 __raw_readq (const volatile void __iomem *addr) +{ +u64 val; + + asmvolatile ("ld %0, 0(%1)" :"=r" (val) :"r" (addr)); +return val; +} +#endif + +/* +* Unordered I/O memory access primitives. These are even more relaxed than +* the relaxed versions, as they don't even order accesses between successive +* operations to the I/O regions. +*/ +#define readb_cpu (c) ({ u8 __r = __raw_readb(c); __r; }) +#define readw_cpu (c) ({ u16 __r = le16_to_cpu((__force __le16)__raw_readw(c)); __r; })
xen/arch/riscv/include/asm/io.h line 107
Quoted 10 lines
xen/arch/riscv/include/asm/io.h new file +10
-0+#define readl_cpu (c) ({ u32 __r = le32_to_cpu((__force __le32)__raw_readl(c)); __r; }) + +#define writeb_cpu (v,c) ((void)__raw_writeb((v),(c))) +#define writew_cpu (v,c) ((void)__raw_writew((__force u16)cpu_to_le16(v),(c))) +#define writel_cpu (v,c) ((void)__raw_writel((__force u32)cpu_to_le32(v),(c))) + +#ifdef CONFIG_64BIT +#define readq_cpu (c) ({ u64 __r = le64_to_cpu((__force __le64)__raw_readq(c)); __r; }) +#define writeq_cpu (v,c) ((void)__raw_writeq((__force u64)cpu_to_le64(v),(c))) +#endif
How come there are endianness assumptions here on the MMIO accessed?
As a file-wide remark: While I don't mind you using u<N> here for now, presumably to stay close to Linux, eventually - as we make progress with the conversion to uint<N>_t - this will need to diverge anyway.
xen/arch/riscv/include/asm/io.h line 115
Quoted 7 lines
xen/arch/riscv/include/asm/io.h new file +7
-0+/* +* I/O memory access primitives. Reads are ordered relative to any +* following Normal memory access. Writes are ordered relative to any prior +* Normal memory access. The memory barriers here are necessary as RISC-V +* doesn't define any ordering between the memory space and the I/O space. +*/ +#define __io_br () do {} while (0)
Nit: Why are this and ...
xen/arch/riscv/include/asm/io.h line 118
Quoted 3 lines
xen/arch/riscv/include/asm/io.h new file +3
-0+#define __io_ar (v) __asm__ __volatile__ ("fence i,r" : : : "memory"); +#define __io_bw () __asm__ __volatile__ ("fence w,o" : : : "memory"); +#define __io_aw () do { } while (0)
... this not expanding exactly the same?
Jan
Re: [PATCH v3 14/34] xen/riscv: introduce io.h
Quoted 24 lines · Jan Beulich
Quoted 23 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/io.h new file +18
-0@@ -0,0 +1,142 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* {read,write}{b,w,l,q} based on arch/arm64/include/asm/io.h +* which was based on arch/arm/include/io.h +* +* Copyright (C) 1996-2000 Russell King +* Copyright (C) 2012 ARM Ltd. +* Copyright (C) 2014 Regents of the University of California +*/ + + +#ifndef _ASM_RISCV_IO_H +#define _ASM_RISCV_IO_H + +#include <asm/byteorder.h> + +/* +* The RISC-V ISA doesn't yet specify how to query or modify PMAs, so we can't
+ * change the properties of memory regions. This should be fixed
Quoted 8 lines
xen/arch/riscv/include/asm/io.h line 24
Quoted 6 lines
by the
+ * upcoming platform spec.
+ */xen/arch/riscv/include/asm/io.h new file +3
-0+#define ioremap_nocache (addr, size) ioremap((addr), (size)) +#define ioremap_wc (addr, size) ioremap((addr), (size)) +#define ioremap_wt (addr, size) ioremap((addr), (size))Nit: No need for the inner parentheses.
Thanks. I'll update that place.
Quoted 92 lines
Quoted 92 lines
+/* Generic IO read/write. These perform native-endian accesses. */
xen/arch/riscv/include/asm/io.h new file +2
-0+#define __raw_writeb __raw_writeb +static inline void __raw_writeb(u8 val, volatile void __iomem*addr)
xen/arch/riscv/include/asm/io.h new file +6
-0+{ + asmvolatile ("sb %0, 0(%1)" : :"r" (val),"r" (addr)); +} + +#define __raw_writew __raw_writew +static inline void __raw_writew(u16 val, volatile void __iomem*addr)
xen/arch/riscv/include/asm/io.h new file +6
-0+{ + asmvolatile ("sh %0, 0(%1)" : :"r" (val),"r" (addr)); +} + +#define __raw_writel __raw_writel +static inline void __raw_writel(u32 val, volatile void __iomem*addr)
xen/arch/riscv/include/asm/io.h new file +7
-0+{ + asmvolatile ("sw %0, 0(%1)" : :"r" (val),"r" (addr)); +} + +#ifdef CONFIG_64BIT +#define __raw_writeq __raw_writeq +static inline void __raw_writeq(u64 val, volatile void __iomem*addr)
xen/arch/riscv/include/asm/io.h new file +45
-0+{ + asmvolatile ("sd %0, 0(%1)" : :"r" (val),"r" (addr)); +} +#endif + +#define __raw_readb __raw_readb +static inline u8 __raw_readb (const volatile void __iomem *addr) +{ +u8 val; + + asmvolatile ("lb %0, 0(%1)" :"=r" (val) :"r" (addr)); +return val; +} + +#define __raw_readw __raw_readw +static inline u16 __raw_readw (const volatile void __iomem *addr) +{ +u16 val; + + asmvolatile ("lh %0, 0(%1)" :"=r" (val) :"r" (addr)); +return val; +} + +#define __raw_readl __raw_readl +static inline u32 __raw_readl (const volatile void __iomem *addr) +{ +u32 val; + + asmvolatile ("lw %0, 0(%1)" :"=r" (val) :"r" (addr)); +return val; +} + +#ifdef CONFIG_64BIT +#define __raw_readq __raw_readq +static inline u64 __raw_readq (const volatile void __iomem *addr) +{ +u64 val; + + asmvolatile ("ld %0, 0(%1)" :"=r" (val) :"r" (addr)); +return val; +} +#endif + +/* +* Unordered I/O memory access primitives. These are even more relaxed than
+ * the relaxed versions, as they don't even order accesses between successive
+ * operations to the I/O regions.
+ */
+#definereadb_cpu(c)({ u8__r=__raw_readb(c);__r;
})
+#definereadw_cpu(c)({ u16__r= le16_to_cpu((__force
__le16)__raw_readw(c));__r; })
+#definereadl_cpu(c)({ u32__r= le32_to_cpu((__force
__le32)__raw_readl(c));__r; })xen/arch/riscv/include/asm/io.h new file +2
-0+ +#define
writeb_cpu(v,c)((void)__raw_writeb((v),(c)))
+#definewritew_cpu(v,c)((void)__raw_writew((__force u16)cpu_to_le16(v),(c)))
+#definewritel_cpu(v,c)((void)__raw_writel((__force u32)cpu_to_le32(v),(c)))
+
Quoted 8 lines
Quoted 6 lines
xen/arch/riscv/include/asm/io.h new file +2
-0+#ifdef CONFIG_64BIT +#define readq_cpu (c) ({ u64 __r = le64_to_cpu((__force__le64)__raw_readq(c));
__r; })
+#definewriteq_cpu(v,c)((void)__raw_writeq((__force u64)cpu_to_le64(v),(c)))
+#endifHow come there are endianness assumptions here on the MMIO accessed?
It is a hard story.
As you might expect it was copy from Linux Kernel where it was decided to follow only LE way:
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/
One of the answers of the author of the commit:
And we don't know if Linux will be around if that ever changes. The point is:
a) the current RISC-V spec is LE only
b) the current linux port is LE only except for this little bit
There is no point in leaving just this bitrotting code around. It just confuses developers, (very very slightly) slows down compiles and will bitrot. It also won't be any significant help to a future developer down the road doing a hypothetical BE RISC-V Linux port.
From the specs [1, p.5 ] it is mentioned that:
The base ISA has been defined to have a little-endian memory system, with big-endian or bi-endian as non-standard variants.
And in [3, p.6]:
RISC-V base ISAs have either little-endian or big-endian memory systems, with the privileged architecture further defining bi-endian operation. Instructions are stored in memory as a sequence of 16-bit little-endian parcels, regardless of memory system endianness. Parcels forming one instruction are stored at increasing halfword addresses, with the lowest-addressed parcel holding the lowest-numbered bits in the instruction specification.
We originally chose little-endian byte ordering for the RISC-V memory
system because little-endian systems are currently dominant commercially (all x86 systems; iOS, Android, and Windows for ARM). A minor point is that we have also found little-endian memory systems to be more natural for hardware designers. However, certain application areas, such as IP networking, operate on big-endian data structures, and certain legacy code bases have been built assuming big-endian processors, so we have defined big-endian and bi-endian variants of RISC-V.
We have to fix the order in which instruction parcels are stored in
memory, independent of memory system endianness, to ensure that the length-encoding bits always appear first in halfword address order. This allows the length of a variable-length instruction to be quickly determined by an instruction-fetch unit by examining only the first few bits of the first 16-bit instruction parcel.
[ this part is from source [2] which I can't find in [3] for some uknown reason ]
We further make the instruction parcels themselves little-endian to decouple the instruction encoding from the memory system endianness altogether. This design benefits both software tooling and bi-endian hardware. Otherwise, for instance, a RISC-V assembler or disassembler would always need to know the intended active endianness, despite that in bi-endian systems, the endianness mode might change dynamically during execution. In contrast, by giving instructions a fixed endianness, it is sometimes possible for carefully written software to be endianness-agnostic even in binary form, much like position- independent code.
The choice to have instructions be only little-endian does have consequences, however, for RISC-V software that encodes or decodes machine instructions. Big-endian JIT compilers, for example, must swap the byte order when storing to instruction memory.
Once we had decided to fix on a little-endian instruction encoding, this naturally led to placing the length-encoding bits in the LSB positions of the instruction format to avoid breaking up opcode fields.
[1] https://riscv.org/wp-content/uploads/2017/05/riscv-spec-v2.2.pdf
[2] https://five-embeddev.com/riscv-isa-manual/latest/intro.html
[3] https://riscv.org/wp-content/uploads/2017/05/riscv-spec-v2.2.pdf
Quoted 6 lines
As a file-wide remark: While I don't mind you using u<N> here for now,
presumably to stay close to Linux, eventually - as we make progress with
the conversion to uint<N>_t - this will need to diverge anyway.
Then I'll use uint<N>_t everywhere from the start. I am pretty sure this file doesn't require sync often, so we can use Xen style instead of Linux.
Quoted 14 lines
Quoted 11 lines
+/*
+ * I/O memory access primitives. Reads are ordered relative to any
+ * following Normal memory access. Writes are ordered relative to any prior
+ * Normal memory access. The memory barriers here are necessary as RISC-V
+ * doesn't define any ordering between the memory space and the I/O space.
+ */
+#define__io_br()do {} while (0)Nit: Why are this and ...
Quoted 7 lines
Quoted 5 lines
+#define
__io_ar(v)__asm____volatile__("fence i,r" : : :
"memory");
+#define__io_bw()__asm____volatile__("fence w,o" : : :
"memory");
+#define__io_aw()do { } while (0)... this not expanding exactly the same?
I don't know the specific reason, it was done so in Linux kernel in case when CONFIG_MMIOWB isn't supported:
https://elixir.bootlin.com/linux/latest/source/include/asm-generic/mmiowb.h#L61
https://elixir.bootlin.com/linux/latest/source/arch/riscv/include/asm/mmio.h#L136
~ Oleksii
Re: [PATCH v3 14/34] xen/riscv: introduce io.h
Quoted 33 lines · Oleksii
Quoted 22 lines · Jan Beulich
Quoted 21 lines · Oleksii Kurochko
+/*
+ * Unordered I/O memory access primitives. These are even more relaxed than
+ * the relaxed versions, as they don't even order accesses between successive
+ * operations to the I/O regions.
+ */
+#definereadb_cpu(c)({ u8__r=__raw_readb(c);__r;
})
+#definereadw_cpu(c)({ u16__r= le16_to_cpu((__force
__le16)__raw_readw(c));__r; })
+#definereadl_cpu(c)({ u32__r= le32_to_cpu((__force
__le32)__raw_readl(c));__r; })(quoted diff) +2
-0+ +#define
writeb_cpu(v,c)((void)__raw_writeb((v),(c)))
+#definewritew_cpu(v,c)((void)__raw_writew((__force u16)cpu_to_le16(v),(c)))
+#definewritel_cpu(v,c)((void)__raw_writel((__force u32)cpu_to_le32(v),(c)))
+Quoted 8 lines
Quoted 6 lines
(quoted diff) +2
-0+#ifdef CONFIG_64BIT +#define readq_cpu(c) ({ u64 __r = le64_to_cpu((__force__le64)__raw_readq(c));
__r; })
+#definewriteq_cpu(v,c)((void)__raw_writeq((__force u64)cpu_to_le64(v),(c)))
+#endifHow come there are endianness assumptions here on the MMIO accessed?
It is a hard story.
Quoted 12 lines
As you might expect it was copy from Linux Kernel where it was decided to follow only LE way:
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/
One of the answers of the author of the commit:
And we don't know if Linux will be around if that ever changes. The point is:
a) the current RISC-V spec is LE only
b) the current linux port is LE only except for this little bit
There is no point in leaving just this bitrotting code around. It just confuses developers, (very very slightly) slows down compiles and will bitrot. It also won't be any significant help to a future developer down the road doing a hypothetical BE RISC-V Linux port.
Reads to me like a justification to _omit_ the cpu_to_le<N>().
Jan
Re: [PATCH v3 14/34] xen/riscv: introduce io.h
Quoted 63 lines · Jan Beulich
Quoted 53 lines · Oleksii
Quoted 32 lines · Jan Beulich
Quoted 31 lines · Oleksii Kurochko
+/*
+ * Unordered I/O memory access primitives. These are even more
relaxed than
+ * the relaxed versions, as they don't even order accesses between
successive
+ * operations to the I/O regions.
+ */
+#definereadb_cpu(c)({ u8__r=__raw_readb(c);__r;
})
+#definereadw_cpu(c)({ u16__r=
le16_to_cpu((__force
__le16)__raw_readw(c));__r; })
+#definereadl_cpu(c)({ u32__r=
le32_to_cpu((__force
__le32)__raw_readl(c));__r; })(quoted diff) +2
-0+ +#define
writeb_cpu(v,c)((void)__raw_writeb((v),(c)))
+#definewritew_cpu(v,c)((void)__raw_writew((__force
u16)cpu_to_le16(v),(c)))
+#definewritel_cpu(v,c)((void)__raw_writel((__force
u32)cpu_to_le32(v),(c)))xen/arch/riscv/include/asm/io.h new file +3
-0+ +#ifdef CONFIG_64BIT +#define readq_cpu (c) ({ u64 __r =le64_to_cpu((__force
Quoted 8 lines
Quoted 5 lines
__le64)__raw_readq(c));
__r; })
+#definewriteq_cpu(v,c)((void)__raw_writeq((__force
u64)cpu_to_le64(v),(c)))
+#endifHow come there are endianness assumptions here on the MMIO accessed?
It is a hard story.
As you might expect it was copy from Linux Kernel where it was decided
to follow only LE way:
https://patchwork.kernel.org/project/linux-riscv/patch/[email protected]/
One of the answers of the author of the commit:
And we don't know if Linux will be around if that ever changes. The point is:
a) the current RISC-V spec is LE only
b) the current linux port is LE only except for this little bitQuoted 8 lines
There is no point in leaving just this bitrotting code around. It
just confuses developers, (very very slightly) slows down compiles
and will bitrot. It also won't be any significant help to a future
developer down the road doing a hypothetical BE RISC-V Linux port.
Quoted 1 line
Reads to me like a justification to _omit_ the cpu_to_le<N>().
Looks like we can omit cpu_to_le<N>(). Even docs say that memory system is little-endian except:
However, certain application areas, such as IP networking, operate on big-endian data structures, and certain legacy code bases have been built assuming big-endian
processors, so we expect that future specifications will describe big-endian or bi-endian variants
of RISC-V.
~ Oleksii
PATCH v3 15/34 xen/riscv: introduce atomic.h
In reply to Oleksii KurochkoFrom: Bobby Eshleman <[email protected]>
Additionally, this patch introduces macros in fence.h, which are utilized in atomic.h.
---
Changes in V3:
- update the commit message
- add SPDX for fence.h
- code style fixes
- Remove /* TODO: ... */ for add_sized macros. It looks correct to me.
- re-order the patch
- merge to this patch fence.h
---
Changes in V2:
- Change an author of commit. I got this header from Bobby's old repo.
--- xen/arch/riscv/include/asm/atomic.h | 384 ++++++++++++++++++++++++++++ xen/arch/riscv/include/asm/fence.h | 13 + 2 files changed, 397 insertions(+) create mode 100644 xen/arch/riscv/include/asm/atomic.h create mode 100644 xen/arch/riscv/include/asm/fence.h
xen/arch/riscv/include/asm/atomic.h new file +384 -0
@@ -0,0 +1,384 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Taken and modified from Linux. +* +* Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. +* Copyright (C) 2012 Regents of the University of California +* Copyright (C) 2017 SiFive +* Copyright (C) 2021 Vates SAS +*/ + +#ifndef _ASM_RISCV_ATOMIC_H +#define _ASM_RISCV_ATOMIC_H + +#include <xen/atomic.h> +#include <asm/cmpxchg.h> +#include <asm/fence.h> +#include <asm/io.h> +#include <asm/system.h> + +void __bad_atomic_size (void ); + +static always_inline void read_atomic_size(const volatile void *p, +void *res, +unsigned int size) +{ +switch ( size ) + { +case 1 : *(uint8_t *)res =readb ((const uint8_t *)p);break ; +case 2 : *(uint16_t *)res =readw ((const uint16_t *)p);break ; +case 4 : *(uint32_t *)res =readl ((const uint32_t *)p);break ; +case 8 : *(uint32_t *)res =readq ((const uint64_t *)p);break ; +default :__bad_atomic_size ();break ; + } +} + +#define read_atomic (p) ({ \ + union { typeof(*p) val; char c[0]; } x_; \ + read_atomic_size(p, x_.c, sizeof(*p)); \ + x_.val; \ +}) + + +#define write_atomic (p, x) ({ \ + typeof(*p) x__ = (x); \ + switch ( sizeof(*p) ) \ + { \ + case 1: writeb((uint8_t)x__, (uint8_t *) p); break; \ + case 2: writew((uint16_t)x__, (uint16_t *) p); break; \ + case 4: writel((uint32_t)x__, (uint32_t *) p); break; \ + case 8: writeq((uint64_t)x__, (uint64_t *) p); break; \ + default: __bad_atomic_size(); break; \ + } \ + x__; \ +}) + +#define add_sized (p, x) ({ \ + typeof(*(p)) x__ = (x); \ + switch ( sizeof(*(p)) ) \ + { \ + case 1: writeb(read_atomic(p) + x__, (uint8_t *)(p)); break; \ + case 2: writew(read_atomic(p) + x__, (uint16_t *)(p)); break; \ + case 4: writel(read_atomic(p) + x__, (uint32_t *)(p)); break; \ + default: __bad_atomic_size(); break; \ + } \ +}) + +/* +* __unqual_scalar_typeof(x) - Declare an unqualified scalar type, leaving +* non-scalar types unchanged. +* +* Prefer C11 _Generic for better compile-times and simpler code. Note: 'char' +* is not type-compatible with 'signed char', and we define a separate case. +*/ +#define __scalar_type_to_expr_cases (type) \ + unsigned type: (unsigned type)0, \ + signed type: (signed type)0 + +#define __unqual_scalar_typeof (x) typeof( \ + _Generic((x), \ + char: (char)0, \ + __scalar_type_to_expr_cases(char), \ + __scalar_type_to_expr_cases(short), \ + __scalar_type_to_expr_cases(int), \ + __scalar_type_to_expr_cases(long), \ + __scalar_type_to_expr_cases(long long), \ + default: (x))) + +#define READ_ONCE (x) (*(const volatile __unqual_scalar_typeof(x) *)&(x)) +#define WRITE_ONCE (x, val) \ + do { \ + *(volatile typeof(x) *)&(x) = (val); \ + } while (0) + +#define __atomic_acquire_fence () \ + __asm__ __volatile__( RISCV_ACQUIRE_BARRIER "" ::: "memory" ) + +#define __atomic_release_fence () \ + __asm__ __volatile__( RISCV_RELEASE_BARRIER "" ::: "memory" ); + +static inline int atomic_read (const atomic_t *v) +{ +return READ_ONCE (v->counter); +} + +static inline int _atomic_read (atomic_t v) +{ +return v.counter; +} + +static inline void atomic_set (atomic_t *v,int i) +{ +WRITE_ONCE (v->counter, i); +} + +static inline void _atomic_set (atomic_t *v,int i) +{ + v->counter = i; +} + +static inline int atomic_sub_and_test (int i,atomic_t *v) +{ +return atomic_sub_return (i, v) ==0 ; +} + +static inline void atomic_inc (atomic_t *v) +{ +atomic_add (1 , v); +} + +static inline int atomic_inc_return (atomic_t *v) +{ +return atomic_add_return (1 , v); +} + +static inline void atomic_dec (atomic_t *v) +{ +atomic_sub (1 , v); +} + +static inline int atomic_dec_return (atomic_t *v) +{ +return atomic_sub_return (1 , v); +} + +static inline int atomic_dec_and_test (atomic_t *v) +{ +return atomic_sub_return (1 , v) ==0 ; +} + +static inline int atomic_add_negative (int i,atomic_t *v) +{ +return atomic_add_return (i, v) <0 ; +} + +static inline int atomic_inc_and_test (atomic_t *v) +{ +return atomic_add_return (1 , v) ==0 ; +} + +/* +* First, the atomic ops that have no ordering constraints and therefor don't +* have the AQ or RL bits set. These don't return anything, so there's only +* one version to worry about. +*/ +#define ATOMIC_OP (op, asm_op,I , asm_type, c_type, prefix) \ +static inline \ +void atomic##prefix##_##op(c_type i, atomic##prefix##_t *v) \ +{ \ + __asm__ __volatile__ ( \ + " amo" #asm_op "." #asm_type " zero, %1, %0" \ + : "+A" (v->counter) \ + : "r" (I) \ + : "memory" ); \ +} \ + +#define ATOMIC_OPS (op, asm_op,I ) \ + ATOMIC_OP (op, asm_op, I, w, int, ) + +ATOMIC_OPS(add, add, i) +ATOMIC_OPS(sub, add, -i) +ATOMIC_OPS(and, and, i) +ATOMIC_OPS( or, or, i) +ATOMIC_OPS(xor, xor, i) + +#undef ATOMIC_OP +#undef ATOMIC_OPS + +/* +* Atomic ops that have ordered, relaxed, acquire, and release variants. +* There's two flavors of these: the arithmatic ops have both fetch and return +* versions, while the logical ops only have fetch versions. +*/ +#define ATOMIC_FETCH_OP (op, asm_op,I , asm_type, c_type, prefix) \ +static inline \ +c_type atomic##prefix##_fetch_##op##_relaxed(c_type i, \ + atomic##prefix##_t *v) \ +{ \ + register c_type ret; \ + __asm__ __volatile__ ( \ + " amo" #asm_op "." #asm_type " %1, %2, %0" \ + : "+A" (v->counter), "=r" (ret) \ + : "r" (I) \ + : "memory" ); \ + return ret; \ +} \ +static inline \ +c_type atomic##prefix##_fetch_##op(c_type i, atomic##prefix##_t *v) \ +{ \ + register c_type ret; \ + __asm__ __volatile__ ( \ + " amo" #asm_op "." #asm_type ".aqrl %1, %2, %0" \ + : "+A" (v->counter), "=r" (ret) \ + : "r" (I) \ + : "memory" ); \ + return ret; \ +} + +#define ATOMIC_OP_RETURN (op, asm_op, c_op,I , asm_type, c_type, prefix) \ +static inline \ +c_type atomic##prefix##_##op##_return_relaxed(c_type i, \ + atomic##prefix##_t *v) \ +{ \ + return atomic##prefix##_fetch_##op##_relaxed(i, v) c_op I; \ +} \ +static inline \ +c_type atomic##prefix##_##op##_return(c_type i, atomic##prefix##_t *v) \ +{ \ + return atomic##prefix##_fetch_##op(i, v) c_op I; \ +} + +#define ATOMIC_OPS (op, asm_op, c_op,I ) \ + ATOMIC_FETCH_OP( op, asm_op, I, w, int, ) \ + ATOMIC_OP_RETURN(op, asm_op, c_op, I, w, int, ) + +ATOMIC_OPS(add, add, +, i) +ATOMIC_OPS(sub, add, +, -i) + +#define atomic_add_return_relaxed atomic_add_return_relaxed +#define atomic_sub_return_relaxed atomic_sub_return_relaxed +#define atomic_add_return atomic_add_return +#define atomic_sub_return atomic_sub_return + +#define atomic_fetch_add_relaxed atomic_fetch_add_relaxed +#define atomic_fetch_sub_relaxed atomic_fetch_sub_relaxed +#define atomic_fetch_add atomic_fetch_add +#define atomic_fetch_sub atomic_fetch_sub + +#undef ATOMIC_OPS + +#define ATOMIC_OPS (op, asm_op,I ) \ + ATOMIC_FETCH_OP(op, asm_op, I, w, int, ) + +ATOMIC_OPS(and, and, i) +ATOMIC_OPS( or, or, i) +ATOMIC_OPS(xor, xor, i) + +#define atomic_fetch_and_relaxed atomic_fetch_and_relaxed +#define atomic_fetch_or_relaxed atomic_fetch_or_relaxed +#define atomic_fetch_xor_relaxed atomic_fetch_xor_relaxed +#define atomic_fetch_and atomic_fetch_and +#define atomic_fetch_or atomic_fetch_or +#define atomic_fetch_xor atomic_fetch_xor + +#undef ATOMIC_OPS + +#undef ATOMIC_FETCH_OP +#undef ATOMIC_OP_RETURN + +/* This is required to provide a full barrier on success. */ +static inline int atomic_add_unless (atomic_t *v,int a,int u) +{ +int prev, rc; + + __asm__ __volatile__ ( +"0: lr.w %[p], %[c]\n" +" beq %[p], %[u], 1f\n" +" add %[rc], %[p], %[a]\n" +" sc.w.rl %[rc], %[rc], %[c]\n" +" bnez %[rc], 0b\n" +" fence rw, rw\n" +"1:\n" + : [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter) + : [a]"r" (a), [u]"r" (u) + :"memory" ); +return prev; +} +#define atomic_fetch_add_unless atomic_fetch_add_unless + +/* +* atomic_{cmp,}xchg is required to have exactly the same ordering semantics as +* {cmp,}xchg and the operations that return, so they need a full barrier. +*/ +#define ATOMIC_OP (c_t, prefix, size) \ +static inline \ +c_t atomic##prefix##_xchg_relaxed(atomic##prefix##_t *v, c_t n) \ +{ \ + return __xchg_relaxed(&(v->counter), n, size); \ +} \ +static inline \ +c_t atomic##prefix##_xchg_acquire(atomic##prefix##_t *v, c_t n) \ +{ \ + return __xchg_acquire(&(v->counter), n, size); \ +} \ +static inline \ +c_t atomic##prefix##_xchg_release(atomic##prefix##_t *v, c_t n) \ +{ \ + return __xchg_release(&(v->counter), n, size); \ +} \ +static inline \ +c_t atomic##prefix##_xchg(atomic##prefix##_t *v, c_t n) \ +{ \ + return __xchg(&(v->counter), n, size); \ +} \ +static inline \ +c_t atomic##prefix##_cmpxchg_relaxed(atomic##prefix##_t *v, \ + c_t o, c_t n) \ +{ \ + return __cmpxchg_relaxed(&(v->counter), o, n, size); \ +} \ +static inline \ +c_t atomic##prefix##_cmpxchg_acquire(atomic##prefix##_t *v, \ + c_t o, c_t n) \ +{ \ + return __cmpxchg_acquire(&(v->counter), o, n, size); \ +} \ +static inline \ +c_t atomic##prefix##_cmpxchg_release(atomic##prefix##_t *v, \ + c_t o, c_t n) \ +{ \ + return __cmpxchg_release(&(v->counter), o, n, size); \ +} \ +static inline \ +c_t atomic##prefix##_cmpxchg(atomic##prefix##_t *v, c_t o, c_t n) \ +{ \ + return __cmpxchg(&(v->counter), o, n, size); \ +} + +#define ATOMIC_OPS () \ + ATOMIC_OP(int, , 4) + +ATOMIC_OPS() + +#define atomic_xchg_relaxed atomic_xchg_relaxed +#define atomic_xchg_acquire atomic_xchg_acquire +#define atomic_xchg_release atomic_xchg_release +#define atomic_xchg atomic_xchg +#define atomic_cmpxchg_relaxed atomic_cmpxchg_relaxed +#define atomic_cmpxchg_acquire atomic_cmpxchg_acquire +#define atomic_cmpxchg_release atomic_cmpxchg_release +#define atomic_cmpxchg atomic_cmpxchg + +#undef ATOMIC_OPS +#undef ATOMIC_OP + +static inline int atomic_sub_if_positive (atomic_t *v,int offset) +{ +int prev, rc; + + __asm__ __volatile__ ( +"0: lr.w %[p], %[c]\n" +" sub %[rc], %[p], %[o]\n" +" bltz %[rc], 1f\n" +" sc.w.rl %[rc], %[rc], %[c]\n" +" bnez %[rc], 0b\n" +" fence rw, rw\n" +"1:\n" + : [p]"=&r" (prev), [rc]"=&r" (rc), [c]"+A" (v->counter) + : [o]"r" (offset) + :"memory" ); +return prev - offset; +} + +#define atomic_dec_if_positive (v) atomic_sub_if_positive(v, 1) + +#endif /* _ASM_RISCV_ATOMIC_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
xen/arch/riscv/include/asm/fence.h new file +13 -0
@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _ASM_RISCV_FENCE_H +#define _ASM_RISCV_FENCE_H + +#ifdef CONFIG_SMP +#define RISCV_ACQUIRE_BARRIER "\tfence r , rw\n" +#define RISCV_RELEASE_BARRIER "\tfence rw, w\n" +#else +#define RISCV_ACQUIRE_BARRIER +#define RISCV_RELEASE_BARRIER +#endif + +#endif /* _ASM_RISCV_FENCE_H */
Signature · 1 line
2.43.0
Re: [PATCH v3 15/34] xen/riscv: introduce atomic.h
Quoted 24 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/atomic.h new file +21
-0@@ -0,0 +1,384 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Taken and modified from Linux. +* +* Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. +* Copyright (C) 2012 Regents of the University of California +* Copyright (C) 2017 SiFive +* Copyright (C) 2021 Vates SAS +*/ + +#ifndef _ASM_RISCV_ATOMIC_H +#define _ASM_RISCV_ATOMIC_H + +#include <xen/atomic.h> +#include <asm/cmpxchg.h> +#include <asm/fence.h> +#include <asm/io.h> +#include <asm/system.h> + +void __bad_atomic_size (void ); +
xen/arch/riscv/include/asm/atomic.h line 31
Quoted 10 lines
xen/arch/riscv/include/asm/atomic.h new file +10
-0+static always_inline void read_atomic_size(const volatile void *p, +void *res, +unsigned int size) +{ +switch ( size ) + { +case 1 : *(uint8_t *)res =readb ((const uint8_t *)p);break ; +case 2 : *(uint16_t *)res =readw ((const uint16_t *)p);break ; +case 4 : *(uint32_t *)res =readl ((const uint32_t *)p);break ; +case 8 : *(uint32_t *)res =readq ((const uint64_t *)p);break ;
Just like const, you should also avoid casting away volatile.
xen/arch/riscv/include/asm/atomic.h line 42
Quoted 11 lines
xen/arch/riscv/include/asm/atomic.h new file +11
-0+default :__bad_atomic_size ();break ; + } +} + +#define read_atomic (p) ({ \ + union { typeof(*p) val; char c[0]; } x_; \ + read_atomic_size(p, x_.c, sizeof(*p)); \ + x_.val; \ +}) + +
Nit: No double blank lines please.
xen/arch/riscv/include/asm/atomic.h line 46
Quoted 4 lines
xen/arch/riscv/include/asm/atomic.h new file +4
-0+#define write_atomic (p, x) ({ \ + typeof(*p) x__ = (x); \ + switch ( sizeof(*p) ) \ + { \
These lines look excessively long, possibly as a result of leaving hard tabs in place.
Overall some of the style comments on the earlier patch seem to apply here as well.
Quoted 4 lines
xen/arch/riscv/include/asm/fence.h new file +1
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */
xen/arch/riscv/include/asm/fence.h line 11
Quoted 10 lines
xen/arch/riscv/include/asm/fence.h new file +10
-0+#ifndef _ASM_RISCV_FENCE_H +#define _ASM_RISCV_FENCE_H + +#ifdef CONFIG_SMP +#define RISCV_ACQUIRE_BARRIER "\tfence r , rw\n" +#define RISCV_RELEASE_BARRIER "\tfence rw, w\n" +#else +#define RISCV_ACQUIRE_BARRIER +#define RISCV_RELEASE_BARRIER +#endif
Do you really care about the !SMP case? On x86 at least we stopped special- casing that configuration many years ago (the few cases where for typically build reasons it matters, using CONFIG_NR_CPUS is sufficient). If you care about it, there needs to be somewhere you actually #define CONFIG_SMP.
Jan
Re: [PATCH v3 15/34] xen/riscv: introduce atomic.h
Quoted 29 lines · Jan Beulich
Quoted 28 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/atomic.h new file +25
-0@@ -0,0 +1,384 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* +* Taken and modified from Linux. +* +* Copyright (C) 2007 Red Hat, Inc. All Rights Reserved. +* Copyright (C) 2012 Regents of the University of California +* Copyright (C) 2017 SiFive +* Copyright (C) 2021 Vates SAS +*/ + +#ifndef _ASM_RISCV_ATOMIC_H +#define _ASM_RISCV_ATOMIC_H + +#include <xen/atomic.h> +#include <asm/cmpxchg.h> +#include <asm/fence.h> +#include <asm/io.h> +#include <asm/system.h> + +void __bad_atomic_size (void ); + +static always_inline void read_atomic_size(const volatile void *p, + void *res, + unsigned int size) +{
Quoted 8 lines
xen/arch/riscv/include/asm/atomic.h line 31
Quoted 6 lines
xen/arch/riscv/include/asm/atomic.h new file +6
-0+ switch ( size ) + { + case 1: *(uint8_t *)res = readb((const uint8_t *)p); break; + case 2: *(uint16_t *)res = readw((const uint16_t *)p); break; + case 4: *(uint32_t *)res = readl((const uint32_t *)p); break; + case 8: *(uint32_t *)res = readq((const uint64_t *)p); break;Just like const, you should also avoid casting away volatile.
Thanks. I will drop casting.
Quoted 11 lines
Quoted 11 lines
xen/arch/riscv/include/asm/atomic.h new file +5
-0+ default: __bad_atomic_size(); break; + } +} + +#define read_atomic (p)({ \
+ union {typeof(*p)val; char c[0]; } x_; \
+read_atomic_size(p, x_.c, sizeof(*p)); \
Quoted 8 lines
xen/arch/riscv/include/asm/atomic.h line 42
Quoted 6 lines
+
x_.val;
\xen/arch/riscv/include/asm/atomic.h new file +3
-0+}) + +Nit: No double blank lines please.
Sure. I'll drtop one blank line.
Quoted 33 lines
Quoted 9 lines
+#define
write_atomic(p, x)
({ \
+typeof(*p)x__=
(x); \
+ switch (sizeof(*p)
) \
+
{ \These lines look excessively long, possibly as a result of leaving hard tabs
in place.Overall some of the style comments on the earlier patch seem to apply here
as well.Quoted 4 lines
xen/arch/riscv/include/asm/fence.h new file +1
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ xen/arch/riscv/include/asm/fence.h line 11
Quoted 10 lines
xen/arch/riscv/include/asm/fence.h new file +10
-0+#ifndef _ASM_RISCV_FENCE_H +#define _ASM_RISCV_FENCE_H + +#ifdef CONFIG_SMP +#define RISCV_ACQUIRE_BARRIER "\tfence r , rw\n" +#define RISCV_RELEASE_BARRIER "\tfence rw, w\n" +#else +#define RISCV_ACQUIRE_BARRIER +#define RISCV_RELEASE_BARRIER +#endif
Quoted 8 lines
Do you really care about the !SMP case? On x86 at least we stopped special-
casing that configuration many years ago (the few cases where for typically
build reasons it matters, usingCONFIG_NR_CPUSis sufficient). If you care
about it, there needs to be somewhere you actually #defineCONFIG_SMP.
Can't we use instead of CONFIG_SMP - CONFIG_NR_CPUS? I missed that CONFIG_SMP is present in Linux, but not in Xen.
~ Oleksii
Re: [PATCH v3 15/34] xen/riscv: introduce atomic.h
Quoted 25 lines · Oleksii
Quoted 16 lines · Jan Beulich
Quoted 4 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/fence.h new file +1
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ xen/arch/riscv/include/asm/fence.h line 11
Quoted 10 lines
xen/arch/riscv/include/asm/fence.h new file +10
-0+#ifndef _ASM_RISCV_FENCE_H +#define _ASM_RISCV_FENCE_H + +#ifdef CONFIG_SMP +#define RISCV_ACQUIRE_BARRIER "\tfence r , rw\n" +#define RISCV_RELEASE_BARRIER "\tfence rw, w\n" +#else +#define RISCV_ACQUIRE_BARRIER +#define RISCV_RELEASE_BARRIER +#endif Quoted 8 lines
Do you really care about the !SMP case? On x86 at least we stopped special-
casing that configuration many years ago (the few cases where for typically
build reasons it matters, usingCONFIG_NR_CPUSis sufficient). If you care
about it, there needs to be somewhere you actually #defineCONFIG_SMP.
Quoted 1 line
Can't we use instead of
CONFIG_SMP-CONFIG_NR_CPUS?
You can. Question is whether there's a point in doing so. Do you expect people to actually want to run Xen on single-CPU systems? They're generally not overly well suited for virtualization ...
Jan
Re: [PATCH v3 15/34] xen/riscv: introduce atomic.h
Quoted 28 lines · Jan Beulich
Quoted 27 lines · Oleksii
Quoted 26 lines · Jan Beulich
Quoted 4 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/fence.h new file +1
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ xen/arch/riscv/include/asm/fence.h line 11
Quoted 10 lines
xen/arch/riscv/include/asm/fence.h new file +10
-0+#ifndef _ASM_RISCV_FENCE_H +#define _ASM_RISCV_FENCE_H + +#ifdef CONFIG_SMP +#define RISCV_ACQUIRE_BARRIER "\tfence r , rw\n" +#define RISCV_RELEASE_BARRIER "\tfence rw, w\n" +#else +#define RISCV_ACQUIRE_BARRIER +#define RISCV_RELEASE_BARRIER +#endif Do you really care about the !SMP case? On x86 at least we stopped
special-
casing that configuration many years ago (the few cases where for typically
build reasons it matters, usingCONFIG_NR_CPUSis sufficient). If you
care
about it, there needs to be somewhere you actually #defineCONFIG_SMP.
Quoted 5 lines
Quoted 1 line
Can't we use instead of
CONFIG_SMP-CONFIG_NR_CPUS?You can. Question is whether there's a point in doing so. Do you expect people to actually want to run Xen on single-CPU systems? They're generally not overly well suited for virtualization ...
Just to clarify.
Do you mean physically single based CPU?
Then I don't expect to run Xen on such systems and it is not nesessary to define *_BARRIER in this case. Should we have to add build error notification that we don't support single-CPU systems in this header?
If you are speaking about we have ,let it be, 4 CPUs and only 1 CPU is currently supported by Xen then it still makes sense.
~ Oleksii
Re: [PATCH v3 15/34] xen/riscv: introduce atomic.h
Quoted 36 lines · Oleksii
Quoted 28 lines · Jan Beulich
Quoted 27 lines · Oleksii
Quoted 26 lines · Jan Beulich
Quoted 4 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/fence.h new file +1
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ xen/arch/riscv/include/asm/fence.h line 11
Quoted 10 lines
xen/arch/riscv/include/asm/fence.h new file +10
-0+#ifndef _ASM_RISCV_FENCE_H +#define _ASM_RISCV_FENCE_H + +#ifdef CONFIG_SMP +#define RISCV_ACQUIRE_BARRIER "\tfence r , rw\n" +#define RISCV_RELEASE_BARRIER "\tfence rw, w\n" +#else +#define RISCV_ACQUIRE_BARRIER +#define RISCV_RELEASE_BARRIER +#endif Do you really care about the !SMP case? On x86 at least we stopped
special-
casing that configuration many years ago (the few cases where for typically
build reasons it matters, usingCONFIG_NR_CPUSis sufficient). If you
care
about it, there needs to be somewhere you actually #defineCONFIG_SMP.Quoted 5 lines
Quoted 1 line
Can't we use instead of
CONFIG_SMP-CONFIG_NR_CPUS?You can. Question is whether there's a point in doing so. Do you expect people to actually want to run Xen on single-CPU systems? They're generally not overly well suited for virtualization ...
Just to clarify.
Quoted 7 lines
Do you mean physically single based CPU?
Then I don't expect to run Xen on such systems and it is not nesessary to define*_BARRIERin this case. Should we have to add build error notification that we don't support single-CPU systems in this header?If you are speaking about we have ,let it be, 4 CPUs and only 1 CPU is currently supported by Xen then it still makes sense.
No, that's still not what I mean. The question is: Is it useful for you to _special case_ the NR_CPUS=1 case? Or is it instead simpler to handle NR_CPUS=1 the same as NR_CPUS>1 (accepting less than ideal performance, on the basis that in reality nobody's expected to use such in production anyway)?
Jan
Re: [PATCH v3 15/34] xen/riscv: introduce atomic.h
Quoted 50 lines · Jan Beulich
Quoted 45 lines · Oleksii
Quoted 30 lines · Jan Beulich
Quoted 29 lines · Oleksii
Quoted 28 lines · Jan Beulich
Quoted 4 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/fence.h new file +1
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ xen/arch/riscv/include/asm/fence.h line 11
Quoted 10 lines
xen/arch/riscv/include/asm/fence.h new file +10
-0+#ifndef _ASM_RISCV_FENCE_H +#define _ASM_RISCV_FENCE_H + +#ifdef CONFIG_SMP +#define RISCV_ACQUIRE_BARRIER "\tfence r , rw\n" +#define RISCV_RELEASE_BARRIER "\tfence rw, w\n" +#else +#define RISCV_ACQUIRE_BARRIER +#define RISCV_RELEASE_BARRIER +#endif Do you really care about the !SMP case? On x86 at least we stopped
special-
casing that configuration many years ago (the few cases where for
typically
build reasons it matters, usingCONFIG_NR_CPUSis sufficient). If
you
care
about it, there needs to be somewhere you actually #defineCONFIG_SMP.Quoted 5 lines
Quoted 1 line
Can't we use instead of
CONFIG_SMP-CONFIG_NR_CPUS?You can. Question is whether there's a point in doing so. Do you expect people to actually want to run Xen on single-CPU systems? They're generally not overly well suited for virtualization ...
Just to clarify.
Do you mean physically single based CPU?
Then I don't expect to run Xen on such systems and it is not nesessary
to define*_BARRIERin this case. Should we have to add build error notification that we don't support single-CPU systems in this header?Quoted 3 lines
If you are speaking about we have ,let it be, 4 CPUs and only 1 CPU is
currently supported by Xen then it still makes sense.
Quoted 9 lines
No, that's still not what I mean. The question is: Is it useful for you
to_specialcase_the NR_CPUS=1 case? Or is it instead simpler to handle
NR_CPUS=1 the same as NR_CPUS>1 (accepting less than ideal performance,
on the basis that in reality nobody's expected to use such in production
anyway)?
NR_CPUS=1 sometimes is useful for debugging. At least, at the start I used that several times, but ITBO I don't remember when I used that case after SMP support was added and context_switch() was fixed.
Probably, I misunderstand the real idea of NR_CPUS. Does NR_CPUS represent a number of logical CPUs which can be different from physical amount of CPU?
If yes, then what I wrote above it was about physical CPU and then in context of logical CPUs I don't need a special case when NR_CPUS=1.
~ Oleksii
Re: [PATCH v3 15/34] xen/riscv: introduce atomic.h
Quoted 60 lines · Oleksii
Quoted 50 lines · Jan Beulich
Quoted 45 lines · Oleksii
Quoted 30 lines · Jan Beulich
Quoted 29 lines · Oleksii
Quoted 28 lines · Jan Beulich
Quoted 4 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/fence.h new file +1
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ xen/arch/riscv/include/asm/fence.h line 11
Quoted 10 lines
xen/arch/riscv/include/asm/fence.h new file +10
-0+#ifndef _ASM_RISCV_FENCE_H +#define _ASM_RISCV_FENCE_H + +#ifdef CONFIG_SMP +#define RISCV_ACQUIRE_BARRIER "\tfence r , rw\n" +#define RISCV_RELEASE_BARRIER "\tfence rw, w\n" +#else +#define RISCV_ACQUIRE_BARRIER +#define RISCV_RELEASE_BARRIER +#endif Do you really care about the !SMP case? On x86 at least we stopped
special-
casing that configuration many years ago (the few cases where for
typically
build reasons it matters, usingCONFIG_NR_CPUSis sufficient). If
you
care
about it, there needs to be somewhere you actually #defineCONFIG_SMP.Quoted 5 lines
Quoted 1 line
Can't we use instead of
CONFIG_SMP-CONFIG_NR_CPUS?You can. Question is whether there's a point in doing so. Do you expect people to actually want to run Xen on single-CPU systems? They're generally not overly well suited for virtualization ...
Just to clarify.
Do you mean physically single based CPU?
Then I don't expect to run Xen on such systems and it is not nesessary
to define*_BARRIERin this case. Should we have to add build error notification that we don't support single-CPU systems in this header?Quoted 3 lines
If you are speaking about we have ,let it be, 4 CPUs and only 1 CPU is
currently supported by Xen then it still makes sense.Quoted 9 lines
No, that's still not what I mean. The question is: Is it useful for you
to_specialcase_the NR_CPUS=1 case? Or is it instead simpler to handle
NR_CPUS=1 the same as NR_CPUS>1 (accepting less than ideal performance,
on the basis that in reality nobody's expected to use such in production
anyway)?
Quoted 3 lines
NR_CPUS=1 sometimes is useful for debugging. At least, at the start I used that several times, but ITBO I don't remember when I used that case after SMP support was added and
context_switch()was fixed.
And "sometimes is useful for debugging" warrants introducing special cases? I've not suggested disallowing that configuration. I'm merely asking whether it isn't easier to have the barriers there at all times. Just like on x86 we now leave the LOCK prefixes in place at all times.
Quoted 3 lines
Probably, I misunderstand the real idea of
NR_CPUS. DoesNR_CPUSrepresent a number of logical CPUs which can be different from physical amount of CPU?
No.
Jan
Re: [PATCH v3 15/34] xen/riscv: introduce atomic.h
Quoted 77 lines · Jan Beulich
Quoted 71 lines · Oleksii
Quoted 60 lines · Jan Beulich
Quoted 54 lines · Oleksii
Quoted 35 lines · Jan Beulich
Quoted 34 lines · Oleksii
Quoted 33 lines · Jan Beulich
Quoted 12 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/fence.h new file +6
-0@@ -0,0 +1,13 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +#ifndef _ASM_RISCV_FENCE_H +#define _ASM_RISCV_FENCE_H + +#ifdef CONFIG_SMP +#define RISCV_ACQUIRE_BARRIER "\tfence r ,rw\n"
+#defineRISCV_RELEASE_BARRIER"\tfence rw,
w\n"xen/arch/riscv/include/asm/fence.h
Quoted 4 lines
xen/arch/riscv/include/asm/fence.h new file +4
-0+#else +#define RISCV_ACQUIRE_BARRIER +#define RISCV_RELEASE_BARRIER +#endif Do you really care about the !SMP case? On x86 at least we
stopped
special-
casing that configuration many years ago (the few cases where
for
typically
build reasons it matters, usingCONFIG_NR_CPUSis sufficient). If
you
care
about it, there needs to be somewhere you actually #defineCONFIG_SMP.Quoted 8 lines
Quoted 1 line
Can't we use instead of
CONFIG_SMP-CONFIG_NR_CPUS?You can. Question is whether there's a point in doing so. Do you
expect people to actually want to run Xen on single-CPU systems?
They're generally not overly well suited for virtualization
...Just to clarify.
Do you mean physically single based CPU?
Then I don't expect to run Xen on such systems and it is not nesessary
to define*_BARRIERin this case. Should we have to add build error
notification that we don't support single-CPU systems in this header?Quoted 4 lines
If you are speaking about we have ,let it be, 4 CPUs and only 1 CPU
is
currently supported by Xen then it still makes sense.Quoted 10 lines
No, that's still not what I mean. The question is: Is it useful for
you
to_specialcase_the NR_CPUS=1 case? Or is it instead simpler to handle
NR_CPUS=1 the same as NR_CPUS>1 (accepting less than ideal performance,
on the basis that in reality nobody's expected to use such in production
anyway)?Quoted 4 lines
NR_CPUS=1 sometimes is useful for debugging. At least, at the start I
used that several times, but ITBO I don't remember when I used that case after SMP support was added andcontext_switch()was fixed.
Quoted 5 lines
And "sometimes is useful for debugging" warrants introducing special cases? I've not suggested disallowing that configuration. I'm merely asking whether it isn't easier to have the barriers there at all times. Just like on x86 we now leave the LOCK prefixes in place at all times.
I misunderstood your initial suggestion. In this case we can always have the barriers. I'll drop then #ifdef CONFIG_SMP.
Thanks for clarification.
~ Oleksii
Quoted 9 lines
Quoted 5 lines
Probably, I misunderstand the real idea of
NR_CPUS. DoesNR_CPUSrepresent a number of logical CPUs which can be different from physical
amount of CPU?No.
Jan
PATCH v3 16/34 xen/lib: introduce generic find next bit operations
In reply to Oleksii Kurochkofind-next-bit.c is common for Arm64 and RISC-V64 so it is moved to xen/lib.
---
Changes in V3:
- new patch.
--- xen/arch/riscv/include/asm/fence.h | 11 +- xen/common/Kconfig | 3 + xen/lib/Makefile | 1 + xen/lib/find-next-bit.c | 281 +++++++++++++++++++++++++++++ 4 files changed, 295 insertions(+), 1 deletion(-) create mode 100644 xen/lib/find-next-bit.c
xen/arch/riscv/include/asm/fence.h +10 -1
@@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* SPDX-License-Identifier: GPL-2.0-only */ #ifndef _ASM_RISCV_FENCE_H#define _ASM_RISCV_FENCE_H
@@ -11,3 +11,12 @@#endif #endif /* _ASM_RISCV_FENCE_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
xen/common/Kconfig +3 -0
@@ -47,6 +47,9 @@ config ARCH_MAP_DOMAIN_PAGE config GENERIC_BUG_FRAME bool +config GENERIC_FIND_NEXT_BIT + bool + config HAS_ALTERNATIVE bool
xen/lib/Makefile +1 -0
@@ -3,6 +3,7 @@ obj-$(CONFIG_X86) += x86/ lib-y += bsearch.o lib-y += ctors.o lib-y += ctype.o +lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find-next-bit.o lib-y += list-sort.o lib-y += memchr.o lib-y += memchr_inv.o
xen/lib/find-next-bit.c new file +281 -0
281 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v3 16/34] xen/lib: introduce generic find next bit operations
Quoted 11 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/fence.h +1
-1@@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* SPDX-License-Identifier: GPL-2.0-only */ #ifndef _ASM_RISCV_FENCE_H#define _ASM_RISCV_FENCE_H@@ -11,3 +11,12 @@#endif
xen/arch/riscv/include/asm/fence.h line 22
Quoted 10 lines
xen/arch/riscv/include/asm/fence.h +9
-0#endif /* _ASM_RISCV_FENCE_H */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Surely all of this wants doing in the previous patch, where the header is introduced?
xen/common/Kconfig config ARCH_MAP_DOMAIN_PAGE · line 51
Quoted 8 lines
xen/common/Kconfig +2
-0@@ -47,6 +47,9 @@ config ARCH_MAP_DOMAIN_PAGE config GENERIC_BUG_FRAME bool +config GENERIC_FIND_NEXT_BIT + bool
There's no need for this, as ...
xen/lib/Makefile obj-$(CONFIG_X86) += x86/ · line 6
Quoted 7 lines
xen/lib/Makefile +1
-0@@ -3,6 +3,7 @@ obj-$(CONFIG_X86) += x86/ lib-y += bsearch.o lib-y += ctors.o lib-y += ctype.o +lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find-next-bit.o
... you're moving this to lib/. Or have you encountered any issue with building this uniformly, and you forgot to mention this in the description?
Quoted 274 lines
xen/lib/find-next-bit.c new file +271
-0@@ -0,0 +1,281 @@ +/* find_next_bit.c: fallback find next bit implementation +* +* Copyright (C) 2004 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ +#include <xen/bitops.h> + +#include <asm/byteorder.h> + +#ifndef find_next_bit +/* +* Find the next set bit in a memory region. +*/ +unsigned long find_next_bit (const unsigned long *addr,unsigned long size, +unsigned long offset) +{ +const unsigned long *p = addr +BIT_WORD (offset); +unsigned long result = offset & ~(BITS_PER_LONG -1 ); +unsigned long tmp; + +if (offset >= size) +return size; + size -= result; + offset %=BITS_PER_LONG ; +if (offset) { + tmp = *(p++); + tmp &= (~0UL << offset); +if (size <BITS_PER_LONG ) + goto found_first; +if (tmp) + goto found_middle; + size -=BITS_PER_LONG ; + result +=BITS_PER_LONG ; + } +while (size & ~(BITS_PER_LONG -1 )) { +if ((tmp = *(p++))) + goto found_middle; + result +=BITS_PER_LONG ; + size -=BITS_PER_LONG ; + } +if (!size) +return result; + tmp = *p; + +found_first: + tmp &= (~0UL >> (BITS_PER_LONG - size)); +if (tmp ==0UL )/* Are any bits set? */ +return result + size;/* Nope. */ +found_middle: +return result +__ffs (tmp); +} +EXPORT_SYMBOL (find_next_bit); +#endif + +#ifndef find_next_zero_bit +/* +* This implementation of find_{first,next}_zero_bit was stolen from +* Linus' asm-alpha/bitops.h. +*/ +unsigned long find_next_zero_bit (const unsigned long *addr,unsigned long size, +unsigned long offset) +{ +const unsigned long *p = addr +BIT_WORD (offset); +unsigned long result = offset & ~(BITS_PER_LONG -1 ); +unsigned long tmp; + +if (offset >= size) +return size; + size -= result; + offset %=BITS_PER_LONG ; +if (offset) { + tmp = *(p++); + tmp |= ~0UL >> (BITS_PER_LONG - offset); +if (size <BITS_PER_LONG ) + goto found_first; +if (~tmp) + goto found_middle; + size -=BITS_PER_LONG ; + result +=BITS_PER_LONG ; + } +while (size & ~(BITS_PER_LONG -1 )) { +if (~(tmp = *(p++))) + goto found_middle; + result +=BITS_PER_LONG ; + size -=BITS_PER_LONG ; + } +if (!size) +return result; + tmp = *p; + +found_first: + tmp |= ~0UL << size; +if (tmp == ~0UL )/* Are any bits zero? */ +return result + size;/* Nope. */ +found_middle: +return result +ffz (tmp); +} +EXPORT_SYMBOL (find_next_zero_bit); +#endif + +#ifndef find_first_bit +/* +* Find the first set bit in a memory region. +*/ +unsigned long find_first_bit (const unsigned long *addr,unsigned long size) +{ +const unsigned long *p = addr; +unsigned long result =0 ; +unsigned long tmp; + +while (size & ~(BITS_PER_LONG -1 )) { +if ((tmp = *(p++))) + goto found; + result +=BITS_PER_LONG ; + size -=BITS_PER_LONG ; + } +if (!size) +return result; + + tmp = (*p) & (~0UL >> (BITS_PER_LONG - size)); +if (tmp ==0UL )/* Are any bits set? */ +return result + size;/* Nope. */ +found: +return result +__ffs (tmp); +} +EXPORT_SYMBOL (find_first_bit); +#endif + +#ifndef find_first_zero_bit +/* +* Find the first cleared bit in a memory region. +*/ +unsigned long find_first_zero_bit (const unsigned long *addr,unsigned long size) +{ +const unsigned long *p = addr; +unsigned long result =0 ; +unsigned long tmp; + +while (size & ~(BITS_PER_LONG -1 )) { +if (~(tmp = *(p++))) + goto found; + result +=BITS_PER_LONG ; + size -=BITS_PER_LONG ; + } +if (!size) +return result; + + tmp = (*p) | (~0UL << size); +if (tmp == ~0UL )/* Are any bits zero? */ +return result + size;/* Nope. */ +found: +return result +ffz (tmp); +} +EXPORT_SYMBOL (find_first_zero_bit); +#endif + +#ifdef __BIG_ENDIAN + +/* include/linux/byteorder does not support "unsigned long" type */ +static inline unsigned long ext2_swabp(const unsigned long * x) +{ +#if BITS_PER_LONG == 64 + return (unsigned long) __swab64p((u64 *) x); +#elif BITS_PER_LONG == 32 + return (unsigned long) __swab32p((u32 *) x); +#else +#error BITS_PER_LONG not defined +#endif +} + +/* include/linux/byteorder doesn't support "unsigned long" type */ +static inline unsigned long ext2_swab(const unsigned long y) +{ +#if BITS_PER_LONG == 64 + return (unsigned long) __swab64((u64) y); +#elif BITS_PER_LONG == 32 + return (unsigned long) __swab32((u32) y); +#else +#error BITS_PER_LONG not defined +#endif +} + +#ifndef find_next_zero_bit_le +unsigned long find_next_zero_bit_le(const void *addr, unsigned + long size, unsigned long offset) +{ + const unsigned long *p = addr; + unsigned long result = offset & ~(BITS_PER_LONG - 1); + unsigned long tmp; + + if (offset >= size) + return size; + p += BIT_WORD(offset); + size -= result; + offset &= (BITS_PER_LONG - 1UL); + if (offset) { + tmp = ext2_swabp(p++); + tmp |= (~0UL >> (BITS_PER_LONG - offset)); + if (size < BITS_PER_LONG) + goto found_first; + if (~tmp) + goto found_middle; + size -= BITS_PER_LONG; + result += BITS_PER_LONG; + } + + while (size & ~(BITS_PER_LONG - 1)) { + if (~(tmp = *(p++))) + goto found_middle_swap; + result += BITS_PER_LONG; + size -= BITS_PER_LONG; + } + if (!size) + return result; + tmp = ext2_swabp(p); +found_first: + tmp |= ~0UL << size; + if (tmp == ~0UL) /* Are any bits zero? */ + return result + size; /* Nope. Skip ffz */ +found_middle: + return result + ffz(tmp); + +found_middle_swap: + return result + ffz(ext2_swab(tmp)); +} +EXPORT_SYMBOL(find_next_zero_bit_le); +#endif + +#ifndef find_next_bit_le +unsigned long find_next_bit_le(const void *addr, unsigned + long size, unsigned long offset) +{ + const unsigned long *p = addr; + unsigned long result = offset & ~(BITS_PER_LONG - 1); + unsigned long tmp; + + if (offset >= size) + return size; + p += BIT_WORD(offset); + size -= result; + offset &= (BITS_PER_LONG - 1UL); + if (offset) { + tmp = ext2_swabp(p++); + tmp &= (~0UL << offset); + if (size < BITS_PER_LONG) + goto found_first; + if (tmp) + goto found_middle; + size -= BITS_PER_LONG; + result += BITS_PER_LONG; + } + + while (size & ~(BITS_PER_LONG - 1)) { + tmp = *(p++); + if (tmp) + goto found_middle_swap; + result += BITS_PER_LONG; + size -= BITS_PER_LONG; + } + if (!size) + return result; + tmp = ext2_swabp(p); +found_first: + tmp &= (~0UL >> (BITS_PER_LONG - size)); + if (tmp == 0UL) /* Are any bits set? */ + return result + size; /* Nope. */
xen/lib/find-next-bit.c line 281
Quoted 10 lines
xen/lib/find-next-bit.c new file +10
-0+found_middle: +return result +__ffs (tmp); + +found_middle_swap: +return result +__ffs (ext2_swab (tmp)); +} +EXPORT_SYMBOL (find_next_bit_le); +#endif + +#endif /* __BIG_ENDIAN */
I was going to ask that you convince git to actually present a proper diff, to make visible what changes. But other than the description says you don't really move the file, you copy it. Judging from further titles there's also nowhere you'd make Arm actually use this now generic code.
Jan
Re: [PATCH v3 16/34] xen/lib: introduce generic find next bit operations
Quoted 18 lines · Jan Beulich
Quoted 17 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/fence.h +1
-1@@ -1,4 +1,4 @@ -/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* SPDX-License-Identifier: GPL-2.0-only */ #ifndef _ASM_RISCV_FENCE_H #define _ASM_RISCV_FENCE_Hxen/arch/riscv/include/asm/fence.h +0
-0@@ -11,3 +11,12 @@ #endif
#endif /*_ASM_RISCV_FENCE_H*/xen/arch/riscv/include/asm/fence.h +5
-0+ +/* +* Local variables: +* mode: C +* c-file-style: "BSD"
Quoted 8 lines
Quoted 4 lines
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */Surely all of this wants doing in the previous patch, where the header
is introduced?
Yes, it should be in the previous patch. I'll do the proper rebase.
Quoted 12 lines
xen/common/Kconfig config ARCH_MAP_DOMAIN_PAGE · line 51
Quoted 9 lines
xen/common/Kconfig +0
-0@@ -47,6 +47,9 @@ config ARCH_MAP_DOMAIN_PAGEconfig
GENERIC_BUG_FRAME
boolxen/common/Kconfig +2
-0+config GENERIC_FIND_NEXT_BIT + boolThere's no need for this, as ...
Quoted 11 lines
Quoted 7 lines
xen/lib/Makefile +0
-0@@ -3,6 +3,7 @@ obj-$(CONFIG_X86) += x86/lib-y += bsearch.o
lib-y += ctors.o
lib-y += ctype.o +lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find-next-bit.o... you're moving this to
lib/. Or have you encountered any issue with building this uniformly, and you forgot to mention this in the description?
I didn't check. My intention was to provide opportunity to check if an architecture want to use generic version or not. Otherwise, I expected that we will have multiple definiotion of the funcion.
But considering that they are all defined under #ifdef...#endif we can remove the declaration of the config GENERIC_FIND_NEXT_BIT.
Quoted 292 lines
Quoted 281 lines
xen/lib/find-next-bit.c new file +19
-0@@ -0,0 +1,281 @@ +/* find_next_bit.c: fallback find next bit implementation +* +* Copyright (C) 2004 Red Hat, Inc. All Rights Reserved. +* Written by David Howells ([email protected]) +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License +* as published by the Free Software Foundation; either version +* 2 of the License, or (at your option) any later version. +*/ +#include <xen/bitops.h> + +#include <asm/byteorder.h> + +#ifndef find_next_bit +/* +* Find the next set bit in a memory region. +*/ +unsigned long find_next_bit(const unsigned long *addr, unsignedlong size,
xen/lib/find-next-bit.c new file +43
-0+ unsigned long offset) +{ +const unsigned long *p = addr +BIT_WORD (offset); +unsigned long result = offset & ~(BITS_PER_LONG -1 ); +unsigned long tmp; + +if (offset >= size) +return size; + size -= result; + offset %=BITS_PER_LONG ; +if (offset) { + tmp = *(p++); + tmp &= (~0UL << offset); +if (size <BITS_PER_LONG ) + goto found_first; +if (tmp) + goto found_middle; + size -=BITS_PER_LONG ; + result +=BITS_PER_LONG ; + } +while (size & ~(BITS_PER_LONG -1 )) { +if ((tmp = *(p++))) + goto found_middle; + result +=BITS_PER_LONG ; + size -=BITS_PER_LONG ; + } +if (!size) +return result; + tmp = *p; + +found_first: + tmp &= (~0UL >> (BITS_PER_LONG - size)); +if (tmp ==0UL )/* Are any bits set? */ +return result + size;/* Nope. */ +found_middle: +return result +__ffs (tmp); +} +EXPORT_SYMBOL (find_next_bit); +#endif + +#ifndef find_next_zero_bit +/* +* This implementation of find_{first,next}_zero_bit was stolen from
+ * Linus'asm-alpha/bitops.h.
+ */
+unsigned long find_next_zero_bit(const unsigned long *addr, unsigned long size,xen/lib/find-next-bit.c new file +45
-0+ unsigned long offset) +{ +const unsigned long *p = addr +BIT_WORD (offset); +unsigned long result = offset & ~(BITS_PER_LONG -1 ); +unsigned long tmp; + +if (offset >= size) +return size; + size -= result; + offset %=BITS_PER_LONG ; +if (offset) { + tmp = *(p++); + tmp |= ~0UL >> (BITS_PER_LONG - offset); +if (size <BITS_PER_LONG ) + goto found_first; +if (~tmp) + goto found_middle; + size -=BITS_PER_LONG ; + result +=BITS_PER_LONG ; + } +while (size & ~(BITS_PER_LONG -1 )) { +if (~(tmp = *(p++))) + goto found_middle; + result +=BITS_PER_LONG ; + size -=BITS_PER_LONG ; + } +if (!size) +return result; + tmp = *p; + +found_first: + tmp |= ~0UL << size; +if (tmp == ~0UL )/* Are any bits zero? */ +return result + size;/* Nope. */ +found_middle: +return result +ffz (tmp); +} +EXPORT_SYMBOL (find_next_zero_bit); +#endif + +#ifndef find_first_bit +/* +* Find the first set bit in a memory region. +*/ +unsigned long find_first_bit(const unsigned long *addr, unsignedlong size)
xen/lib/find-next-bit.c new file +28
-0+{ +const unsigned long *p = addr; +unsigned long result =0 ; +unsigned long tmp; + +while (size & ~(BITS_PER_LONG -1 )) { +if ((tmp = *(p++))) + goto found; + result +=BITS_PER_LONG ; + size -=BITS_PER_LONG ; + } +if (!size) +return result; + + tmp = (*p) & (~0UL >> (BITS_PER_LONG - size)); +if (tmp ==0UL )/* Are any bits set? */ +return result + size;/* Nope. */ +found: +return result +__ffs (tmp); +} +EXPORT_SYMBOL (find_first_bit); +#endif + +#ifndef find_first_zero_bit +/* +* Find the first cleared bit in a memory region. +*/ +unsigned long find_first_zero_bit(const unsigned long *addr,unsigned long size)
xen/lib/find-next-bit.c new file +26
-0+{ +const unsigned long *p = addr; +unsigned long result =0 ; +unsigned long tmp; + +while (size & ~(BITS_PER_LONG -1 )) { +if (~(tmp = *(p++))) + goto found; + result +=BITS_PER_LONG ; + size -=BITS_PER_LONG ; + } +if (!size) +return result; + + tmp = (*p) | (~0UL << size); +if (tmp == ~0UL )/* Are any bits zero? */ +return result + size;/* Nope. */ +found: +return result +ffz (tmp); +} +EXPORT_SYMBOL (find_first_zero_bit); +#endif + +#ifdef __BIG_ENDIAN + +/* include/linux/byteorder does not support "unsigned long" type */
xen/lib/find-next-bit.c new file +107
-0+static inline unsigned long ext2_swabp (const unsigned long * x) +{ +#if BITS_PER_LONG ==64 +return (unsigned long )__swab64p ((u64 *) x); +#elif BITS_PER_LONG ==32 +return (unsigned long )__swab32p ((u32 *) x); +#else +#error BITS_PER_LONG not defined +#endif +} + +/* include/linux/byteorder doesn't support "unsigned long" type */ +static inline unsigned long ext2_swab (const unsigned long y) +{ +#if BITS_PER_LONG ==64 +return (unsigned long )__swab64 ((u64 ) y); +#elif BITS_PER_LONG ==32 +return (unsigned long )__swab32 ((u32 ) y); +#else +#error BITS_PER_LONG not defined +#endif +} + +#ifndef find_next_zero_bit_le +unsigned long find_next_zero_bit_le (const void *addr,unsigned +long size,unsigned long offset) +{ +const unsigned long *p = addr; +unsigned long result = offset & ~(BITS_PER_LONG -1 ); +unsigned long tmp; + +if (offset >= size) +return size; + p +=BIT_WORD (offset); + size -= result; + offset &= (BITS_PER_LONG -1UL ); +if (offset) { + tmp =ext2_swabp (p++); + tmp |= (~0UL >> (BITS_PER_LONG - offset)); +if (size <BITS_PER_LONG ) + goto found_first; +if (~tmp) + goto found_middle; + size -=BITS_PER_LONG ; + result +=BITS_PER_LONG ; + } + +while (size & ~(BITS_PER_LONG -1 )) { +if (~(tmp = *(p++))) + goto found_middle_swap; + result +=BITS_PER_LONG ; + size -=BITS_PER_LONG ; + } +if (!size) +return result; + tmp =ext2_swabp (p); +found_first: + tmp |= ~0UL << size; +if (tmp == ~0UL )/* Are any bits zero? */ +return result + size;/* Nope. Skip ffz */ +found_middle: +return result +ffz (tmp); + +found_middle_swap: +return result +ffz (ext2_swab (tmp)); +} +EXPORT_SYMBOL (find_next_zero_bit_le); +#endif + +#ifndef find_next_bit_le +unsigned long find_next_bit_le (const void *addr,unsigned +long size,unsigned long offset) +{ +const unsigned long *p = addr; +unsigned long result = offset & ~(BITS_PER_LONG -1 ); +unsigned long tmp; + +if (offset >= size) +return size; + p +=BIT_WORD (offset); + size -= result; + offset &= (BITS_PER_LONG -1UL ); +if (offset) { + tmp =ext2_swabp (p++); + tmp &= (~0UL << offset); +if (size <BITS_PER_LONG ) + goto found_first; +if (tmp) + goto found_middle; + size -=BITS_PER_LONG ; + result +=BITS_PER_LONG ; + } + +while (size & ~(BITS_PER_LONG -1 )) { + tmp = *(p++); +if (tmp) + goto found_middle_swap; + result +=BITS_PER_LONG ; + size -=BITS_PER_LONG ; + } +if (!size) +return result; + tmp =ext2_swabp (p); +found_first: + tmp &= (~0UL >> (BITS_PER_LONG - size)); +if (tmp ==0UL )/* Are any bits set? */ +return result + size;/* Nope. */ xen/lib/find-next-bit.c line 281
Quoted 10 lines
xen/lib/find-next-bit.c new file +10
-0+found_middle: +return result +__ffs (tmp); + +found_middle_swap: +return result +__ffs (ext2_swab (tmp)); +} +EXPORT_SYMBOL (find_next_bit_le); +#endif + +#endif /* __BIG_ENDIAN */
Quoted 7 lines
I was going to ask that you convince git to actually present a proper diff, to make visible what changes. But other than the description says
you don't really move the file, you copy it. Judging from further titles
there's also nowhere you'd make Arm actually use this now generic code.
I wanted to do it separately, outside this patch series to simplify review and not have Arm specific changes in RISC-V patch series.
Regarding a proper diff, you would like me to make git shows that it was copy from Arm and it is not newly created file. Am I understand you correctly?
~ Oleksii
Re: [PATCH v3 16/34] xen/lib: introduce generic find next bit operations
Quoted 24 lines · Oleksii
Quoted 12 lines · Jan Beulich
xen/common/Kconfig config ARCH_MAP_DOMAIN_PAGE · line 51
Quoted 8 lines · Oleksii Kurochko
xen/common/Kconfig +0
-0@@ -47,6 +47,9 @@ config ARCH_MAP_DOMAIN_PAGEconfig
GENERIC_BUG_FRAME
boolxen/common/Kconfig +2
-0+config GENERIC_FIND_NEXT_BIT + boolThere's no need for this, as ...
Quoted 11 lines
Quoted 7 lines
xen/lib/Makefile +0
-0@@ -3,6 +3,7 @@ obj-$(CONFIG_X86) += x86/lib-y += bsearch.o
lib-y += ctors.o
lib-y += ctype.o +lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find-next-bit.o... you're moving this to
lib/. Or have you encountered any issue with building this uniformly, and you forgot to mention this in the description?
Quoted 6 lines
I didn't check. My intention was to provide opportunity to check if an architecture want to use generic version or not. Otherwise, I expected that we will have multiple definiotion of the funcion.
But considering that they are all defined under #ifdef...#endif we can remove the declaration of the config
GENERIC_FIND_NEXT_BIT.
What #ifdef / #endif would matter here? Whats in lib/ is intended to be generic anyway. And what is in the resulting lib.a won't be used by an arch if it has an arch-specific implementation. Problems could arise if an arch had an inline function colliding with the out-of-line one. But that's about the old case where I could see a need to make the building of one of the objects conditional. And you'll note that withing this Makefile there are pretty few conditionals.
Quoted 11 lines
Quoted 11 lines
xen/lib/find-next-bit.c
Quoted 3 lines
xen/lib/find-next-bit.c new file +0
-0I was going to ask that you convince git to actually present a proper diff, to make visible what changes. But other than the description says
you don't really move the file, you copy it. Judging from further titles
there's also nowhere you'd make Arm actually use this now generic code.
Quoted 2 lines
I wanted to do it separately, outside this patch series to simplify review and not have Arm specific changes in RISC-V patch series.
Then do it the other way around: Make a separate _prereq_ change truly moving the file.
Quoted 3 lines
Regarding a proper diff, you would like me to make git shows that it was copy from Arm and it is not newly created file. Am I understand you correctly?
Not quite, I think. Git has move detection (and we've seen that in action in other patches of yours). So when truly moving a file, what (if anything) is changed is easily visible.
Jan
Re: [PATCH v3 16/34] xen/lib: introduce generic find next bit operations
Quoted 35 lines · Jan Beulich
Quoted 30 lines · Oleksii
Quoted 12 lines · Jan Beulich
xen/common/Kconfig config ARCH_MAP_DOMAIN_PAGE · line 51
Quoted 8 lines · Oleksii Kurochko
xen/common/Kconfig +0
-0@@ -47,6 +47,9 @@ config ARCH_MAP_DOMAIN_PAGEconfig
GENERIC_BUG_FRAME
boolxen/common/Kconfig +2
-0+config GENERIC_FIND_NEXT_BIT + boolThere's no need for this, as ...
Quoted 11 lines
Quoted 7 lines
xen/lib/Makefile +0
-0@@ -3,6 +3,7 @@ obj-$(CONFIG_X86) += x86/lib-y += bsearch.o
lib-y += ctors.o
lib-y += ctype.o +lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find-next-bit.o... you're moving this to
lib/. Or have you encountered any issue with building this uniformly, and you forgot to mention this in the description?I didn't check. My intention was to provide opportunity to check if an
architecture want to use generic version or not. Otherwise, I expected
that we will have multiple definiotion of the funcion.Quoted 3 lines
But considering that they are all defined under #ifdef...#endif we can
remove the declaration of the configGENERIC_FIND_NEXT_BIT.
Quoted 5 lines
What #ifdef / #endif would matter here? Whats in
lib/is intended to be
generic anyway. And what is in the resulting lib.a won't be used by an
arch if it has an arch-specific implementation.
If what is implemented in lib.a won't be used by an arch if it has an arch-specific implementation then, for sure, I have to drop CONFIG_GENERIC_FIND_NEXT_BIT.
But I am not really understand if lib.a is linked with Xen, then it should be an issue then if some arch implement find-next-bit function we will have to multiple definitions ( one in lib.a and one arch specific ). Probably, I have to look at how it is done.
Quoted 7 lines
Problems could arise if
an arch had an inline function colliding with the out-of-line one. But
that's about the old case where I could see a need to make the building
of one of the objects conditional. And you'll note that withing thisMakefilethere are pretty few conditionals.
Could you please clarify What does it mean "out-of-line" ?
Quoted 14 lines
Quoted 14 lines
Quoted 14 lines
xen/lib/find-next-bit.c
Quoted 4 lines
xen/lib/find-next-bit.c new file +0
-0I was going to ask that you convince git to actually present a proper
diff, to make visible what changes. But other than the description
says
you don't really move the file, you copy it. Judging from further titles
there's also nowhere you'd make Arm actually use this now generic code.
Quoted 6 lines
Quoted 2 lines
I wanted to do it separately, outside this patch series to simplify review and not have Arm specific changes in RISC-V patch series.
Then do it the other way around: Make a separate _prereq_ change truly
moving the file.
So this one patch should be separated by 2? One which moves find-next- bit.c from Arm to xen/lib, and second where xen/lib/Makefile is updated.
Quoted 10 lines
Quoted 6 lines
Regarding a proper diff, you would like me to make git shows that it
was copy from Arm and it is not newly created file. Am I understand you
correctly?Not quite, I think. Git has move detection (and we've seen that in action in other patches of yours). So when truly moving a file, what (if anything) is changed is easily visible.
I think I am still a little bit confused. But I think the answer on my question above can clarify that.
~ Oleksii
Re: [PATCH v3 16/34] xen/lib: introduce generic find next bit operations
Quoted 41 lines · Oleksii
Quoted 35 lines · Jan Beulich
Quoted 30 lines · Oleksii
Quoted 12 lines · Jan Beulich
xen/common/Kconfig config ARCH_MAP_DOMAIN_PAGE · line 51
Quoted 8 lines · Oleksii Kurochko
xen/common/Kconfig +0
-0@@ -47,6 +47,9 @@ config ARCH_MAP_DOMAIN_PAGEconfig
GENERIC_BUG_FRAME
boolxen/common/Kconfig +2
-0+config GENERIC_FIND_NEXT_BIT + boolThere's no need for this, as ...
Quoted 11 lines
Quoted 7 lines
xen/lib/Makefile +0
-0@@ -3,6 +3,7 @@ obj-$(CONFIG_X86) += x86/lib-y += bsearch.o
lib-y += ctors.o
lib-y += ctype.o +lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find-next-bit.o... you're moving this to
lib/. Or have you encountered any issue with building this uniformly, and you forgot to mention this in the description?I didn't check. My intention was to provide opportunity to check if an
architecture want to use generic version or not. Otherwise, I expected
that we will have multiple definiotion of the funcion.Quoted 3 lines
But considering that they are all defined under #ifdef...#endif we can
remove the declaration of the configGENERIC_FIND_NEXT_BIT.Quoted 5 lines
What #ifdef / #endif would matter here? Whats in
lib/is intended to be
generic anyway. And what is in the resulting lib.a won't be used by an
arch if it has an arch-specific implementation.
Quoted 7 lines
If what is implemented in lib.a won't be used by an arch if it has an arch-specific implementation then, for sure, I have to drop
CONFIG_GENERIC_FIND_NEXT_BIT.
But I am not really understand if lib.a is linked with Xen, then it should be an issue then if some arch implement find-next-bit function we will have to multiple definitions ( one in lib.a and one arch specific ). Probably, I have to look at how it is done.
You're aware how linking works? Objects are pulled out of archives only if there's no other definition for a to-be-resolved symbol provided by a particular object in the archive.
Quoted 8 lines
Quoted 7 lines
Problems could arise if
an arch had an inline function colliding with the out-of-line one. But
that's about the old case where I could see a need to make the building
of one of the objects conditional. And you'll note that withing thisMakefilethere are pretty few conditionals.Could you please clarify What does it mean "out-of-line" ?
"not inline"
Quoted 16 lines
Quoted 16 lines
Quoted 15 lines
Quoted 5 lines
xen/lib/find-next-bit.c
Quoted 3 lines
xen/lib/find-next-bit.c new file +0
-0I was going to ask that you convince git to actually present a
Quoted 8 lines
proper
diff, to make visible what changes. But other than the description
says
you don't really move the file, you copy it. Judging from further titles
there's also nowhere you'd make Arm actually use this now generic code.I wanted to do it separately, outside this patch series to simplify review and not have Arm specific changes in RISC-V patch series.
Quoted 6 lines
Quoted 3 lines
Then do it the other way around: Make a separate _prereq_ change truly
moving the file.So this one patch should be separated by 2? One which moves find-next-
bit.cfrom Arm to xen/lib, and second where xen/lib/Makefile is updated.
No, that would break the Arm build. I suggested breaking out this patch from the series, and then doing what the description says:
Actually move the file. I don't think I suggested splitting the patch. Even the breaking out of the series was only because you said "I wanted to do it separately, outside this patch series".
Jan
Re: [PATCH v3 16/34] xen/lib: introduce generic find next bit operations
Quoted 58 lines · Jan Beulich
Quoted 47 lines · Oleksii
Quoted 39 lines · Jan Beulich
Quoted 33 lines · Oleksii
Quoted 12 lines · Jan Beulich
xen/common/Kconfig config ARCH_MAP_DOMAIN_PAGE · line 51
Quoted 8 lines · Oleksii Kurochko
xen/common/Kconfig +0
-0@@ -47,6 +47,9 @@ config ARCH_MAP_DOMAIN_PAGEconfig
GENERIC_BUG_FRAME
boolxen/common/Kconfig +2
-0+config GENERIC_FIND_NEXT_BIT + boolThere's no need for this, as ...
Quoted 13 lines
Quoted 7 lines
xen/lib/Makefile +0
-0@@ -3,6 +3,7 @@ obj-$(CONFIG_X86) += x86/lib-y += bsearch.o
lib-y += ctors.o
lib-y += ctype.o +lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find-next-bit.o... you're moving this to
lib/. Or have you encountered any issue
with building this uniformly, and you forgot to mention this in
the description?I didn't check. My intention was to provide opportunity to check if
an
architecture want to use generic version or not. Otherwise, I expected
that we will have multiple definiotion of the funcion.Quoted 4 lines
But considering that they are all defined under #ifdef...#endif we
can
remove the declaration of the configGENERIC_FIND_NEXT_BIT.Quoted 7 lines
What #ifdef / #endif would matter here? Whats in
lib/is intended to
be
generic anyway. And what is in the resulting lib.a won't be used by
an
arch if it has an arch-specific implementation.Quoted 9 lines
If what is implemented in lib.a won't be used by an arch if it has an
arch-specific implementation then, for sure, I have to dropCONFIG_GENERIC_FIND_NEXT_BIT.
But I am not really understand if lib.a is linked with Xen, then it should be an issue then if some arch implement find-next-bit function
we will have to multiple definitions ( one in lib.a and one arch specific ). Probably, I have to look at how it is done.
Quoted 5 lines
You're aware how linking works? Objects are pulled out of archives only
if there's no other definition for a to-be-resolved symbol provided by
a particular object in the archive.
I wasn't aware about the case of the archive. Thanks for the explanation.
Quoted 43 lines
Quoted 11 lines
Quoted 10 lines
Problems could arise if
an arch had an inline function colliding with the out-of-line one.
But
that's about the old case where I could see a need to make the building
of one of the objects conditional. And you'll note that withing thisMakefilethere are pretty few conditionals.Could you please clarify What does it mean "out-of-line" ?
"not inline"
Quoted 21 lines
Quoted 21 lines
Quoted 20 lines
Quoted 8 lines
xen/lib/find-next-bit.c
Quoted 3 lines
xen/lib/find-next-bit.c new file +0
-0I was going to ask that you convince git to actually present a
proper
diff, to make visible what changes. But other than theQuoted 8 lines
description
says
you don't really move the file, you copy it. Judging from further
titles
there's also nowhere you'd make Arm actually use this now generic
code.I wanted to do it separately, outside this patch series to simplify
review and not have Arm specific changes in RISC-V patch series.Quoted 7 lines
Quoted 3 lines
Then do it the other way around: Make a separate _prereq_ change truly
moving the file.So this one patch should be separated by 2? One which moves find- next-
bit.cfrom Arm to xen/lib, and second where xen/lib/Makefile is updated.
Quoted 5 lines
No, that would break the Arm build. I suggested breaking out this patch from the series, and then doing what the description says:
Actually move the file. I don't think I suggested splitting the patch. Even the breaking out of the series was only because you said "I wanted to do it separately, outside this patch series".
What I meant was that I would like to have a patch which introduces generic version of find-next-bit in the current patch series and provide a separate patch outside of the current patch series which switches Arm to use generic version.
~ Oleksii
Re: [PATCH v3 16/34] xen/lib: introduce generic find next bit operations
Quoted 40 lines · Oleksii
Quoted 34 lines · Jan Beulich
Quoted 25 lines · Oleksii
Quoted 24 lines · Jan Beulich
Quoted 22 lines · Oleksii
Quoted 17 lines · Jan Beulich
xen/lib/find-next-bit.c
Quoted 3 lines · Oleksii Kurochko
xen/lib/find-next-bit.c new file +0
-0I was going to ask that you convince git to actually present a
proper
diff, to make visible what changes. But other than the description
says
you don't really move the file, you copy it. Judging from further
titles
there's also nowhere you'd make Arm actually use this now generic
code.I wanted to do it separately, outside this patch series to simplify
review and not have Arm specific changes in RISC-V patch series.Quoted 7 lines
Quoted 3 lines
Then do it the other way around: Make a separate _prereq_ change truly
moving the file.So this one patch should be separated by 2? One which moves find- next-
bit.cfrom Arm to xen/lib, and second where xen/lib/Makefile is updated.Quoted 5 lines
No, that would break the Arm build. I suggested breaking out this patch from the series, and then doing what the description says:
Actually move the file. I don't think I suggested splitting the patch. Even the breaking out of the series was only because you said "I wanted to do it separately, outside this patch series".
Quoted 4 lines
What I meant was that I would like to have a patch which introduces generic version of find-next-bit in the current patch series and provide a separate patch outside of the current patch series which switches Arm to use generic version.
I understand that this is what you meant. Yet I don't like the duplication of code, even if it's only temporary. The more that iirc git can show proper history for moved files, while there'll be a disconnect when you first add a 2nd copy and later purge the original. If you want this change separate from the series - fine. But then, as said, please as a prereq patch.
Jan
Re: [PATCH v3 16/34] xen/lib: introduce generic find next bit operations
In reply to Jan BeulichQuoted 35 lines · Jan Beulich
Quoted 30 lines · Oleksii
Quoted 12 lines · Jan Beulich
xen/common/Kconfig config ARCH_MAP_DOMAIN_PAGE · line 51
Quoted 8 lines · Oleksii Kurochko
xen/common/Kconfig +0
-0@@ -47,6 +47,9 @@ config ARCH_MAP_DOMAIN_PAGEconfig
GENERIC_BUG_FRAME
boolxen/common/Kconfig +2
-0+config GENERIC_FIND_NEXT_BIT + boolThere's no need for this, as ...
Quoted 11 lines
Quoted 7 lines
xen/lib/Makefile +0
-0@@ -3,6 +3,7 @@ obj-$(CONFIG_X86) += x86/lib-y += bsearch.o
lib-y += ctors.o
lib-y += ctype.o +lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find-next-bit.o... you're moving this to
lib/. Or have you encountered any issue with building this uniformly, and you forgot to mention this in the description?I didn't check. My intention was to provide opportunity to check if an
architecture want to use generic version or not. Otherwise, I expected
that we will have multiple definiotion of the funcion.Quoted 3 lines
But considering that they are all defined under #ifdef...#endif we can
remove the declaration of the configGENERIC_FIND_NEXT_BIT.
Quoted 12 lines
What #ifdef / #endif would matter here? Whats in
lib/is intended to be
generic anyway. And what is in the resulting lib.a won't be used by an
arch if it has an arch-specific implementation. Problems could arise if
an arch had an inline function colliding with the out-of-line one. But
that's about the old case where I could see a need to make the building
of one of the objects conditional. And you'll note that withing thisMakefilethere are pretty few conditionals.
We will have such issue with PPC:
...
static inline unsigned long find_next_bit(const unsigned long *addr,
unsigned long size, unsigned long offset)
...
It looks like an introduction of new config for find_next_bit is needed.
Does a better option exist? Would making find_next_bit non inline non inline for PPC better?
~ Oleksii
Re: [PATCH v3 16/34] xen/lib: introduce generic find next bit operations
Quoted 55 lines · Oleksii
Quoted 35 lines · Jan Beulich
Quoted 30 lines · Oleksii
Quoted 12 lines · Jan Beulich
xen/common/Kconfig config ARCH_MAP_DOMAIN_PAGE · line 51
Quoted 8 lines · Oleksii Kurochko
xen/common/Kconfig +0
-0@@ -47,6 +47,9 @@ config ARCH_MAP_DOMAIN_PAGEconfig
GENERIC_BUG_FRAME
boolxen/common/Kconfig +2
-0+config GENERIC_FIND_NEXT_BIT + boolThere's no need for this, as ...
Quoted 11 lines
Quoted 7 lines
xen/lib/Makefile +0
-0@@ -3,6 +3,7 @@ obj-$(CONFIG_X86) += x86/lib-y += bsearch.o
lib-y += ctors.o
lib-y += ctype.o +lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find-next-bit.o... you're moving this to
lib/. Or have you encountered any issue with building this uniformly, and you forgot to mention this in the description?I didn't check. My intention was to provide opportunity to check if an
architecture want to use generic version or not. Otherwise, I expected
that we will have multiple definiotion of the funcion.Quoted 3 lines
But considering that they are all defined under #ifdef...#endif we can
remove the declaration of the configGENERIC_FIND_NEXT_BIT.Quoted 12 lines
What #ifdef / #endif would matter here? Whats in
lib/is intended to be
generic anyway. And what is in the resulting lib.a won't be used by an
arch if it has an arch-specific implementation. Problems could arise if
an arch had an inline function colliding with the out-of-line one. But
that's about the old case where I could see a need to make the building
of one of the objects conditional. And you'll note that withing thisMakefilethere are pretty few conditionals.We will have such issue with PPC:
...
static inline unsigned long find_next_bit(const unsigned long *addr,
unsigned long size, unsigned long offset)
...
Quoted 5 lines
It looks like an introduction of new config for
find_next_bitis needed.Does a better option exist? Would making
find_next_bitnon inline non inline for PPC better?
Isn't that generic code anyway? If so, that also wants replacing by the generic library function(s). Shawn - I have to admit I have a hard time seeing why this was introduced as inline functions in the first place.
Jan
Re: [PATCH v3 16/34] xen/lib: introduce generic find next bit operations
Quoted 69 lines · Jan Beulich
Quoted 68 lines · Oleksii
Quoted 48 lines · Jan Beulich
Quoted 33 lines · Oleksii
Quoted 12 lines · Jan Beulich
xen/common/Kconfig config ARCH_MAP_DOMAIN_PAGE · line 51
Quoted 8 lines · Oleksii Kurochko
xen/common/Kconfig +0
-0@@ -47,6 +47,9 @@ config ARCH_MAP_DOMAIN_PAGEconfig
GENERIC_BUG_FRAME
boolxen/common/Kconfig +2
-0+config GENERIC_FIND_NEXT_BIT + boolThere's no need for this, as ...
Quoted 13 lines
Quoted 7 lines
xen/lib/Makefile +0
-0@@ -3,6 +3,7 @@ obj-$(CONFIG_X86) += x86/lib-y += bsearch.o
lib-y += ctors.o
lib-y += ctype.o +lib-$(CONFIG_GENERIC_FIND_NEXT_BIT) += find-next-bit.o... you're moving this to
lib/. Or have you encountered any issue
with building this uniformly, and you forgot to mention this in
the description?I didn't check. My intention was to provide opportunity to check if
an
architecture want to use generic version or not. Otherwise, I expected
that we will have multiple definiotion of the funcion.Quoted 4 lines
But considering that they are all defined under #ifdef...#endif we
can
remove the declaration of the configGENERIC_FIND_NEXT_BIT.What #ifdef / #endif would matter here? Whats in
lib/is intended to
be
generic anyway. And what is in the resulting lib.a won't be used by
an
arch if it has an arch-specific implementation. Problems could arise
ifQuoted 8 lines
an arch had an inline function colliding with the out-of-line one.
But
that's about the old case where I could see a need to make the building
of one of the objects conditional. And you'll note that withing thisMakefilethere are pretty few conditionals.We will have such issue with PPC:
...
static inline unsigned long find_next_bit(const unsigned long *addr,
unsigned long size, unsigned long offset)
...It looks like an introduction of new config for
find_next_bitis needed.
Quoted 8 lines
Quoted 3 lines
Does a better option exist? Would making
find_next_bitnon inline non
inline for PPC better?Isn't that generic code anyway? If so, that also wants replacing by the generic library function(s). Shawn - I have to admit I have a hard time seeing why this was introduced as inline functions in the first place.
You are right, it is generic one too. I'll replace it too.
~ Oleksii
PATCH v3 17/34 xen/riscv: add compilation of generic find-next-bit.c
In reply to Oleksii Kurochko---
Changes in V3:
- new patch
--- xen/arch/riscv/Kconfig | 1 + xen/arch/riscv/configs/tiny64_defconfig | 1 + 2 files changed, 2 insertions(+)
xen/arch/riscv/Kconfig +1 -0
@@ -4,6 +4,7 @@ config RISCV config RISCV_64 def_bool y select 64BIT + select GENERIC_FIND_NEXT_BIT config ARCH_DEFCONFIG string
xen/arch/riscv/configs/tiny64_defconfig +1 -0
@@ -29,3 +29,4 @@ CONFIG_RISCV_64=y CONFIG_DEBUG=y CONFIG_DEBUG_INFO=y CONFIG_EXPERT=y +CONFIG_GENERIC_FIND_NEXT_BIT=y
Signature · 1 line
2.43.0
PATCH v3 18/34 xen/riscv: introduce domain.h
In reply to Oleksii Kurochko---
Changes in V3:
- add SPDX
- add Acked-by: Jan Beulich <[email protected]>
- update the commit message
---
Changes in V2:
- Nothing changed. Only rebase.
--- xen/arch/riscv/include/asm/domain.h | 53 +++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 xen/arch/riscv/include/asm/domain.h
xen/arch/riscv/include/asm/domain.h new file +53 -0
@@ -0,0 +1,53 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_RISCV_DOMAIN_H__ +#define __ASM_RISCV_DOMAIN_H__ + +#include <xen/xmalloc.h> +#include <public/hvm/params.h> + +struct hvm_domain +{ +uint64_t params[HVM_NR_PARAMS ]; +}; + +#define is_domain_direct_mapped (d) ((void)(d), 0) + +struct arch_vcpu_io { +}; + +struct arch_vcpu { +}; + +struct arch_domain { +struct hvm_domain hvm; +}; + +#include <xen/sched.h> + +static inline struct vcpu_guest_context *alloc_vcpu_guest_context (void ) +{ + return xmalloc(struct vcpu_guest_context); +} + +static inline void free_vcpu_guest_context (struct vcpu_guest_context *vgc) +{ +xfree (vgc); +} + +struct guest_memory_policy {}; +static inline void update_guest_memory_policy (struct vcpu *v, +struct guest_memory_policy *gmp) +{} + +static inline void arch_vcpu_block (struct vcpu *v) {} + +#endif /* __ASM_RISCV_DOMAIN_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
2.43.0
PATCH v3 19/34 xen/riscv: introduce guest_access.h
In reply to Oleksii KurochkoAll necessary dummiy implementation of functions in this header will be introduced in stubs.c
---
Changes in V3:
- remove unnessary inclusion of types.h header.
- drop copy_to_guest_phys. it isn't needed yet
- add SPDX
- add comment above guest_handle_okay()
- update the commit message
---
Changes in V2:
- change xen/mm.h to xen/types.h
--- xen/arch/riscv/include/asm/guest_access.h | 29 +++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 xen/arch/riscv/include/asm/guest_access.h
xen/arch/riscv/include/asm/guest_access.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_RISCV_GUEST_ACCESS_H__ +#define __ASM_RISCV_GUEST_ACCESS_H__ + +unsigned long raw_copy_to_guest (void *to,const void *from,unsigned len); +unsigned long raw_copy_from_guest (void *to,const void *from,unsigned len); +unsigned long raw_clear_guest (void *to,unsigned int len); + +#define __raw_copy_to_guest raw_copy_to_guest +#define __raw_copy_from_guest raw_copy_from_guest +#define __raw_clear_guest raw_clear_guest + +/* +* Pre-validate a guest handle. +* Allows use of faster __copy_* functions. +*/ +/* All RISCV guests are paging mode external and hence safe */ +#define guest_handle_okay (hnd, nr) (1) +#define guest_handle_subrange_okay (hnd, first, last) (1) + +#endif /* __ASM_RISCV_GUEST_ACCESS_H__ */ +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
2.43.0
Re: [PATCH v3 19/34] xen/riscv: introduce guest_access.h
Quoted 4 lines · Oleksii Kurochko
All necessary dummiy implementation of functions in this header will be introduced in
stubs.cSigned-off-by Oleksii Kurochko <[email protected]>
PATCH v3 20/34 xen/riscv: introduce irq.h
In reply to Oleksii Kurochko---
Changes in V3:
- add SPDX
- remove all that was wraped to HAS_DEVICETREE_... as for RISC-V it is going to be always selected.
- update the commit message
---
Changes in V2:
- add ifdef CONFIG_HAS_DEVICE_TREE for things that shouldn't be
in case !CONFIG_HAS_DEVICE_TREE
- use proper includes.
--- xen/arch/riscv/include/asm/irq.h | 37 ++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 xen/arch/riscv/include/asm/irq.h
xen/arch/riscv/include/asm/irq.h new file +37 -0
@@ -0,0 +1,37 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_RISCV_IRQ_H__ +#define __ASM_RISCV_IRQ_H__ + +#include <xen/bug.h> + +/* TODO */ +#define nr_irqs 0U +#define nr_static_irqs 0 +#define arch_hwdom_irqs (domid) 0U + +#define domain_pirq_to_irq (d, pirq) (pirq) + +#define arch_evtchn_bind_pirq (d, pirq) ((void)((d) + (pirq))) + +struct arch_pirq { +}; + +struct arch_irq_desc { +unsigned int type; +}; + +static inline void arch_move_irqs (struct vcpu *v) +{ +BUG (); +} + +#endif /* __ASM_RISCV_IRQ_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
2.43.0
Re: [PATCH v3 20/34] xen/riscv: introduce irq.h
xen/arch/riscv/include/asm/irq.h line 26
Quoted 4 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/irq.h new file +4
-0+static inline void arch_move_irqs (struct vcpu *v) +{ +BUG (); +}
As I think you said you're doing the conversion already - with this becoming the "canonical" BUG_ON("unimplemented"):
Jan
Re: [PATCH v3 20/34] xen/riscv: introduce irq.h
Quoted 9 lines · Jan Beulich
xen/arch/riscv/include/asm/irq.h line 26
Quoted 4 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/irq.h new file +4
-0+static inline void arch_move_irqs (struct vcpu *v) +{ + BUG(); +}As I think you said you're doing the conversion already - with this becoming the "canonical"
BUG_ON("unimplemented"):Acked-by Jan Beulich <[email protected]>
Missed that, I'll update that in my next patch version.
Thanks.
~ Oleksii
PATCH v3 21/34 xen/riscv: introduce p2m.h
In reply to Oleksii Kurochko---
Changes in V3:
- add SPDX
- drop unneeded for now p2m types.
- return false in all functions implemented with BUG() inside.
- update the commit message
---
Changes in V2:
- Nothing changed. Only rebase.
--- xen/arch/ppc/include/asm/p2m.h | 3 +- xen/arch/riscv/include/asm/p2m.h | 102 +++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 xen/arch/riscv/include/asm/p2m.h
xen/arch/ppc/include/asm/p2m.h +1 -2
@@ -50,8 +50,7 @@ static inline void memory_type_changed(struct domain *d)static inline int guest_physmap_mark_populate_on_demand (struct domain *d,unsigned long gfn,unsigned int order) { -BUG_ON ("unimplemented" ); -return 1 ; +return -EOPNOTSUPP ; } static inline int guest_physmap_add_entry(struct domain *d,
xen/arch/riscv/include/asm/p2m.h new file +102 -0
102 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v3 21/34] xen/riscv: introduce p2m.h
Hi Oleksii,
Quoted 21 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- add SPDX
- drop unneeded for now p2m types.
- return false in all functions implemented withBUG()inside.
- update the commit message
---
Changes in V2:
- Nothing changed. Only rebase.--- xen/arch/ppc/include/asm/p2m.h | 3 +- xen/arch/riscv/include/asm/p2m.h | 102 +++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 2 deletions(-) create mode 100644 xen/arch/riscv/include/asm/p2m.hxen/arch/ppc/include/asm/p2m.h +0
-0
xen/arch/ppc/include/asm/p2m.h static inline void memory_type_changed(struct domain *d) · line 55
Quoted 8 lines
xen/arch/ppc/include/asm/p2m.h +1
-2@@ -50,8 +50,7 @@ static inline void memory_type_changed(struct domain *d)static inline int guest_physmap_mark_populate_on_demand (struct domain *d,unsigned long gfn,unsigned int order) { -BUG_ON ("unimplemented" ); -return 1 ; +return -EOPNOTSUPP ; }
Was this change included by mistake? I'm not sure why this patch should touch PPC's p2m.h.
Thanks,
Shawn
Re: [PATCH v3 21/34] xen/riscv: introduce p2m.h
Quoted 33 lines · Shawn Anastasio
Hi Oleksii,
Quoted 30 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- add SPDX
- drop unneeded for now p2m types.
- return false in all functions implemented withBUG()inside.
- update the commit message
---
Changes in V2:
- Nothing changed. Only rebase.
---
xen/arch/ppc/include/asm/p2m.h | 3 +-xen/arch/riscv/include/asm/p2m.h| 102
+++++++++++++++++++++++++++++++2 files changed, 103 insertions(+), 2 deletions(-)create mode 100644
xen/arch/riscv/include/asm/p2m.hxen/arch/ppc/include/asm/p2m.h +0
-0@@ -50,8 +50,7 @@ static inline void memory_type_changed(struct domain *d)static inline int guest_physmap_mark_populate_on_demand(struct domain *d, unsigned long gfn,
unsigned int order)
{
-BUG_ON("unimplemented");
Quoted 8 lines
Quoted 4 lines
- return 1;
+ return-EOPNOTSUPP;
}Was this change included by mistake? I'm not sure why this patch should
touch PPC'sp2m.h.
I think you are right. It's mistake. RISC-V has the similar p2m.h so I faulty changed PPC version too.
Thanks.
~ Oleksii
Re: [PATCH v3 21/34] xen/riscv: introduce p2m.h
In reply to Oleksii KurochkoHi Oleksii,
Quoted 41 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- add SPDX
- drop unneeded for now p2m types.
- return false in all functions implemented withBUG()inside.
- update the commit message
---
Changes in V2:
- Nothing changed. Only rebase.--- xen/arch/ppc/include/asm/p2m.h | 3 +- xen/arch/riscv/include/asm/p2m.h | 102 +++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 2 deletions(-)create mode 100644
xen/arch/riscv/include/asm/p2m.hxen/arch/ppc/include/asm/p2m.h +1
-2@@ -50,8 +50,7 @@ static inline void memory_type_changed(struct domain *d)static inline int guest_physmap_mark_populate_on_demand (struct domain *d,unsigned long gfn,unsigned int order) { -BUG_ON ("unimplemented" ); -return 1 ; +return -EOPNOTSUPP ; } static inline int guest_physmap_add_entry(struct domain *d,xen/arch/riscv/include/asm/p2m.h new file +5
-0@@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_RISCV_P2M_H__ +#define __ASM_RISCV_P2M_H__ + +#include <asm/page-bits.h>
xen/arch/riscv/include/asm/p2m.h line 15
Quoted 10 lines
xen/arch/riscv/include/asm/p2m.h new file +10
-0+ +#define paddr_bits PADDR_BITS + +/* +* List of possible type for each page in the p2m entry. +* The number of available bit per page in the pte for this purpose is 4 bits. +* So it's possible to only have 16 fields. If we run out of value in the +* future, it's possible to use higher value for pseudo-type and don't store +* them in the p2m entry. +*/
This looks like a verbatim copy from Arm. Did you actually check RISC-V has 4 bits available in the PTE to store this value?
xen/arch/riscv/include/asm/p2m.h line 18
Quoted 3 lines
xen/arch/riscv/include/asm/p2m.h new file +3
-0+typedef enum { + p2m_invalid = 0, /* Nothing mapped here */ + p2m_ram_rw, /* Normal read/write guest RAM */
s/guest/domain/ as this also applies for dom0.
xen/arch/riscv/include/asm/p2m.h line 27
Quoted 9 lines
xen/arch/riscv/include/asm/p2m.h new file +9
-0+} p2m_type_t; + +#include <xen/p2m-common.h> + +static inline int get_page_and_type (struct page_info *page, +struct domain *domain, +unsigned long type) +{ +BUG ();
I understand your goal with the BUG() but I find it risky. This is not a problem right now, it is more when we will decide to have RISC-V supported. You will have to go through all the BUG() to figure out which one are warrant or not.
To reduce the load, I would recommend to switch to ASSERT_UNREACHABLE() (or maybe introduced a different macro) that would lead to a crash on debug build but propagate the error normally on production build.
Of course, if you can't propagate an error, then the right course of action is a BUG(). But I expect this case to be limited.
[...]
xen/arch/riscv/include/asm/p2m.h line 76
Quoted 4 lines
xen/arch/riscv/include/asm/p2m.h new file +4
-0+static inline mfn_t gfn_to_mfn (struct domain *d,gfn_t gfn) +{ +BUG (); +return _mfn (0 );
This wants to be INVALID_MFN.
[...]
Signature · 1 line
Julien Grall
Re: [PATCH v3 21/34] xen/riscv: introduce p2m.h
Quoted 77 lines · Julien Grall
Quoted 41 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- add SPDX
- drop unneeded for now p2m types.
- return false in all functions implemented withBUG()inside.
- update the commit message
---
Changes in V2:
- Nothing changed. Only rebase.--- xen/arch/ppc/include/asm/p2m.h | 3 +- xen/arch/riscv/include/asm/p2m.h | 102 +++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 2 deletions(-)create mode 100644
xen/arch/riscv/include/asm/p2m.hxen/arch/ppc/include/asm/p2m.h +1
-2@@ -50,8 +50,7 @@ static inline void memory_type_changed(struct domain *d)static inline int guest_physmap_mark_populate_on_demand (struct domain *d,unsigned long gfn,unsigned int order) { -BUG_ON ("unimplemented" ); -return 1 ; +return -EOPNOTSUPP ; } static inline int guest_physmap_add_entry(struct domain *d,xen/arch/riscv/include/asm/p2m.h new file +5
-0@@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_RISCV_P2M_H__ +#define __ASM_RISCV_P2M_H__ + +#include <asm/page-bits.h> xen/arch/riscv/include/asm/p2m.h line 15
Quoted 10 lines
xen/arch/riscv/include/asm/p2m.h new file +10
-0+ +#define paddr_bits PADDR_BITS + +/* +* List of possible type for each page in the p2m entry. +* The number of available bit per page in the pte for this purpose is 4 bits. +* So it's possible to only have 16 fields. If we run out of value in the +* future, it's possible to use higher value for pseudo-type and don't store +* them in the p2m entry. +*/ This looks like a verbatim copy from Arm. Did you actually check RISC-V has 4 bits available in the PTE to store this value?
xen/arch/riscv/include/asm/p2m.h line 18
Quoted 3 lines
xen/arch/riscv/include/asm/p2m.h new file +3
-0+typedef enum { + p2m_invalid = 0, /* Nothing mapped here */ + p2m_ram_rw, /* Normal read/write guest RAM */s/guest/domain/ as this also applies for dom0.
xen/arch/riscv/include/asm/p2m.h line 27
Quoted 9 lines
xen/arch/riscv/include/asm/p2m.h new file +9
-0+} p2m_type_t; + +#include <xen/p2m-common.h> + +static inline int get_page_and_type (struct page_info *page, +struct domain *domain, +unsigned long type) +{ +BUG ();I understand your goal with the
BUG()but I find it risky. This is not a problem right now, it is more when we will decide to have RISC-V supported. You will have to go through all theBUG()to figure out which one are warrant or not.
Quoted 3 lines
To reduce the load, I would recommend to switch to
ASSERT_UNREACHABLE()(or maybe introduced a different macro) that would lead to a crash on debug build but propagate the error normally on production build.
Elsewhere BUG_ON("unimplemented") is used to indicate such cases. Can't this be used here (and then uniformly elsewhere) as well?
Jan
Re: [PATCH v3 21/34] xen/riscv: introduce p2m.h
Hi Jan,
Quoted 78 lines · Jan Beulich
Quoted 77 lines · Julien Grall
Quoted 41 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- add SPDX
- drop unneeded for now p2m types.
- return false in all functions implemented withBUG()inside.
- update the commit message
---
Changes in V2:
- Nothing changed. Only rebase.--- xen/arch/ppc/include/asm/p2m.h | 3 +- xen/arch/riscv/include/asm/p2m.h | 102 +++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 2 deletions(-)create mode 100644
xen/arch/riscv/include/asm/p2m.hxen/arch/ppc/include/asm/p2m.h +1
-2@@ -50,8 +50,7 @@ static inline void memory_type_changed(struct domain *d)static inline int guest_physmap_mark_populate_on_demand (struct domain *d,unsigned long gfn,unsigned int order) { -BUG_ON ("unimplemented" ); -return 1 ; +return -EOPNOTSUPP ; } static inline int guest_physmap_add_entry(struct domain *d,xen/arch/riscv/include/asm/p2m.h new file +5
-0@@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_RISCV_P2M_H__ +#define __ASM_RISCV_P2M_H__ + +#include <asm/page-bits.h> xen/arch/riscv/include/asm/p2m.h line 15
Quoted 10 lines
xen/arch/riscv/include/asm/p2m.h new file +10
-0+ +#define paddr_bits PADDR_BITS + +/* +* List of possible type for each page in the p2m entry. +* The number of available bit per page in the pte for this purpose is 4 bits. +* So it's possible to only have 16 fields. If we run out of value in the +* future, it's possible to use higher value for pseudo-type and don't store +* them in the p2m entry. +*/ This looks like a verbatim copy from Arm. Did you actually check RISC-V has 4 bits available in the PTE to store this value?
xen/arch/riscv/include/asm/p2m.h line 18
Quoted 3 lines
xen/arch/riscv/include/asm/p2m.h new file +3
-0+typedef enum { + p2m_invalid = 0, /* Nothing mapped here */ + p2m_ram_rw, /* Normal read/write guest RAM */s/guest/domain/ as this also applies for dom0.
xen/arch/riscv/include/asm/p2m.h line 27
Quoted 9 lines
xen/arch/riscv/include/asm/p2m.h new file +9
-0+} p2m_type_t; + +#include <xen/p2m-common.h> + +static inline int get_page_and_type (struct page_info *page, +struct domain *domain, +unsigned long type) +{ +BUG ();I understand your goal with the
BUG()but I find it risky. This is not a problem right now, it is more when we will decide to have RISC-V supported. You will have to go through all theBUG()to figure out which one are warrant or not.
Quoted 6 lines
Quoted 3 lines
To reduce the load, I would recommend to switch to
ASSERT_UNREACHABLE()(or maybe introduced a different macro) that would lead to a crash on debug build but propagate the error normally on production build.Elsewhere
BUG_ON("unimplemented")is used to indicate such cases. Can't this be used here (and then uniformly elsewhere) as well?
I would prefer something that can be compiled out in production build. But I would be Ok with BUG_ON("...") this is at least clearer than a plain BUG().
Signature · 1 line
Julien Grall
Re: [PATCH v3 21/34] xen/riscv: introduce p2m.h
In reply to Julien GrallHi Julien,
Quoted 59 lines · Julien Grall
Hi Oleksii,
Quoted 56 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- add SPDX
- drop unneeded for now p2m types.
- return false in all functions implemented withBUG()inside.
- update the commit message
---
Changes in V2:
- Nothing changed. Only rebase.
---
xen/arch/ppc/include/asm/p2m.h | 3 +-xen/arch/riscv/include/asm/p2m.h| 102
+++++++++++++++++++++++++++++++2 files changed, 103 insertions(+), 2 deletions(-)create mode 100644
xen/arch/riscv/include/asm/p2m.hxen/arch/ppc/include/asm/p2m.h +0
-0@@ -50,8 +50,7 @@ static inline void memory_type_changed(struct domain *d)static inline int guest_physmap_mark_populate_on_demand(struct domain *d, unsigned long gfn,
unsigned int order)
{
-BUG_ON("unimplemented");
- return 1;
+ return-EOPNOTSUPP;
}
static inline int guest_physmap_add_entry(struct domain *d,xen/arch/riscv/include/asm/p2m.h new file +11
-0@@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_RISCV_P2M_H__ +#define __ASM_RISCV_P2M_H__ + +#include <asm/page-bits.h> + +#define paddr_bits PADDR_BITS + +/* +* List of possible type for each page in the p2m entry. +* The number of available bit per page in the pte for this purpose is 4 bits.
+ * So it's possible to only have 16 fields. If we run out of value in the
Quoted 8 lines
Quoted 4 lines
+ * future, it's possible to use higher value for pseudo-type and don't store
+ * them in the p2m entry.
+ */This looks like a verbatim copy from Arm. Did you actually check RISC-V
has 4 bits available in the PTE to store this value?
Thanks for noticing that, in RISC-V it is available only 2 bits ( bits 8 and 9), so I'll update the comment:
53 10 9 8 7 6 5 4 3 2 1 0
Physical Page Number RSV D A G U X W R V
It seems that I missed something in the Arm code/architecture.As far as I recall, in Arm, bits 5-8 are ignored by the MMU, and they are expected
to be used by the hypervisor for its purpose.
However, in the code, I notice that these bits are utilized for storing
a reference counter.
Could you confirm if my understanding is correct? Additionally, I am curious about where the PTE bits are used to store one of the values of the enum p2m_type_t.
Quoted 6 lines
Quoted 4 lines
+typedef enum {
+p2m_invalid= 0, /* Nothing mapped here */ + p2m_ram_rw, /* Normal read/write guest RAM */s/guest/domain/ as this also applies for dom0.
Thanks. I'll update that.
Quoted 18 lines
xen/arch/riscv/include/asm/p2m.h line 27
Quoted 10 lines
xen/arch/riscv/include/asm/p2m.h new file +9
-0+} p2m_type_t; + +#include <xen/p2m-common.h> + +static inline int get_page_and_type (struct page_info *page, + struct domain *domain, + unsigned long type) +{ + BUG();I understand your goal with the
BUG()but I find it risky. This is not a
problem right now, it is more when we will decide to have RISC-V supported. You will have to go through all theBUG()to figure out which
one are warrant or not.
Quoted 7 lines
To reduce the load, I would recommend to switch to
ASSERT_UNREACHABLE()
(or maybe introduced a different macro) that would lead to a crash on debug build but propagate the error normally on production build.Of course, if you can't propagate an error, then the right course of action is a
BUG(). But I expect this case to be limited.
Thanks.
I'm currently transitioning to using ASSERT_UNREACHABLE() or BUG_ON() throughout the codebase, and this is one of the instances where I overlooked the update.
Quoted 12 lines
[...]
xen/arch/riscv/include/asm/p2m.h line 76
Quoted 4 lines
xen/arch/riscv/include/asm/p2m.h new file +4
-0+static inline mfn_t gfn_to_mfn (struct domain *d,gfn_t gfn) +{ + BUG(); + return _mfn(0);This wants to be
INVALID_MFN.[...]
~ Oleksii
Re: [PATCH v3 21/34] xen/riscv: introduce p2m.h
Quoted 70 lines · Oleksii
Hi Julien,
Quoted 59 lines · Julien Grall
Hi Oleksii,
Quoted 56 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- add SPDX
- drop unneeded for now p2m types.
- return false in all functions implemented withBUG()inside.
- update the commit message
---
Changes in V2:
- Nothing changed. Only rebase.
---
xen/arch/ppc/include/asm/p2m.h | 3 +-xen/arch/riscv/include/asm/p2m.h| 102
+++++++++++++++++++++++++++++++2 files changed, 103 insertions(+), 2 deletions(-)create mode 100644
xen/arch/riscv/include/asm/p2m.hxen/arch/ppc/include/asm/p2m.h +0
-0@@ -50,8 +50,7 @@ static inline void memory_type_changed(struct domain *d)static inline int guest_physmap_mark_populate_on_demand(struct domain *d, unsigned long gfn,
unsigned int order)
{
-BUG_ON("unimplemented");
- return 1;
+ return-EOPNOTSUPP;
}
static inline int guest_physmap_add_entry(struct domain *d,xen/arch/riscv/include/asm/p2m.h new file +11
-0@@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_RISCV_P2M_H__ +#define __ASM_RISCV_P2M_H__ + +#include <asm/page-bits.h> + +#define paddr_bits PADDR_BITS + +/* +* List of possible type for each page in the p2m entry. +* The number of available bit per page in the pte for this purpose is 4 bits.
+ * So it's possible to only have 16 fields. If we run out of value in theQuoted 8 lines
Quoted 4 lines
+ * future, it's possible to use higher value for pseudo-type and don't store
+ * them in the p2m entry.
+ */This looks like a verbatim copy from Arm. Did you actually check RISC-V
has 4 bits available in the PTE to store this value?
Quoted 4 lines
Thanks for noticing that, in RISC-V it is available only 2 bits ( bits 8 and 9), so I'll update the comment:
53 10 9 8 7 6 5 4 3 2 1 0
Physical Page Number RSV D A G U X W R V
It's RSW (Reserved for Supervisor softWare use), not RSV, which is pretty important in this context.
Quoted 5 lines
It seems that I missed something in the Arm code/architecture.As far as I recall, in Arm, bits 5-8 are ignored by the MMU, and they are expected
to be used by the hypervisor for its purpose.
However, in the code, I notice that these bits are utilized for storing
a reference counter.
Why "however"? Hardware still is going to ignore these bits.
Jan
Re: [PATCH v3 21/34] xen/riscv: introduce p2m.h
Quoted 82 lines · Jan Beulich
Quoted 75 lines · Oleksii
Hi Julien,
Quoted 64 lines · Julien Grall
Hi Oleksii,
Quoted 61 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- add SPDX
- drop unneeded for now p2m types.
- return false in all functions implemented withBUG()inside.
- update the commit message
---
Changes in V2:
- Nothing changed. Only rebase.
---
xen/arch/ppc/include/asm/p2m.h | 3 +-xen/arch/riscv/include/asm/p2m.h| 102
+++++++++++++++++++++++++++++++2 files changed, 103 insertions(+), 2 deletions(-)create mode 100644
xen/arch/riscv/include/asm/p2m.hxen/arch/ppc/include/asm/p2m.h +0
-0@@ -50,8 +50,7 @@ static inline void memory_type_changed(struct domain *d)static inline int guest_physmap_mark_populate_on_demand(struct
domain *d, unsigned long gfn,
unsigned
int order)
{
-BUG_ON("unimplemented");
- return 1;
+ return-EOPNOTSUPP;
}
static inline int guest_physmap_add_entry(struct domain *d,xen/arch/riscv/include/asm/p2m.h new file +11
-0@@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_RISCV_P2M_H__ +#define __ASM_RISCV_P2M_H__ + +#include <asm/page-bits.h> + +#define paddr_bits PADDR_BITS + +/* +* List of possible type for each page in the p2m entry. +* The number of available bit per page in the pte for this purpose is 4 bits.
+ * So it's possible to only have 16 fields. If we run out of value
in the
+ * future, it's possible to use higher value for pseudo-typeQuoted 8 lines
Quoted 4 lines
and
don't store
+ * them in the p2m entry.
+ */This looks like a verbatim copy from Arm. Did you actually check RISC-V
has 4 bits available in the PTE to store this value?Quoted 5 lines
Thanks for noticing that, in RISC-V it is available only 2 bits ( bits
8 and 9), so I'll update the comment:
53 10 9 8 7 6 5 4 3 2 1 0
Physical Page Number RSV D A G U X W R V
Quoted 3 lines
It's RSW (Reserved for Supervisor softWare use), not RSV, which is pretty
important in this context.
Yes, you are right it is RSW. Thanks for the correction.
Quoted 10 lines
Quoted 8 lines
It seems that I missed something in the Arm code/architecture.As far as I recall, in Arm, bits 5-8 are ignored by the MMU, and they are expected
to be used by the hypervisor for its purpose.
However, in the code, I notice that these bits are utilized for storing
a reference counter.Why "however"? Hardware still is going to ignore these bits.
Sure, these bits are ignored by hardware. What I meant is that, according to the code, these bits are used for storing a reference counter, not p2m_type_t. I guess I am missing something...
~ Oleksii
Re: [PATCH v3 21/34] xen/riscv: introduce p2m.h
Hi Oleksii,
Quoted 97 lines · Oleksii
Quoted 82 lines · Jan Beulich
Quoted 75 lines · Oleksii
Hi Julien,
Quoted 64 lines · Julien Grall
Hi Oleksii,
Quoted 61 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- add SPDX
- drop unneeded for now p2m types.
- return false in all functions implemented withBUG()
inside.
- update the commit message
---
Changes in V2:
- Nothing changed. Only rebase.--- xen/arch/ppc/include/asm/p2m.h | 3 +- xen/arch/riscv/include/asm/p2m.h | 102 +++++++++++++++++++++++++++++++ 2 files changed, 103 insertions(+), 2 deletions(-)create mode 100644
xen/arch/riscv/include/asm/p2m.hxen/arch/ppc/include/asm/p2m.h +0
-0@@ -50,8 +50,7 @@ static inline void memory_type_changed(struct domain *d) static inline intguest_physmap_mark_populate_on_demand(struct
domain *d, unsigned long gfn,unsigned
int order)
{
-BUG_ON("unimplemented");
- return 1;
+ return-EOPNOTSUPP;
}static inline int guest_physmap_add_entry(struct domain *d,
xen/arch/riscv/include/asm/p2m.h new file +11
-0@@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_RISCV_P2M_H__ +#define __ASM_RISCV_P2M_H__ + +#include <asm/page-bits.h> + +#define paddr_bits PADDR_BITS + +/* +* List of possible type for each page in the p2m entry. +* The number of available bit per page in the pte for this purpose is 4 bits.
+ * So it's possible to only have 16 fields. If we run out of value
in the
+ * future, it's possible to use higher value for pseudo-typeQuoted 8 lines
Quoted 4 lines
and
don't store
+ * them in the p2m entry.
+ */This looks like a verbatim copy from Arm. Did you actually check RISC-V
has 4 bits available in the PTE to store this value?Quoted 5 lines
Thanks for noticing that, in RISC-V it is available only 2 bits ( bits
8 and 9), so I'll update the comment:
53 10 9 8 7 6 5 4 3 2 1 0
Physical Page Number RSV D A G U X W R VQuoted 3 lines
It's RSW (Reserved for Supervisor softWare use), not RSV, which is pretty
important in this context.Yes, you are right it is RSW. Thanks for the correction.
Quoted 9 lines
Quoted 8 lines
It seems that I missed something in the Arm code/architecture.As far as I recall, in Arm, bits 5-8 are ignored by the MMU, and they are expected
to be used by the hypervisor for its purpose.
However, in the code, I notice that these bits are utilized for storing
a reference counter.
Quoted 4 lines
Quoted 1 line
Why "however"? Hardware still is going to ignore these bits.
Sure, these bits are ignored by hardware. What I meant is that, according to the code, these bits are used for storing a reference counter, not
p2m_type_t. I guess I am missing something...
I can only guess where you saw the field used for reference counting. This was the domain map page infrastruture, right?
If so, this is for stage-1 page-table (aka hypervisor table) and not the stage-2 (e.g. P2M). For the latter, we would use the p2m_type_t.
Cheers,
Signature · 1 line
Julien Grall
Re: [PATCH v3 21/34] xen/riscv: introduce p2m.h
Hi Julien,
Quoted 111 lines · Julien Grall
Hi Oleksii,
Quoted 108 lines · Oleksii
Quoted 90 lines · Jan Beulich
Quoted 82 lines · Oleksii
Hi Julien,
Quoted 71 lines · Julien Grall
Hi Oleksii,
Quoted 68 lines · Oleksii Kurochko
Signed-off-by: Oleksii Kurochko <[email protected]>
---
Changes in V3:
- add SPDX
- drop unneeded for now p2m types.
- return false in all functions implemented withBUG()inside.
- update the commit message
---
Changes in V2:
- Nothing changed. Only rebase.
---
xen/arch/ppc/include/asm/p2m.h | 3 +-xen/arch/riscv/include/asm/p2m.h| 102
+++++++++++++++++++++++++++++++2 files changed, 103 insertions(+), 2 deletions(-)create mode 100644
xen/arch/riscv/include/asm/p2m.hxen/arch/ppc/include/asm/p2m.h +0
-0@@ -50,8 +50,7 @@ static inline voidmemory_type_changed(struct
domain *d)
static inline int guest_physmap_mark_populate_on_demand(struct domain *d, unsigned long gfn,
unsigned
int order)
{
-BUG_ON("unimplemented");
- return 1;
+ return-EOPNOTSUPP;
}
static inline int guest_physmap_add_entry(struct domain *d,xen/arch/riscv/include/asm/p2m.h new file +11
-0@@ -0,0 +1,102 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_RISCV_P2M_H__ +#define __ASM_RISCV_P2M_H__ + +#include <asm/page-bits.h> + +#define paddr_bits PADDR_BITS + +/* +* List of possible type for each page in the p2m entry. +* The number of available bit per page in the pte for this
purpose is 4 bits.
+ * So it's possible to only have 16 fields. If we run out of
value
in the
+ * future, it's possible to use higher value for pseudo- type
andQuoted 8 lines
Quoted 3 lines
don't store
+ * them in the p2m entry.
+ */This looks like a verbatim copy from Arm. Did you actually check
RISC-V
has 4 bits available in the PTE to store this value?Quoted 6 lines
Thanks for noticing that, in RISC-V it is available only 2 bits (
bits
8 and 9), so I'll update the comment:
53 10 9 8 7 6 5 4 3 2 1 0 Physical Page Number RSV D A G U X W R VQuoted 4 lines
It's RSW (Reserved for Supervisor softWare use), not RSV, which is
pretty
important in this context.Yes, you are right it is RSW. Thanks for the correction.
Quoted 11 lines
Quoted 10 lines
It seems that I missed something in the Arm code/architecture.As
far as I recall, in Arm, bits 5-8 are ignored by the MMU, and they
are expected
to be used by the hypervisor for its purpose. However, in the code, I notice that these bits are utilized for storing
a reference counter.
Quoted 7 lines
Quoted 4 lines
Quoted 1 line
Why "however"? Hardware still is going to ignore these bits.
Sure, these bits are ignored by hardware. What I meant is that, according to the code, these bits are used for storing a reference counter, not
p2m_type_t. I guess I am missing something...I can only guess where you saw the field used for reference counting. This was the domain map page infrastruture, right?
Yes, you are right.
Quoted 4 lines
If so, this is for stage-1 page-table (aka hypervisor table) and not the
stage-2 (e.g. P2M). For the latter, we would use thep2m_type_t.
I confused stage-1 & stage-2. Now everything fell into place. Thanks.
~ Oleksii
PATCH v3 22/34 xen/riscv: introduce regs.h
In reply to Oleksii Kurochko---
Changes in V3:
- update the commit message
- add Acked-by: Jan Beulich <[email protected]>
- remove "include <asm/current.h>" and use a forward declaration instead.
---
Changes in V2:
- change xen/lib.h to xen/bug.h
- remove unnecessary empty line
--- xen/arch/riscv/include/asm/regs.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 xen/arch/riscv/include/asm/regs.h
xen/arch/riscv/include/asm/regs.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ARM_RISCV_REGS_H__ +#define __ARM_RISCV_REGS_H__ + +#ifndef __ASSEMBLY__ + +#include <xen/bug.h> + +#define hyp_mode (r) (0) + +struct cpu_user_regs ; + +static inline bool guest_mode (const struct cpu_user_regs *r) +{ +BUG (); +} + +#endif /* __ASSEMBLY__ */ + +#endif /* __ARM_RISCV_REGS_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
2.43.0
Re: [PATCH v3 22/34] xen/riscv: introduce regs.h
Quoted 5 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- update the commit message
- add Acked-by: Jan Beulich <[email protected]>
I see none above the --- marker.
Jan
Re: [PATCH v3 22/34] xen/riscv: introduce regs.h
Quoted 8 lines · Jan Beulich
Quoted 5 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- update the commit message
- add Acked-by: Jan Beulich <[email protected]>I see none above the --- marker.
Thanks for noticing. I'll add in the next patch version.
~ Oleksii
PATCH v3 23/34 xen/riscv: introduce time.h
In reply to Oleksii Kurochko---
Changes in V3:
- Acked-by: Jan Beulich <[email protected]>
- add SPDX
- Add new line
---
Changes in V2:
- change xen/lib.h to xen/bug.h
- remove inclusion of <asm/processor.h> as it's not needed.
--- xen/arch/riscv/include/asm/time.h | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 xen/arch/riscv/include/asm/time.h
xen/arch/riscv/include/asm/time.h new file +29 -0
@@ -0,0 +1,29 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_RISCV_TIME_H__ +#define __ASM_RISCV_TIME_H__ + +#include <xen/bug.h> +#include <asm/csr.h> + +struct vcpu ; + +/* TODO: implement */ +static inline void force_update_vcpu_system_time (struct vcpu *v) {BUG (); } + +typedef unsigned long cycles_t ; + +static inline cycles_t get_cycles (void ) +{ +return csr_read (CSR_TIME ); +} + +#endif /* __ASM_RISCV_TIME_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
2.43.0
PATCH v3 24/34 xen/riscv: introduce event.h
In reply to Oleksii Kurochko---
Changes in V3:
- add SPDX
- add BUG() inside stubs.
- update the commit message
---
Changes in V2:
- Nothing changed. Only rebase.
--- xen/arch/riscv/include/asm/event.h | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 xen/arch/riscv/include/asm/event.h
xen/arch/riscv/include/asm/event.h new file +40 -0
@@ -0,0 +1,40 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_RISCV_EVENT_H__ +#define __ASM_RISCV_EVENT_H__ + +#include <xen/bug.h> + +void vcpu_mark_events_pending (struct vcpu *v); + +static inline int vcpu_event_delivery_is_enabled (struct vcpu *v) +{ +BUG (); +return 0 ; +} + +static inline int local_events_need_delivery (void ) +{ +BUG (); +return 0 ; +} + +static inline void local_event_delivery_enable (void ) +{ +BUG (); +} + +/* No arch specific virq definition now. Default to global. */ +static inline bool arch_virq_is_global (unsigned int virq) +{ +return true; +} + +#endif +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
2.43.0
PATCH v3 25/34 xen/riscv: introduce monitor.h
In reply to Oleksii Kurochko---
Taking into account conversion in [PATCH v6 0/9] Introduce generic headers
(https://lore.kernel.org/xen-devel/[email protected]/)
this patch can be changed
---
Changes in V3:
- new patch.
--- xen/arch/riscv/include/asm/monitor.h | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 xen/arch/riscv/include/asm/monitor.h
xen/arch/riscv/include/asm/monitor.h new file +26 -0
@@ -0,0 +1,26 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +#ifndef __ASM_RISCV_MONITOR_H__ +#define __ASM_RISCV_MONITOR_H__ + +#include <xen/bug.h> + +#include <asm-generic/monitor.h> + +struct domain ; + +static inline uint32_t arch_monitor_get_capabilities (struct domain *d) +{ +BUG_ON ("unimplemented" ); +return 0 ; +} + +#endif /* __ASM_RISCV_MONITOR_H__ */ + +/* +* Local variables: +* mode: C +* c-file-style: "BSD" +* c-basic-offset: 4 +* indent-tabs-mode: nil +* End: +*/
Signature · 1 line
2.43.0
PATCH v3 26/34 xen/riscv: add definition of __read_mostly
In reply to Oleksii KurochkoThe definition of __read_mostly should be removed in:
https://lore.kernel.org/xen-devel/[email protected]/
The patch introduces it in arch-specific header to not block enabling of full Xen build for RISC-V.
---
- [PATCH] move __read_mostly to xen/cache.h [2]
Right now, the patch series doesn't have a direct dependency on [2] and it provides __read_mostly in the patch:
[PATCH v3 26/34] xen/riscv: add definition of __read_mostly
However, it will be dropped as soon as [2] is merged or at least when the final version of the patch [2] is provided.
[2] https://lore.kernel.org/xen-devel/[email protected]/
--- xen/arch/riscv/include/asm/cache.h | 2 ++ 1 file changed, 2 insertions(+)
xen/arch/riscv/include/asm/cache.h +2 -0
@@ -3,4 +3,6 @@#ifndef _ASM_RISCV_CACHE_H#define _ASM_RISCV_CACHE_H +#define __read_mostly __section(".data.read_mostly") +#endif /* _ASM_RISCV_CACHE_H */
Signature · 1 line
2.43.0
PATCH v3 27/34 xen/riscv: define an address of frame table
In reply to Oleksii KurochkoAlso, the patch adds some helpful macros that assist in avoiding the redefinition of memory layout for each MMU mode.
---
Changes in V3:
- drop OFFSET_BITS, and use PAGE_SHIFT instead.
- code style fixes.
- add comment how macros are useful.
- move all memory related layout definitions close to comment with memory layout description.
- make memory layout description generic for any MMU mode.
---
Changes in V2:
- Nothing changed. Only rebase.
--- xen/arch/riscv/include/asm/config.h | 85 +++++++++++++++++++---------- 1 file changed, 55 insertions(+), 30 deletions(-)
xen/arch/riscv/include/asm/config.h +55 -30
@@ -6,6 +6,14 @@#include <xen/const.h> #include <xen/page-size.h> +#ifdef CONFIG_RISCV_64 +#define CONFIG_PAGING_LEVELS 3 +#define RV_STAGE1_MODE SATP_MODE_SV39 +#else +#define CONFIG_PAGING_LEVELS 2 +#define RV_STAGE1_MODE SATP_MODE_SV32 +#endif +/* * RISC-V64 Layout: *
@@ -22,25 +30,56 @@* * It means that: * top VA bits are simply ignored for the purpose of translating to PA. +#endif * -* ============================================================================ -* Start addr | End addr | Size | Slot |area description -* ============================================================================ -* FFFFFFFFC0800000 | FFFFFFFFFFFFFFFF |1016 MB | L2 511 | Unused -* FFFFFFFFC0600000 | FFFFFFFFC0800000 | 2 MB | L2 511 | Fixmap -* FFFFFFFFC0200000 | FFFFFFFFC0600000 | 4 MB | L2 511 | FDT -* FFFFFFFFC0000000 | FFFFFFFFC0200000 | 2 MB | L2 511 | Xen -* ... | 1 GB | L2 510 | Unused -* 0000003200000000 | 0000007F80000000 | 309 GB | L2 200-509 | Direct map -* ... | 1 GB | L2 199 | Unused -* 0000003100000000 | 00000031C0000000 | 3 GB | L2 196-198 | Frametable -* ... | 1 GB | L2 195 | Unused -* 0000003080000000 | 00000030C0000000 | 1 GB | L2 194 | VMAP -* ... | 194 GB | L2 0 - 193 | Unused -* ============================================================================ +* SATP_MODE_SV32 | SATP_MODE_SV39 | SATP_MODE_SV48 | SATP_MODE_SV57 +* ==================|==================|==================|================= +* BA0 | FFFFFFFFFFE00000 | FFFFFFFFC0000000 | FFFFFF8000000000 | FFFF000000000000 +* BA1 | 0000000019000000 | 0000003200000000 | 0000640000000000 | 00C8000000000000 +* BA2 | 0000000018800000 | 0000003100000000 | 0000620000000000 | 00C4000000000000 +* BA3 | 0000000018400000 | 0000003080000000 | 0000610000000000 | 00C2000000000000 * -#endif +* =============================================================================== +* Start addr | End addr | Size | Root PT slot | Area description +* =============================================================================== +* BA0 + 0x800000 | FFFFFFFFFFFFFFFF |1016 MB | 511 | Unused +* BA0 + 0x400000 | BA0 + 0x800000 | 2 MB | 511 | Fixmap +* BA0 + 0x200000 | BA0 + 0x400000 | 4 MB | 511 | FDT +* BA0 | BA0 + 0x200000 | 2 MB | 511 | Xen +* ... | 1 GB | 510 | Unused +* BA1 + 0x000000 | BA1 + 0x4D80000000 | 309 GB | 200-509 | Direct map +* ... | 1 GB | 199 | Unused +* BA2 + 0x000000 | BA2 + 0xC0000000 | 3 GB | 196-198 | Frametable +* ... | 1 GB | 195 | Unused +* BA3 + 0x000000 | BA3 + 0x40000000 | 1 GB | 194 | VMAP +* ... | 194 GB | 0 - 193 | Unused +* =============================================================================== */ +#define VPN_BITS (9) + +#define HYP_PT_ROOT_LEVEL (CONFIG_PAGING_LEVELS - 1) + +#ifdef CONFIG_RISCV_64 + +#define SLOTN_ENTRY_BITS (HYP_PT_ROOT_LEVEL * VPN_BITS + PAGE_SHIFT) +#define SLOTN (slot) (_AT(vaddr_t, slot) << SLOTN_ENTRY_BITS) +#define SLOTN_ENTRY_SIZE SLOTN(1) + +#define XEN_VIRT_START 0xFFFFFFFFC0000000/* (_AC(-1, UL) + 1 - GB(1)) */ + +#define FRAMETABLE_VIRT_START SLOTN(196) +#define FRAMETABLE_SIZE GB(3) +#define FRAMETABLE_NR (FRAMETABLE_SIZE / sizeof(*frame_table)) +#define FRAMETABLE_VIRT_END (FRAMETABLE_VIRT_START + FRAMETABLE_SIZE - 1) + +#define VMAP_VIRT_START SLOTN(194) +#define VMAP_VIRT_SIZE GB(1) + +#else +#error "RV32 isn't supported" +#endif + +#define HYPERVISOR_VIRT_START XEN_VIRT_START#if defined(CONFIG_RISCV_64 )# define LONG_BYTEORDER 3
@@ -77,24 +116,10 @@ name:#endif -#ifdef CONFIG_RISCV_64 -#define XEN_VIRT_START 0xFFFFFFFFC0000000/* (_AC(-1, UL) + 1 - GB(1)) */ -#else -#error "RV32 isn't supported" -#endif -#define SMP_CACHE_BYTES (1 << 6)#define STACK_SIZE PAGE_SIZE -#ifdef CONFIG_RISCV_64 -#define CONFIG_PAGING_LEVELS 3 -#define RV_STAGE1_MODE SATP_MODE_SV39 -#else -#define CONFIG_PAGING_LEVELS 2 -#define RV_STAGE1_MODE SATP_MODE_SV32 -#endif -#define IDENT_AREA_SIZE 64#endif /* __RISCV_CONFIG_H__ */
Signature · 1 line
2.43.0
Re: [PATCH v3 27/34] xen/riscv: define an address of frame table
Quoted 65 lines · Oleksii Kurochko
Also, the patch adds some helpful macros that assist in avoiding the redefinition of memory layout for each MMU mode.
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- dropOFFSET_BITS, and usePAGE_SHIFTinstead.
- code style fixes.
- add comment how macros are useful.
- move all memory related layout definitions close to comment with memory layout description.
- make memory layout description generic for any MMU mode.
---
Changes in V2:
- Nothing changed. Only rebase.--- xen/arch/riscv/include/asm/config.h | 85 +++++++++++++++++++---------- 1 file changed, 55 insertions(+), 30 deletions(-)xen/arch/riscv/include/asm/config.h +15
-15@@ -6,6 +6,14 @@#include <xen/const.h> #include <xen/page-size.h> +#ifdef CONFIG_RISCV_64 +#define CONFIG_PAGING_LEVELS 3 +#define RV_STAGE1_MODE SATP_MODE_SV39 +#else +#define CONFIG_PAGING_LEVELS 2 +#define RV_STAGE1_MODE SATP_MODE_SV32 +#endif +/* * RISC-V64 Layout: * @@ -22,25 +30,56 @@* * It means that: * top VA bits are simply ignored for the purpose of translating to PA. +#endif * -* ============================================================================ -* Start addr | End addr | Size | Slot |area description -* ============================================================================ -* FFFFFFFFC0800000 | FFFFFFFFFFFFFFFF |1016 MB | L2 511 | Unused -* FFFFFFFFC0600000 | FFFFFFFFC0800000 | 2 MB | L2 511 | Fixmap -* FFFFFFFFC0200000 | FFFFFFFFC0600000 | 4 MB | L2 511 | FDT -* FFFFFFFFC0000000 | FFFFFFFFC0200000 | 2 MB | L2 511 | Xen -* ... | 1 GB | L2 510 | Unused -* 0000003200000000 | 0000007F80000000 | 309 GB | L2 200-509 | Direct map -* ... | 1 GB | L2 199 | Unused -* 0000003100000000 | 00000031C0000000 | 3 GB | L2 196-198 | Frametable -* ... | 1 GB | L2 195 | Unused -* 0000003080000000 | 00000030C0000000 | 1 GB | L2 194 | VMAP -* ... | 194 GB | L2 0 - 193 | Unused -* ============================================================================ +* SATP_MODE_SV32 | SATP_MODE_SV39 | SATP_MODE_SV48 | SATP_MODE_SV57 +* ==================|==================|==================|================= +* BA0 | FFFFFFFFFFE00000 | FFFFFFFFC0000000 | FFFFFF8000000000 | FFFF000000000000 +* BA1 | 0000000019000000 | 0000003200000000 | 0000640000000000 | 00C8000000000000 +* BA2 | 0000000018800000 | 0000003100000000 | 0000620000000000 | 00C4000000000000 +* BA3 | 0000000018400000 | 0000003080000000 | 0000610000000000 | 00C2000000000000 *
xen/arch/riscv/include/asm/config.h line 50
Quoted 10 lines
xen/arch/riscv/include/asm/config.h +9
-1-#endif +* =============================================================================== +* Start addr | End addr | Size | Root PT slot | Area description +* =============================================================================== +* BA0 + 0x800000 | FFFFFFFFFFFFFFFF |1016 MB | 511 | Unused +* BA0 + 0x400000 | BA0 + 0x800000 | 2 MB | 511 | Fixmap +* BA0 + 0x200000 | BA0 + 0x400000 | 4 MB | 511 | FDT +* BA0 | BA0 + 0x200000 | 2 MB | 511 | Xen +* ... | 1 GB | 510 | Unused +* BA1 + 0x000000 | BA1 + 0x4D80000000 | 309 GB | 200-509 | Direct map
This definitely can't be right for SV32. Others may be problematic, too, like ...
xen/arch/riscv/include/asm/config.h line 52
Quoted 2 lines
xen/arch/riscv/include/asm/config.h +2
-0+* ... | 1 GB | 199 | Unused +* BA2 + 0x000000 | BA2 + 0xC0000000 | 3 GB | 196-198 | Frametable
... this one. Otoh I'd expect both to potentially be much larger in SV48 and SV57 modes.
xen/arch/riscv/include/asm/config.h line 58
Quoted 6 lines
xen/arch/riscv/include/asm/config.h +5
-0+* ... | 1 GB | 195 | Unused +* BA3 + 0x000000 | BA3 + 0x40000000 | 1 GB | 194 | VMAP +* ... | 194 GB | 0 - 193 | Unused +* =============================================================================== */ +#define VPN_BITS (9)
This need to move ...
xen/arch/riscv/include/asm/config.h line 62
Quoted 3 lines
xen/arch/riscv/include/asm/config.h +3
-0+#define HYP_PT_ROOT_LEVEL (CONFIG_PAGING_LEVELS - 1) + +#ifdef CONFIG_RISCV_64
... here, I think, for not being applicable to SV32?
xen/arch/riscv/include/asm/config.h line 66
Quoted 3 lines
xen/arch/riscv/include/asm/config.h +3
-0+#define SLOTN_ENTRY_BITS (HYP_PT_ROOT_LEVEL * VPN_BITS + PAGE_SHIFT) +#define SLOTN (slot) (_AT(vaddr_t, slot) << SLOTN_ENTRY_BITS) +#define SLOTN_ENTRY_SIZE SLOTN(1)
Do you have any example of how/where this going to be used?
xen/arch/riscv/include/asm/config.h line 68
Quoted 1 line
xen/arch/riscv/include/asm/config.h +1
-0+#define XEN_VIRT_START 0xFFFFFFFFC0000000/* (_AC(-1, UL) + 1 - GB(1)) */
Won't /* -GB(1) */ do, thus allowing the line to also be padded such that it matches neighboring ones in layout?
Jan
Quoted 8 lines
xen/arch/riscv/include/asm/config.h +7
-0+#define FRAMETABLE_VIRT_START SLOTN(196) +#define FRAMETABLE_SIZE GB(3) +#define FRAMETABLE_NR (FRAMETABLE_SIZE / sizeof(*frame_table)) +#define FRAMETABLE_VIRT_END (FRAMETABLE_VIRT_START + FRAMETABLE_SIZE - 1) + +#define VMAP_VIRT_START SLOTN(194) +#define VMAP_VIRT_SIZE GB(1)
Re: [PATCH v3 27/34] xen/riscv: define an address of frame table
Quoted 120 lines · Jan Beulich
Quoted 107 lines · Oleksii Kurochko
Also, the patch adds some helpful macros that assist in avoiding the redefinition of memory layout for each MMU mode.
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- dropOFFSET_BITS, and usePAGE_SHIFTinstead.
- code style fixes.
- add comment how macros are useful.
- move all memory related layout definitions close to comment with memory layout description.
- make memory layout description generic for any MMU mode.
---
Changes in V2:
- Nothing changed. Only rebase.
---
xen/arch/riscv/include/asm/config.h | 85 +++++++++++++++++++------
----1 file changed, 55 insertions(+), 30 deletions(-)xen/arch/riscv/include/asm/config.h +0
-0@@ -6,6 +6,14 @@ #include <xen/const.h> #include <xen/page-size.h>xen/arch/riscv/include/asm/config.h +8
-0+#ifdef CONFIG_RISCV_64 +#define CONFIG_PAGING_LEVELS 3 +#define RV_STAGE1_MODE SATP_MODE_SV39 +#else +#define CONFIG_PAGING_LEVELS 2 +#define RV_STAGE1_MODE SATP_MODE_SV32 +#endif +/*
* RISC-V64 Layout:
*xen/arch/riscv/include/asm/config.h +0
-0@@ -22,25 +30,56 @@ * * It means that: * top VA bits are simply ignored for the purpose of translatingto PA.
+#endif
*
- *
===================================================================
=========
- * Start addr | End addr | Size | Slot |area description
- *
===================================================================
=========
- * FFFFFFFFC0800000 | FFFFFFFFFFFFFFFF |1016 MB | L2 511 | Unused
- * FFFFFFFFC0600000 | FFFFFFFFC0800000 | 2 MB | L2 511 | Fixmap
- * FFFFFFFFC0200000 | FFFFFFFFC0600000 | 4 MB | L2 511 | FDT
- * FFFFFFFFC0000000 | FFFFFFFFC0200000 | 2 MB | L2 511 | Xen
- * ... | 1 GB | L2 510 | Unused
- * 0000003200000000 | 0000007F80000000 | 309 GB | L2 200-509 | Direct map
- * ... | 1 GB | L2 199 | Unused
- * 0000003100000000 | 00000031C0000000 | 3 GB | L2 196-198 | Frametable
- * ... | 1 GB | L2 195 | Unused
- * 0000003080000000 | 00000030C0000000 | 1 GB | L2 194 | VMAP
- * ... | 194 GB | L2 0 - 193 | Unused
- *
===================================================================
=========
+ * SATP_MODE_SV32 | SATP_MODE_SV39 | SATP_MODE_SV48 |SATP_MODE_SV57
+ * ==================|==================|==================|==========
=======
+ * BA0 | FFFFFFFFFFE00000 | FFFFFFFFC0000000 | FFFFFF8000000000 | FFFF000000000000
+ * BA1 | 0000000019000000 | 0000003200000000 | 0000640000000000 | 00C8000000000000
+ * BA2 | 0000000018800000 | 0000003100000000 | 0000620000000000 | 00C4000000000000
+ * BA3 | 0000000018400000 | 0000003080000000 | 0000610000000000 | 00C2000000000000
*
-#endif
+ *
===================================================================
============
+ * Start addr | End addr | Size | Root PT slot | Area description
+ *
===================================================================
============
+ * BA0 +0x800000| FFFFFFFFFFFFFFFF |1016 MB | 511 | Unused
+ * BA0 +0x400000| BA0 + 0x800000 | 2 MB | 511 | FixmapQuoted 8 lines
+ * BA0 +
0x200000| BA0 + 0x400000 | 4 MB | 511 | FDT
+ * BA0 | BA0 + 0x200000 | 2 MB | 511 | Xen
+ * ... | 1 GB | 510 | Unused
+ * BA1 +0x000000| BA1 +0x4D80000000| 309 GB | 200-509 | Direct mapThis definitely can't be right for SV32. Others may be problematic, too, like ...
Quoted 7 lines
Quoted 4 lines
+ * ... | 1 GB | 199 | Unused
+ * BA2 +0x000000| BA2 + 0xC0000000 | 3 GB | 196-198 | Frametable... this one. Otoh I'd expect both to potentially be much larger in SV48 and SV57 modes.
Regarding Sv32, it looks to me the only BA0 and End addr at the first line isn't correct as address size is 32.
Regarding other modes, yes, it should be changed Size column. Also, the size of frame table should be recalculated.
Do we really need size column?
Wouldn't it be enough only have PT slot number?
Would it be better to have separate table for each mode?
Probably, it would be more useful to print memory map to Xen console.
Quoted 13 lines
Quoted 12 lines
+ * ... | 1 GB | 195 | Unused
+ * BA3 +0x000000| BA3 + 0x40000000 | 1 GB | 194 | VMAP
+ * ... | 194 GB | 0 - 193 | Unused
+ *
===================================================================
============
*/
+#define VPN_BITS (9)
Quoted 7 lines
This need to move ...
xen/arch/riscv/include/asm/config.h line 62
Quoted 3 lines
xen/arch/riscv/include/asm/config.h +3
-0+#define HYP_PT_ROOT_LEVEL (CONFIG_PAGING_LEVELS - 1) + +#ifdef CONFIG_RISCV_64 ... here, I think, for not being applicable to SV32?
You are right, it is not applicable for Sv32. In case of Sv32, it should be 10.
But I am not sure that it is correct only to move this definition as RISCV-64 can also use Sv32. So it looks like VPN_BITS should be "#ifdef RV_STAGE1_MODE == Sv32".
Quoted 8 lines
Quoted 6 lines
+#define SLOTN_ENTRY_BITS (
HYP_PT_ROOT_LEVEL*VPN_BITS+PAGE_SHIFT)
+#define SLOTN(slot) (_AT(vaddr_t, slot)<<SLOTN_ENTRY_BITS)
+#define SLOTN_ENTRY_SIZE SLOTN(1)Do you have any example of how/where this going to be used?
Yes, it will be used to define DIRECTMAP_SIZE:
#define DIRECTMAP_SIZE (SLOTN_ENTRY_SIZE * (509-200))
Quoted 7 lines
Quoted 3 lines
+#define
XEN_VIRT_START0xFFFFFFFFC0000000/* (_AC(-1, UL)+ 1 - GB(1)) */Won't /* -GB(1) */ do, thus allowing the line to also be padded such that
it matches neighboring ones in layout?
Could you please clarify what do you mean by padded here? The intention was to show that 1 GB is used for Xen, FDT and fixmap.
~ Oleksii
Quoted 12 lines
Quoted 11 lines
xen/arch/riscv/include/asm/config.h +3
-0+#define FRAMETABLE_VIRT_START SLOTN(196) +#define FRAMETABLE_SIZE GB(3) +#define FRAMETABLE_NR (FRAMETABLE_SIZE /
sizeof(*frame_table))
+#define FRAMETABLE_VIRT_END (FRAMETABLE_VIRT_START+FRAMETABLE_SIZE- 1)xen/arch/riscv/include/asm/config.h +3
-0+ +#define VMAP_VIRT_START SLOTN(194) +#define VMAP_VIRT_SIZE GB(1)
Re: [PATCH v3 27/34] xen/riscv: define an address of frame table
Quoted 91 lines · Oleksii
Quoted 80 lines · Jan Beulich
Quoted 67 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/config.h +0
-0@@ -22,25 +30,56 @@ * * It means that: * top VA bits are simply ignored for the purpose of translatingto PA.
+#endif
*
- *
===================================================================
=========
- * Start addr | End addr | Size | Slot |area description
- *
===================================================================
=========
- * FFFFFFFFC0800000 | FFFFFFFFFFFFFFFF |1016 MB | L2 511 | Unused
- * FFFFFFFFC0600000 | FFFFFFFFC0800000 | 2 MB | L2 511 | Fixmap
- * FFFFFFFFC0200000 | FFFFFFFFC0600000 | 4 MB | L2 511 | FDT
- * FFFFFFFFC0000000 | FFFFFFFFC0200000 | 2 MB | L2 511 | Xen
- * ... | 1 GB | L2 510 | Unused
- * 0000003200000000 | 0000007F80000000 | 309 GB | L2 200-509 | Direct map
- * ... | 1 GB | L2 199 | Unused
- * 0000003100000000 | 00000031C0000000 | 3 GB | L2 196-198 | Frametable
- * ... | 1 GB | L2 195 | Unused
- * 0000003080000000 | 00000030C0000000 | 1 GB | L2 194 | VMAP
- * ... | 194 GB | L2 0 - 193 | Unused
- *
===================================================================
=========
+ * SATP_MODE_SV32 | SATP_MODE_SV39 | SATP_MODE_SV48 |SATP_MODE_SV57
+ * ==================|==================|==================|==========
=======
+ * BA0 | FFFFFFFFFFE00000 | FFFFFFFFC0000000 | FFFFFF8000000000 | FFFF000000000000
+ * BA1 | 0000000019000000 | 0000003200000000 | 0000640000000000 | 00C8000000000000
+ * BA2 | 0000000018800000 | 0000003100000000 | 0000620000000000 | 00C4000000000000
+ * BA3 | 0000000018400000 | 0000003080000000 | 0000610000000000 | 00C2000000000000
*
-#endif
+ *
===================================================================
============
+ * Start addr | End addr | Size | Root PT slot | Area description
+ *
===================================================================
============
+ * BA0 +0x800000| FFFFFFFFFFFFFFFF |1016 MB | 511 | Unused
+ * BA0 +0x400000| BA0 + 0x800000 | 2 MB | 511 | FixmapQuoted 8 lines
+ * BA0 +
0x200000| BA0 + 0x400000 | 4 MB | 511 | FDT
+ * BA0 | BA0 + 0x200000 | 2 MB | 511 | Xen
+ * ... | 1 GB | 510 | Unused
+ * BA1 +0x000000| BA1 +0x4D80000000| 309 GB | 200-509 | Direct mapThis definitely can't be right for SV32. Others may be problematic, too, like ...
Quoted 7 lines
Quoted 4 lines
+ * ... | 1 GB | 199 | Unused
+ * BA2 +0x000000| BA2 + 0xC0000000 | 3 GB | 196-198 | Frametable... this one. Otoh I'd expect both to potentially be much larger in SV48 and SV57 modes.
Regarding Sv32, it looks to me the only BA0 and End addr at the first line isn't correct as address size is 32.
Quoted 6 lines
Regarding other modes, yes, it should be changed Size column. Also, the size of frame table should be recalculated.
Do we really need size column?
Wouldn't it be enough only have PT slot number?
Perhaps.
Quoted 1 line
Would it be better to have separate table for each mode?
Don't know.
Quoted 9 lines
Quoted 9 lines
Quoted 1 line
+#define VPN_BITS (9)
This need to move ...
xen/arch/riscv/include/asm/config.h line 62
Quoted 3 lines
xen/arch/riscv/include/asm/config.h +3
-0+#define HYP_PT_ROOT_LEVEL (CONFIG_PAGING_LEVELS - 1) + +#ifdef CONFIG_RISCV_64 ... here, I think, for not being applicable to SV32?
Quoted 5 lines
You are right, it is not applicable for Sv32. In case of Sv32, it should be 10.
But I am not sure that it is correct only to move this definition as RISCV-64 can also use Sv32. So it looks likeVPN_BITSshould be "#ifdefRV_STAGE1_MODE== Sv32".
Can it? The spec talks of SXLEN=32 implying SV32, while SXLEN=64 permits SV39, SV48, and SV57. No mention of SV32 there.
Quoted 9 lines
Quoted 7 lines
Quoted 5 lines
+#define SLOTN_ENTRY_BITS (
HYP_PT_ROOT_LEVEL*VPN_BITS+PAGE_SHIFT)
+#define SLOTN(slot) (_AT(vaddr_t, slot)<<SLOTN_ENTRY_BITS)
+#define SLOTN_ENTRY_SIZE SLOTN(1)Do you have any example of how/where this going to be used?
Yes, it will be used to define
DIRECTMAP_SIZE:
#defineDIRECTMAP_SIZE(SLOTN_ENTRY_SIZE* (509-200))
How about
#define DIRECTMAP_SIZE (SLOTN(509) - SLOTN(200))
instead?
Quoted 8 lines
Quoted 6 lines
Quoted 2 lines
+#define
XEN_VIRT_START0xFFFFFFFFC0000000/* (_AC(-1, UL)+ 1 - GB(1)) */Won't /* -GB(1) */ do, thus allowing the line to also be padded such that
it matches neighboring ones in layout?Could you please clarify what do you mean by padded here? The intention was to show that 1 GB is used for Xen, FDT and fixmap.
I'm talking of blank padding in the source file. Note how preceding and following #define-s blank-pad expansions so they all align. Just this one in the middle does not.
Jan
Quoted 12 lines
Quoted 11 lines
Quoted 10 lines
xen/arch/riscv/include/asm/config.h +3
-0+#define FRAMETABLE_VIRT_START SLOTN(196) +#define FRAMETABLE_SIZE GB(3) +#define FRAMETABLE_NR (FRAMETABLE_SIZE /
sizeof(*frame_table))
+#define FRAMETABLE_VIRT_END (FRAMETABLE_VIRT_START+FRAMETABLE_SIZE- 1)xen/arch/riscv/include/asm/config.h +3
-0+ +#define VMAP_VIRT_START SLOTN(194) +#define VMAP_VIRT_SIZE GB(1)
Re: [PATCH v3 27/34] xen/riscv: define an address of frame table
Quoted 133 lines · Jan Beulich
Quoted 132 lines · Oleksii
Quoted 118 lines · Jan Beulich
Quoted 97 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/config.h +0
-0@@ -22,25 +30,56 @@ * * It means that: * top VA bits are simply ignored for the purpose oftranslating
to PA.
+#endif
*
- *
===============================================================
====
=========
- * Start addr | End addr | Size | SlotQuoted 1 line
area description
- *
===============================================================
====
=========
- * FFFFFFFFC0800000 | FFFFFFFFFFFFFFFF |1016 MB | L2 511 |
Unused
- * FFFFFFFFC0600000 | FFFFFFFFC0800000 | 2 MB | L2 511 |
Fixmap
- * FFFFFFFFC0200000 | FFFFFFFFC0600000 | 4 MB | L2 511 |
FDT
- * FFFFFFFFC0000000 | FFFFFFFFC0200000 | 2 MB | L2 511 |
Xen
- * ... | 1 GB | L2 510 |
Unused
- * 0000003200000000 | 0000007F80000000 | 309 GB | L2 200-509 |
Direct map
- * ... | 1 GB | L2 199 |
Unused
- * 0000003100000000 | 00000031C0000000 | 3 GB | L2 196-198 |
Frametable
- * ... | 1 GB | L2 195 |
Unused
- * 0000003080000000 | 00000030C0000000 | 1 GB | L2 194 |
VMAP
- * ... | 194 GB | L2 0 - 193 |
Unused
- *
===============================================================
====
=========
+ * SATP_MODE_SV32 | SATP_MODE_SV39 | SATP_MODE_SV48 |SATP_MODE_SV57
+ * ==================|==================|==================|======
====
=======
+ * BA0 | FFFFFFFFFFE00000 | FFFFFFFFC0000000 | FFFFFF8000000000 |
FFFF000000000000
+ * BA1 | 0000000019000000 | 0000003200000000 | 0000640000000000 |
00C8000000000000
+ * BA2 | 0000000018800000 | 0000003100000000 | 0000620000000000 |
00C4000000000000
+ * BA3 | 0000000018400000 | 0000003080000000 | 0000610000000000 |
00C2000000000000
*
-#endif
+ *
===============================================================
====
============
+ * Start addr | End addr | Size | Root PT slot |
Area description
+ *
===============================================================
====
============
+ * BA0 +0x800000| FFFFFFFFFFFFFFFF |1016 MB | 511 |
Unused
+ * BA0 +0x400000| BA0 + 0x800000 | 2 MB | 511 |
Fixmap
+ * BA0 +0x200000| BA0 + 0x400000 | 4 MB | 511 |
FDT
+ * BA0 | BA0 + 0x200000 | 2 MB |Quoted 8 lines
511 |
Xen
+ * ... | 1 GB | 510 |
Unused
+ * BA1 +0x000000| BA1 +0x4D80000000| 309 GB | 200- 509 |
Direct mapThis definitely can't be right for SV32. Others may be problematic,
too, like ...Quoted 6 lines
+ * ... | 1 GB | 199 |
Unused
+ * BA2 +0x000000| BA2 + 0xC0000000 | 3 GB | 196- 198 |
FrametableQuoted 3 lines
... this one. Otoh I'd expect both to potentially be much larger in
SV48 and SV57 modes.Regarding Sv32, it looks to me the only BA0 and End addr at the first
line isn't correct as address size is 32.Regarding other modes, yes, it should be changed Size column. Also, the
size of frame table should be recalculated.Do we really need size column?
Quoted 7 lines
Quoted 1 line
Wouldn't it be enough only have PT slot number?
Perhaps.
Quoted 1 line
Would it be better to have separate table for each mode?
Don't know.
Then I'll play around different ways to display memory layout.
Quoted 18 lines
Quoted 10 lines
Quoted 10 lines
Quoted 2 lines
+#define VPN_BITS (9)
This need to move ...
xen/arch/riscv/include/asm/config.h line 62
Quoted 3 lines
xen/arch/riscv/include/asm/config.h +3
-0+#define HYP_PT_ROOT_LEVEL (CONFIG_PAGING_LEVELS - 1) + +#ifdef CONFIG_RISCV_64 ... here, I think, for not being applicable to SV32?
Quoted 7 lines
You are right, it is not applicable for Sv32. In case of Sv32, it should be 10.
But I am not sure that it is correct only to move this definition as
RISCV-64 can also use Sv32. So it looks likeVPN_BITSshould be "#ifdefRV_STAGE1_MODE== Sv32".
Quoted 3 lines
Can it? The spec talks of SXLEN=32 implying SV32, while SXLEN=64 permits
SV39, SV48, and SV57. No mention of SV32 there.
According to spec it can't, but when I tried that in baremetal it worked.
Let's stick to the spec, and then it would be better to move VPN_BITS to #ifdef CONFIG_RISCV_64.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 7 lines
(quoted diff) +2
-0+#define SLOTN_ENTRY_BITS (HYP_PT_ROOT_LEVEL * VPN_BITS +
PAGE_SHIFT)
+#define SLOTN(slot) (_AT(vaddr_t, slot)<<SLOTN_ENTRY_BITS)
+#define SLOTN_ENTRY_SIZE SLOTN(1)Do you have any example of how/where this going to be used?
Quoted 8 lines
Quoted 2 lines
Yes, it will be used to define
DIRECTMAP_SIZE:
#define DIRECTMAP_SIZE (SLOTN_ENTRY_SIZE* (509-200))How about
#define DIRECTMAP_SIZE (SLOTN(509) - SLOTN(200))
instead?
It would be better, I'll drop SLOTN_ENTRY_SIZE then. Thanks.
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
Quoted 4 lines
(quoted diff) +1
-1+#define XEN_VIRT_START 0xFFFFFFFFC0000000 /* (_AC(-1, UL) + 1 -GB(1)) */
Won't /* -GB(1) */ do, thus allowing the line to also be padded such
that
it matches neighboring ones in layout?
Quoted 8 lines
Quoted 3 lines
Could you please clarify what do you mean by padded here? The intention
was to show that 1 GB is used for Xen, FDT and fixmap.I'm talking of blank padding in the source file. Note how preceding and
following #define-s blank-pad expansions so they all align. Just this one in the middle does not.
I see what you mean now. Thanks.
~ Oleksii
Quoted 14 lines
Quoted 13 lines
Quoted 12 lines
Quoted 11 lines
xen/arch/riscv/include/asm/config.h +3
-0+#define FRAMETABLE_VIRT_START SLOTN(196) +#define FRAMETABLE_SIZE GB(3) +#define FRAMETABLE_NR (FRAMETABLE_SIZE /
sizeof(*frame_table))
+#define FRAMETABLE_VIRT_END (FRAMETABLE_VIRT_START+FRAMETABLE_SIZE- 1)xen/arch/riscv/include/asm/config.h +3
-0+ +#define VMAP_VIRT_START SLOTN(194) +#define VMAP_VIRT_SIZE GB(1)
PATCH v3 28/34 xen/riscv: add required things to current.h
In reply to Oleksii KurochkoAdd minimal requied things to be able to build full Xen.
---
Changes in V3:
- add SPDX
- drop a forward declaration of struct vcpu;
- update guest_cpu_user_regs() macros
- replace get_processor_id with smp_processor_id
- update the commit message
- code style fixes
---
Changes in V2:
- Nothing changed. Only rebase.
--- xen/arch/riscv/include/asm/current.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+)
xen/arch/riscv/include/asm/current.h +19 -0
@@ -3,6 +3,21 @@#ifndef __ASM_CURRENT_H#define __ASM_CURRENT_H +#include <xen/bug.h> +#include <xen/percpu.h> +#include <asm/processor.h> + +#ifndef __ASSEMBLY__ + +/* Which VCPU is "current" on this PCPU. */ +DECLARE_PER_CPU(struct vcpu *, curr_vcpu); + +#define current this_cpu(curr_vcpu) +#define set_current (vcpu) do { current = (vcpu); } while (0) +#define get_cpu_current (cpu) per_cpu(curr_vcpu, cpu) + +#define guest_cpu_user_regs () ({ BUG(); NULL; }) +#define switch_stack_and_jump (stack, fn) do { \ asm volatile ( \ "mv sp, %0\n" \
@@ -10,4 +25,8 @@unreachable (); \ } while ( false ) +#define get_per_cpu_offset () __per_cpu_offset[smp_processor_id()] + +#endif /* __ASSEMBLY__ */ +#endif /* __ASM_CURRENT_H */
Signature · 1 line
2.43.0
Re: [PATCH v3 28/34] xen/riscv: add required things to current.h
On 22.12.2023 16:13, Oleksii Kurochko wrote:> --- a/xen/arch/riscv/include/asm/current.h
Quoted 9 lines
+++
b/xen/arch/riscv/include/asm/current.hxen/arch/riscv/include/asm/current.h +4
-0@@ -3,6 +3,21 @@#ifndef __ASM_CURRENT_H#define __ASM_CURRENT_H +#include <xen/bug.h> +#include <xen/percpu.h> +#include <asm/processor.h> +
xen/arch/riscv/include/asm/current.h line 19
Quoted 10 lines
xen/arch/riscv/include/asm/current.h +10
-0+#ifndef __ASSEMBLY__ + +/* Which VCPU is "current" on this PCPU. */ +DECLARE_PER_CPU(struct vcpu *, curr_vcpu); + +#define current this_cpu(curr_vcpu) +#define set_current (vcpu) do { current = (vcpu); } while (0) +#define get_cpu_current (cpu) per_cpu(curr_vcpu, cpu) + +#define guest_cpu_user_regs () ({ BUG(); NULL; })
Again with this changed to the "canonical" placeholder:
Jan
Re: [PATCH v3 28/34] xen/riscv: add required things to current.h
Quoted 23 lines · Jan Beulich
On 22.12.2023 16:13, Oleksii Kurochko wrote:> ---
a/xen/arch/riscv/include/asm/current.hQuoted 9 lines
+++
b/xen/arch/riscv/include/asm/current.hxen/arch/riscv/include/asm/current.h +0
-0@@ -3,6 +3,21 @@ #ifndef __ASM_CURRENT_H #define __ASM_CURRENT_Hxen/arch/riscv/include/asm/current.h +4
-0+#include <xen/bug.h> +#include <xen/percpu.h> +#include <asm/processor.h> +xen/arch/riscv/include/asm/current.h line 19
Quoted 10 lines
xen/arch/riscv/include/asm/current.h +10
-0+#ifndef __ASSEMBLY__ + +/* Which VCPU is "current" on this PCPU. */ +DECLARE_PER_CPU(struct vcpu *, curr_vcpu); + +#define current this_cpu(curr_vcpu) +#define set_current (vcpu) do { current = (vcpu); } while (0) +#define get_cpu_current (cpu) per_cpu(curr_vcpu, cpu) + +#define guest_cpu_user_regs () ({ BUG(); NULL; })Again with this changed to the "canonical" placeholder:
Quoted 1 line
Acked-by Jan Beulich <[email protected]>
Thanks. I'll updarte BUG() part.
~ Oleksii
PATCH v3 29/34 xen/riscv: add minimal stuff to page.h to build full Xen
In reply to Oleksii Kurochko---
Changes in V3:
- update the commit message
- add implemetation of PAGE_HYPERVISOR macros
- add Acked-by: Jan Beulich <[email protected]>
- drop definition of pfn_to_addr, and paddr_to_pfn in <asm/mm.h>
---
Changes in V2:
- Nothing changed. Only rebase.
--- xen/arch/riscv/include/asm/mm.h | 3 --- xen/arch/riscv/include/asm/page.h | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 3 deletions(-)
xen/arch/riscv/include/asm/mm.h +0 -3
@@ -5,9 +5,6 @@#include <asm/page-bits.h> -#define pfn_to_paddr (pfn) ((paddr_t)(pfn) << PAGE_SHIFT) -#define paddr_to_pfn (pa) ((unsigned long)((pa) >> PAGE_SHIFT)) -extern unsigned char cpu0_boot_stack[];void setup_initial_pagetables (void );
xen/arch/riscv/include/asm/page.h +22 -0
@@ -6,6 +6,7 @@#ifndef __ASSEMBLY__#include <xen/const.h> +#include <xen/bug.h> #include <xen/types.h> #include <asm/mm.h>
@@ -32,6 +33,10 @@#define PTE_LEAF_DEFAULT (PTE_VALID | PTE_READABLE | PTE_WRITABLE)#define PTE_TABLE (PTE_VALID) +#define PAGE_HYPERVISOR_RW (PTE_VALID | PTE_READABLE | PTE_WRITABLE) + +#define PAGE_HYPERVISOR PAGE_HYPERVISOR_RW +/* Calculate the offsets into the pagetables for a given VA */ #define pt_linear_offset (lvl, va) ((va) >> XEN_PT_LEVEL_SHIFT(lvl))
@@ -46,6 +51,9 @@ typedef struct {#endif } pte_t; +#define pfn_to_paddr (pfn) ((paddr_t)(pfn) << PAGE_SHIFT) +#define paddr_to_pfn (pa) ((unsigned long)((pa) >> PAGE_SHIFT)) +static inline pte_t paddr_to_pte (paddr_t paddr,unsigned int permissions) {
@@ -62,6 +70,20 @@ static inline bool pte_is_valid(pte_t p)return p.pte &PTE_VALID ; } +static inline void invalidate_icache (void ) +{ +BUG (); +} + +#define clear_page (page) memset((void *)(page), 0, PAGE_SIZE) +#define copy_page (dp, sp) memcpy(dp, sp, PAGE_SIZE) + +/* TODO: Flush the dcache for an entire page. */ +static inline void flush_page_to_ram (unsigned long mfn,bool sync_icache) +{ +BUG (); +} +#endif /* __ASSEMBLY__ */ #endif /* _ASM_RISCV_PAGE_H */
Signature · 1 line
2.43.0
Re: [PATCH v3 29/34] xen/riscv: add minimal stuff to page.h to build full Xen
Quoted 5 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>Acked-by Jan Beulich <[email protected]>---
Changes in V3:
- update the commit message
Once again I find this puzzling, considering there's no commit message at all.
Jan
Re: [PATCH v3 29/34] xen/riscv: add minimal stuff to page.h to build full Xen
Quoted 10 lines · Jan Beulich
Quoted 5 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>Acked-by Jan Beulich <[email protected]>---
Changes in V3:
- update the commit messageOnce again I find this puzzling, considering there's no commit message
at all.
By the I meant that asm/page.h was changed to page.h
~ Oleksii
Re: [PATCH v3 29/34] xen/riscv: add minimal stuff to page.h to build full Xen
Quoted 8 lines · Oleksii
Quoted 7 lines · Jan Beulich
Quoted 5 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>Acked-by Jan Beulich <[email protected]>---
Changes in V3:
- update the commit message
Quoted 4 lines
Quoted 3 lines
Once again I find this puzzling, considering there's no commit message
at all.By the I meant that
asm/page.hwas changed topage.h
Oh. Can you say "title" or "subject" when you mean that, and "commit message" (or "description") only when you actually mean the description?
Jan
Re: [PATCH v3 29/34] xen/riscv: add minimal stuff to page.h to build full Xen
Quoted 9 lines · Jan Beulich
Quoted 8 lines · Oleksii
Quoted 7 lines · Jan Beulich
Quoted 5 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>Acked-by Jan Beulich <[email protected]>---
Changes in V3:
- update the commit message
Quoted 8 lines
Quoted 4 lines
Quoted 3 lines
Once again I find this puzzling, considering there's no commit message
at all.By the I meant that
asm/page.hwas changed topage.hOh. Can you say "title" or "subject" when you mean that, and "commit message" (or "description") only when you actually mean the description?
Sure, I'll stick to proposed terminology next time. Thanks.
~ Oleksii
PATCH v3 30/34 xen/riscv: add minimal stuff to processor.h to build full Xen
In reply to Oleksii Kurochko---
Changes in V3:
- Update the commit message
- rename get_processor_id to smp_processor_id
- code style fixes
- update the cpu_relax instruction: use pause instruction instead of div %0, %0, zero
---
Changes in V2:
- Nothing changed. Only rebase.
--- xen/arch/riscv/include/asm/processor.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
xen/arch/riscv/include/asm/processor.h +15 -0
@@ -12,6 +12,9 @@#ifndef __ASSEMBLY__ +/* TODO: need to be implemeted */ +#define smp_processor_id () 0 +/* On stack VCPU state */ struct cpu_user_regs {
@@ -53,6 +56,18 @@ struct cpu_user_regsunsigned long pregs; }; +/* TODO: need to implement */ +#define cpu_to_core (cpu) (0) +#define cpu_to_socket (cpu) (0) + +static inline void cpu_relax (void ) +{ +/* Encoding of the pause instruction */ + __asm__ __volatile__ (".insn 0x100000F" ); + +barrier (); +} +static inline void wfi (void ) { __asm__ __volatile__ ("wfi" );
Signature · 1 line
2.43.0
Re: [PATCH v3 30/34] xen/riscv: add minimal stuff to processor.h to build full Xen
Quoted 4 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- Update the commit message
??? (again)
xen/arch/riscv/include/asm/processor.h struct cpu_user_regs · line 66
Quoted 12 lines
xen/arch/riscv/include/asm/processor.h +8
-0@@ -53,6 +56,18 @@ struct cpu_user_regsunsigned long pregs; }; +/* TODO: need to implement */ +#define cpu_to_core (cpu) (0) +#define cpu_to_socket (cpu) (0) + +static inline void cpu_relax (void ) +{ +/* Encoding of the pause instruction */ + __asm__ __volatile__ (".insn 0x100000F" );
binutils 2.40 knows "pause" - why use .insn then?
xen/arch/riscv/include/asm/processor.h struct cpu_user_regs · line 68
Quoted 1 line
xen/arch/riscv/include/asm/processor.h +1
-0+barrier ();
Why?
Jan
Re: [PATCH v3 30/34] xen/riscv: add minimal stuff to processor.h to build full Xen
Quoted 7 lines · Jan Beulich
Quoted 4 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- Update the commit message??? (again)
The same as with previous. asm/processor.h was changed to processor.h
Quoted 15 lines
xen/arch/riscv/include/asm/processor.h struct cpu_user_regs · line 66
Quoted 13 lines
xen/arch/riscv/include/asm/processor.h +0
-0@@ -53,6 +56,18 @@ struct cpu_user_regs unsigned long pregs; };xen/arch/riscv/include/asm/processor.h +8
-0+/* TODO: need to implement */ +#define cpu_to_core (cpu) (0) +#define cpu_to_socket (cpu) (0) + +static inline void cpu_relax (void ) +{ + /* Encoding of the pause instruction */ + __asm__ __volatile__ ( ".insn 0x100000F" );binutils 2.40 knows "pause" - why use .insn then?
I thought that for this instruction it is needed to have extension ZIHINTPAUSE ( according to Linux Kernel source code [1] ) and to cover older version.
But looking at [2] and considering that I announced that we expected binutils >= 2.40 ( or 2.39 as I mentioned as an reply to patch to README file ) it can be used pause instruction.
Quoted 4 lines
Quoted 2 lines
+
barrier();Why?
Just to be aligned with Linux kernel implemetation from where this function was taken.
~ Oleksii
[1]
https://elixir.bootlin.com/linux/latest/source/arch/riscv/include/asm/vdso/processor.h#L9
[2]https://elixir.bootlin.com/linux/latest/source/arch/riscv/Kconfig#L582
Re: [PATCH v3 30/34] xen/riscv: add minimal stuff to processor.h to build full Xen
Quoted 25 lines · Oleksii
Quoted 7 lines · Jan Beulich
Quoted 4 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- Update the commit message??? (again)
The same as with previous.
asm/processor.hwas changed toprocessor.hQuoted 15 lines
xen/arch/riscv/include/asm/processor.h struct cpu_user_regs · line 66
Quoted 13 lines
xen/arch/riscv/include/asm/processor.h +0
-0@@ -53,6 +56,18 @@ struct cpu_user_regs unsigned long pregs; };xen/arch/riscv/include/asm/processor.h +8
-0+/* TODO: need to implement */ +#define cpu_to_core (cpu) (0) +#define cpu_to_socket (cpu) (0) + +static inline void cpu_relax (void ) +{ + /* Encoding of the pause instruction */ + __asm__ __volatile__ ( ".insn 0x100000F" );binutils 2.40 knows "pause" - why use .insn then?
Quoted 3 lines
I thought that for this instruction it is needed to have extension ZIHINTPAUSE ( according to Linux Kernel source code [1] ) and to cover older version.
Well, of course you'll need to enable the extension then for gas. But as long as you use the insn unconditionally, that's all fine and natural. Another thing would be if you meant to also run on systems not supporting the extension: Then the above use of .insn would need to become conditional anyway.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
+
barrier();Why?
Just to be aligned with Linux kernel implemetation from where this function was taken.
Hmm, looking more closely we have an (open-coded) barrier even on x86. So I suppose it's really wanted (to keep the compiler from moving memory accesses around this construct), but then you may want to consider using
__asm__ __volatile__ ( "pause" ::: "memory" );
here. First and foremost because at least in the general case two separate asm()s aren't the same as one combined one (volatile ones are more restricted, but I'd always err on the safe side, even if just to avoid giving bad examples which later on may be taken as a basis for deriving other code).
Jan
Re: [PATCH v3 30/34] xen/riscv: add minimal stuff to processor.h to build full Xen
Quoted 32 lines · Jan Beulich
Quoted 26 lines · Oleksii
Quoted 7 lines · Jan Beulich
Quoted 4 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- Update the commit message??? (again)
The same as with previous.
asm/processor.hwas changed toprocessor.hQuoted 15 lines
xen/arch/riscv/include/asm/processor.h struct cpu_user_regs · line 66
Quoted 13 lines
xen/arch/riscv/include/asm/processor.h +0
-0@@ -53,6 +56,18 @@ struct cpu_user_regs unsigned long pregs; };xen/arch/riscv/include/asm/processor.h +8
-0+/* TODO: need to implement */ +#define cpu_to_core (cpu) (0) +#define cpu_to_socket (cpu) (0) + +static inline void cpu_relax (void ) +{ + /* Encoding of the pause instruction */ + __asm__ __volatile__ ( ".insn 0x100000F" );binutils 2.40 knows "pause" - why use .insn then?
Quoted 4 lines
I thought that for this instruction it is needed to have extension ZIHINTPAUSE ( according to Linux Kernel source code [1] ) and to cover
older version.
Quoted 5 lines
Well, of course you'll need to enable the extension then for gas. But as long as you use the insn unconditionally, that's all fine and natural. Another thing would be if you meant to also run on systems not supporting the extension: Then the above use of .insn would need to become conditional anyway.
Then it makes sense to use "pause".
Let's assume that for now we are running only on systems which support the extension until we won't face compilation issue for some system.
Quoted 13 lines
Quoted 6 lines
Quoted 4 lines
Quoted 2 lines
+
barrier();Why?
Just to be aligned with Linux kernel implemetation from where this function was taken.
Hmm, looking more closely we have an (open-coded) barrier even on x86.
So I suppose it's really wanted (to keep the compiler from moving memory accesses around this construct), but then you may want to consider using
Quoted 7 lines
__asm____volatile__( "pause" ::: "memory" );here. First and foremost because at least in the general case two separate asm()s aren't the same as one combined one (volatile ones are more restricted, but I'd always err on the safe side, even if just to avoid giving bad examples which later on may be taken as a basis for deriving other code).
It makes sense, I'll update inline assembler line code.
Thanks.
~ Oleksii
Re: [PATCH v3 30/34] xen/riscv: add minimal stuff to processor.h to build full Xen
Quoted 23 lines · Oleksii
Quoted 22 lines · Jan Beulich
Quoted 20 lines · Oleksii
Quoted 15 lines · Jan Beulich
xen/arch/riscv/include/asm/processor.h struct cpu_user_regs · line 66
Quoted 12 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/processor.h +0
-0@@ -53,6 +56,18 @@ struct cpu_user_regs unsigned long pregs; };xen/arch/riscv/include/asm/processor.h +8
-0+/* TODO: need to implement */ +#define cpu_to_core (cpu) (0) +#define cpu_to_socket (cpu) (0) + +static inline void cpu_relax (void ) +{ + /* Encoding of the pause instruction */ + __asm__ __volatile__ ( ".insn 0x100000F" );binutils 2.40 knows "pause" - why use .insn then?
I thought that for this instruction it is needed to have extension ZIHINTPAUSE ( according to Linux Kernel source code [1] ) and to cover
older version.
Quoted 8 lines
Quoted 5 lines
Well, of course you'll need to enable the extension then for gas. But as long as you use the insn unconditionally, that's all fine and natural. Another thing would be if you meant to also run on systems not supporting the extension: Then the above use of .insn would need to become conditional anyway.
Then it makes sense to use "pause".
Let's assume that for now we are running only on systems which support the extension until we won't face compilation issue for some system.
Gives me the impression that you still don't properly separate the two
aspects: One is what systems Xen is to run on, and other is what's needed to make Xen build properly. The first needs documenting (and ideally at some point actually enforcing), while the latter may require e.g. compiler command line option adjustments.
Jan
Re: [PATCH v3 30/34] xen/riscv: add minimal stuff to processor.h to build full Xen
Quoted 40 lines · Jan Beulich
Quoted 33 lines · Oleksii
Quoted 24 lines · Jan Beulich
Quoted 16 lines · Oleksii
Quoted 15 lines · Jan Beulich
xen/arch/riscv/include/asm/processor.h struct cpu_user_regs · line 66
Quoted 12 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/processor.h +0
-0@@ -53,6 +56,18 @@ struct cpu_user_regs unsigned long pregs; };xen/arch/riscv/include/asm/processor.h +8
-0+/* TODO: need to implement */ +#define cpu_to_core (cpu) (0) +#define cpu_to_socket (cpu) (0) + +static inline void cpu_relax (void ) +{ + /* Encoding of the pause instruction */ + __asm__ __volatile__ ( ".insn 0x100000F" );binutils 2.40 knows "pause" - why use .insn then?
Quoted 6 lines
I thought that for this instruction it is needed to have extension
ZIHINTPAUSE ( according to Linux Kernel source code [1] ) and to
cover
older version.Quoted 8 lines
Well, of course you'll need to enable the extension then for gas. But
as long as you use the insn unconditionally, that's all fine and natural. Another thing would be if you meant to also run on systems
not supporting the extension: Then the above use of .insn would need
to become conditional anyway.Quoted 5 lines
Then it makes sense to use "pause".
Let's assume that for now we are running only on systems which support
the extension until we won't face compilation issue for some system.
Quoted 7 lines
Gives me the impression that you still don't properly separate the two
aspects: One is what systems Xen is to run on, and other is what's needed to make Xen build properly. The first needs documenting (and ideally at some point actually enforcing), while the latter may require
e.g. compiler command line option adjustments.
I understand that it will be required update "-march=..._zihintpause" and it should be a check that this extension is supported by a toolchain.
But I am not sure that I know how can I enforce that a system should have this extension, and considering Linux kernel implementation which uses always pause instruction, it looks like all available systems support this extension.
But I agree what I wrote above isn't fully correct.
~ Oleksii
Re: [PATCH v3 30/34] xen/riscv: add minimal stuff to processor.h to build full Xen
Quoted 48 lines · Oleksii
Quoted 40 lines · Jan Beulich
Quoted 33 lines · Oleksii
Quoted 24 lines · Jan Beulich
Quoted 16 lines · Oleksii
Quoted 15 lines · Jan Beulich
Review
Quoted 12 lines · Oleksii Kurochko
(quoted diff) +0
-0@@ -53,6 +56,18 @@ struct cpu_user_regs unsigned long pregs; };(quoted diff) +8
-0+/* TODO: need to implement */ +#define cpu_to_core(cpu) (0) +#define cpu_to_socket(cpu) (0) + +static inline void cpu_relax(void) +{ + /* Encoding of the pause instruction */ + __asm__ __volatile__ ( ".insn 0x100000F" );binutils 2.40 knows "pause" - why use .insn then?
Quoted 6 lines
I thought that for this instruction it is needed to have extension
ZIHINTPAUSE ( according to Linux Kernel source code [1] ) and to
cover
older version.Quoted 8 lines
Well, of course you'll need to enable the extension then for gas. But
as long as you use the insn unconditionally, that's all fine and natural. Another thing would be if you meant to also run on systems
not supporting the extension: Then the above use of .insn would need
to become conditional anyway.Quoted 5 lines
Then it makes sense to use "pause".
Let's assume that for now we are running only on systems which support
the extension until we won't face compilation issue for some system.Quoted 7 lines
Gives me the impression that you still don't properly separate the two
aspects: One is what systems Xen is to run on, and other is what's needed to make Xen build properly. The first needs documenting (and ideally at some point actually enforcing), while the latter may require
e.g. compiler command line option adjustments.
Quoted 8 lines
I understand that it will be required update "-march=..._zihintpause" and it should be a check that this extension is supported by a toolchain.
But I am not sure that I know how can I enforce that a system should have this extension, and considering Linux kernel implementation which uses always pause instruction, it looks like all available systems support this extension.
Which is why I said documenting will suffice, at least for now.
Jan
PATCH v3 31/34 xen/riscv: add minimal stuff to mm.h to build full Xen
In reply to Oleksii Kurochko---
Changes in V3:
- update the commit message
- introduce DIRECTMAP_VIRT_START.
- drop changes related pfn_to_paddr() and paddr_to_pfn as they were remvoe in [PATCH v2 32/39] xen/riscv: add minimal stuff to asm/page.h to build full Xen
- code style fixes.
- drop get_page_nr and put_page_nr as they don't need for time being
- drop CONFIG_STATIC_MEMORY related things
- code style fixes
---
Changes in V2:
- define stub for arch_get_dma_bitsize(void)
--- xen/arch/riscv/include/asm/config.h | 2 + xen/arch/riscv/include/asm/mm.h | 248 ++++++++++++++++++++++++++++ 2 files changed, 250 insertions(+)
xen/arch/riscv/include/asm/config.h +2 -0
@@ -67,6 +67,8 @@#define XEN_VIRT_START 0xFFFFFFFFC0000000/* (_AC(-1, UL) + 1 - GB(1)) */ +#define DIRECTMAP_VIRT_START SLOTN(200) +#define FRAMETABLE_VIRT_START SLOTN(196)#define FRAMETABLE_SIZE GB(3)#define FRAMETABLE_NR (FRAMETABLE_SIZE / sizeof(*frame_table))
xen/arch/riscv/include/asm/mm.h +248 -0
260 lines not on this page · raw message
Signature · 1 line
2.43.0
Re: [PATCH v3 31/34] xen/riscv: add minimal stuff to mm.h to build full Xen
Quoted 314 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- update the commit message
- introduceDIRECTMAP_VIRT_START.
- drop changes relatedpfn_to_paddr()andpaddr_to_pfnas they were remvoe in
[PATCH v2 32/39] xen/riscv: add minimal stuff toasm/page.hto build full Xen
- code style fixes.
- drop get_page_nr andput_page_nras they don't need for time being
- dropCONFIG_STATIC_MEMORYrelated things
- code style fixes
---
Changes in V2:
- define stub forarch_get_dma_bitsize(void)
---
xen/arch/riscv/include/asm/config.h | 2 + xen/arch/riscv/include/asm/mm.h | 248
++++++++++++++++++++++++++++2 files changed, 250 insertions(+)xen/arch/riscv/include/asm/config.h +0
-0@@ -67,6 +67,8 @@
#defineXEN_VIRT_START0xFFFFFFFFC0000000/* (_AC(-1, UL)+ 1 - GB(1)) */xen/arch/riscv/include/asm/config.h +2
-0+#define DIRECTMAP_VIRT_START SLOTN(200) +#define FRAMETABLE_VIRT_START SLOTN(196) #define FRAMETABLE_SIZE GB(3) #define FRAMETABLE_NR (
FRAMETABLE_SIZE/sizeof(*frame_table))xen/arch/riscv/include/asm/mm.h +0
-0@@ -3,8 +3,251 @@ #ifndef _ASM_RISCV_MM_H #define _ASM_RISCV_MM_Hxen/arch/riscv/include/asm/mm.h +5
-0+#include <public/xen.h> +#include <xen/pdx.h> +#include <xen/types.h> + +#include <asm/page.h> #include <
asm/page-bits.h>xen/arch/riscv/include/asm/mm.h +17
-0+#define paddr_to_pdx (pa) mfn_to_pdx(maddr_to_mfn(pa)) +#define gfn_to_gaddr (gfn) pfn_to_paddr(gfn_x(gfn)) +#define gaddr_to_gfn (ga) _gfn(paddr_to_pfn(ga)) +#define mfn_to_maddr (mfn) pfn_to_paddr(mfn_x(mfn)) +#define maddr_to_mfn (ma) _mfn(paddr_to_pfn(ma)) +#define vmap_to_mfn (va) maddr_to_mfn(virt_to_maddr((vaddr_t)va)) +#define vmap_to_page (va) mfn_to_page(vmap_to_mfn(va)) +#define paddr_to_pdx (pa) mfn_to_pdx(maddr_to_mfn(pa)) +#define gfn_to_gaddr (gfn) pfn_to_paddr(gfn_x(gfn)) +#define gaddr_to_gfn (ga) _gfn(paddr_to_pfn(ga)) +#define mfn_to_maddr (mfn) pfn_to_paddr(mfn_x(mfn)) +#define maddr_to_mfn (ma) _mfn(paddr_to_pfn(ma)) +#define vmap_to_mfn (va) maddr_to_mfn(virt_to_maddr((vaddr_t)va)) +#define vmap_to_page (va) mfn_to_page(vmap_to_mfn(va)) + +#define virt_to_maddr (va) ((paddr_t)((vaddr_t)(va) & PADDR_MASK)) +#define maddr_to_virt (pa) ((void *)((paddr_t)(pa) |
DIRECTMAP_VIRT_START))xen/arch/riscv/include/asm/mm.h +2
-0+ +/* Convert between Xen-heap virtual addresses and machine frame numbers. */
xen/arch/riscv/include/asm/mm.h +2
-0+#define __virt_to_mfn (va) (virt_to_maddr(va) >> PAGE_SHIFT) +#define __mfn_to_virt (mfn) maddr_to_virt((paddr_t)(mfn) <<
PAGE_SHIFT)xen/arch/riscv/include/asm/mm.h +2
-0+ +/* Convert between Xen-heap virtual addresses and page-info structures. */
xen/arch/riscv/include/asm/mm.h +8
-0+static inline struct page_info *virt_to_page (const void *v) +{ + BUG(); + return NULL; +} + +/* +* We define non-underscored wrappers for above conversion functions.
+ * These are overriden in various source files while underscored version
+ * remain intact.
+ */xen/arch/riscv/include/asm/mm.h +16
-0+#define virt_to_mfn (va) __virt_to_mfn(va) +#define mfn_to_virt (mfn) __mfn_to_virt(mfn) + +struct page_info +{ + /* Each frame can be threaded onto a doubly-linked list. */ + struct page_list_entry list; + + /* Reference count and various PGC_xxx flags and fields. */ + unsigned long count_info; + + /* Context-dependent fields follow... */ + union { + /* Page is in use: ((count_info & PGC_count_mask) != 0). */ + struct { + /* Type reference count and various PGT_xxx flags andfields. */
+ unsigned longtype_info;
+ } inuse;
+ /* Page is on a free list: ((count_info&PGC_count_mask) == 0). */
+ union {
+ struct {
+ /*
+ * Index of the first *possibly* unscrubbed page in the buddy.
+ * One more bit than maximum possible order to accommodate
+ *INVALID_DIRTY_IDX.
+ */xen/arch/riscv/include/asm/mm.h +4
-0+#define INVALID_DIRTY_IDX ((1UL << (MAX_ORDER + 1)) - 1) + unsigned long first_dirty:MAX_ORDER + 1; + + /* Do TLBs need flushing for safety before next pageuse? */
+ bool need_tlbflush:1;xen/arch/riscv/include/asm/mm.h +22
-0+ +#define BUDDY_NOT_SCRUBBING 0 +#define BUDDY_SCRUBBING 1 +#define BUDDY_SCRUB_ABORT 2 + unsigned long scrub_state:2; + }; + + unsigned long val; + } free; + + } u; + + union { + /* Page is in use, but not as a shadow. */ + struct { + /* Owner of this page (zero if page is anonymous). */ + struct domain *domain; + } inuse; + + /* Page is on a free list. */ + struct { + /* Order-size of the free chunk this page is the headof. */
+ unsigned int order;
+ } free;xen/arch/riscv/include/asm/mm.h +6
-0+ + } v; + + union { + /* +* Timestamp from 'TLB clock', used to avoid extra safety flushes.
+ * Only valid for: a) free pages, and b) pages with zero type count
+ */
+uint32_ttlbflush_timestamp;
+ };
+uint64_tpad;xen/arch/riscv/include/asm/mm.h +8
-0+}; + +#define frame_table ((struct page_info *)FRAMETABLE_VIRT_START) + +/* PDX of the first page in the frame table. */ +extern unsigned long frametable_base_pdx; + +/* Convert between machine frame numbers and page-info structures. */
+#definemfn_to_page(mfn)
\
+ (frame_table+ (mfn_to_pdx(mfn)-frametable_base_pdx)) +#definepage_to_mfn(pg)
\
+pdx_to_mfn((unsigned long)((pg) - frame_table) + frametable_base_pdx)xen/arch/riscv/include/asm/mm.h +9
-0+ +static inline void *page_to_virt (const struct page_info *pg) +{ + return mfn_to_virt(mfn_x(page_to_mfn(pg))); +} + +/* +* Common code requires get_page_type and put_page_type. +* We don't care about typecounts so we just do the minimum to make it
+ * happy.
+ */
+static inline intget_page_type(struct page_info *page, unsigned long type)xen/arch/riscv/include/asm/mm.h +17
-0+{ + return 1; +} + +static inline void put_page_type (struct page_info *page) +{ +} + +static inline void put_page_and_type (struct page_info *page) +{ + put_page_type(page); + put_page(page); +} + +/* +* RISC-V does not have an M2P, but common code expects a handful of +* M2P-related defines and functions. Provide dummy versions of these.
+ */xen/arch/riscv/include/asm/mm.h +6
-0+#define INVALID_M2P_ENTRY (~0UL) +#define SHARED_M2P_ENTRY (~0UL - 1UL) +#define SHARED_M2P (_e) ((_e) == SHARED_M2P_ENTRY) + +/* Xen always owns P2M on RISC-V */ +#define set_gpfn_from_mfn (mfn, pfn) do { (void) (mfn), (void)(pfn);} while (0)
xen/arch/riscv/include/asm/mm.h +5
-0+#define mfn_to_gfn (d, mfn) ((void)(d), _gfn(mfn_x(mfn))) + +#define PDX_GROUP_SHIFT (16 + 5) + +static inline unsigned long domain_get_maximum_gpfn(struct domain*d)
xen/arch/riscv/include/asm/mm.h +6
-0+{ + BUG(); + return 0; +} + +static inline long arch_memory_op(int op,
XEN_GUEST_HANDLE_PARAM(void)arg)xen/arch/riscv/include/asm/mm.h +10
-0+{ + BUG(); + return 0; +} + +/* +* On RISCV, all the RAM is currently direct mapped in Xen. +* Hence return always true. +*/ +static inline bool arch_mfns_in_directmap(unsigned long mfn,unsigned long nr)
xen/arch/riscv/include/asm/mm.h +8
-0+{ + return true; +} + +#define PG_shift (idx) (BITS_PER_LONG - (idx)) +#define PG_mask (x, idx) (x ## UL << PG_shift(idx)) + +#define PGT_none PG_mask(0, 1)/* no special uses of this page */
+#definePGT_writable_pagePG_mask(1, 1)/* has writable mappings? */
+#define PGT_type_maskPG_mask(1, 1)/* Bits 31 or 63. */xen/arch/riscv/include/asm/mm.h +7
-0+ +/* Count of uses of this frame as its current type. */ +#define PGT_count_width PG_shift(2) +#define PGT_count_mask ((1UL<<PGT_count_width)-1) + +/* +* Page needs to be scrubbed. Since this bit can only be set on a page that is
+ * free (i.e. inPGC_state_free) we can reusePGC_allocatedbit.
+ */xen/arch/riscv/include/asm/mm.h +13
-0+#define _PGC_need_scrub _PGC_allocated +#define PGC_need_scrub PGC_allocated + +// /* Cleared when the owning guest 'frees' this page. */ +#define _PGC_allocated PG_shift(1) +#define PGC_allocated PG_mask(1, 1) + /* Page is Xen heap? */ +#define _PGC_xen_heap PG_shift(2) +#define PGC_xen_heap PG_mask(1, 2) +/* Page is broken? */ +#define _PGC_broken PG_shift(7) +#define PGC_broken PG_mask(1, 7) +/* Mutually-exclusive page states: { inuse, offlining, offlined, free }. */
xen/arch/riscv/include/asm/mm.h +6
-0+#define PGC_state PG_mask(3, 9) +#define PGC_state_inuse PG_mask(0, 9) +#define PGC_state_offlining PG_mask(1, 9) +#define PGC_state_offlined PG_mask(2, 9) +#define PGC_state_free PG_mask(3, 9) +// #define page_state_is(pg, st) (((pg)->count_info&PGC_state) == PGC_state_##st)
xen/arch/riscv/include/asm/mm.h +6
-0+ +/* Count of references to this frame. */ +#define PGC_count_width PG_shift(9) +#define PGC_count_mask ((1UL<<PGC_count_width)-1) + +#define page_state_is (pg, st) (((pg)->count_info&PGC_state) ==PGC_state_##st)
xen/arch/riscv/include/asm/mm.h +14
-0+ +#define _PGC_extra PG_shift(10) +#define PGC_extra PG_mask(1, 10) + +#define is_xen_heap_page (page) ((page)->count_info & PGC_xen_heap) +#define is_xen_heap_mfn (mfn) \ + (mfn_valid(mfn) && is_xen_heap_page(mfn_to_page(mfn))) + +#define is_xen_fixed_mfn (mfn) \ + ((mfn_to_maddr(mfn) >= virt_to_maddr(&_start)) && \ + (mfn_to_maddr(mfn) <= virt_to_maddr((vaddr_t)_end - 1))) + +#define page_get_owner (_p) (_p)->v.inuse.domain +#define page_set_owner (_p,_d) ((_p)->v.inuse.domain = (_d))
xen/arch/riscv/include/asm/mm.h line 249
Quoted 10 lines
xen/arch/riscv/include/asm/mm.h +10
-0+ +/* TODO: implement */ +#define mfn_valid (mfn) ({ (void) (mfn); 0; }) + +#define mfn_to_gfn (d, mfn) ((void)(d), _gfn(mfn_x(mfn))) + +#define domain_set_alloc_bitsize (d) ((void)0) +#define domain_clamp_alloc_bitsize (d, b) (b) + +#define PFN_ORDER (_pfn) ((_pfn)->v.free.order)
I missed saving these changes. It should be _pfn -> pfn_. (Just a reminder for me).
Sorry for the inconvenience.
Quoted 14 lines
+
extern unsigned char cpu0_boot_stack[];
voidsetup_initial_pagetables(void);xen/arch/riscv/include/asm/mm.h +0
-0@@ -17,4 +260,9 @@ unsigned long calc_phys_offset(void);
voidturn_on_mmu(unsigned long ra);xen/arch/riscv/include/asm/mm.h +5
-0+static inline unsigned int arch_get_dma_bitsize (void ) +{ + return 32; /* TODO */ +} +#endif /*
_ASM_RISCV_MM_H*/
Re: [PATCH v3 31/34] xen/riscv: add minimal stuff to mm.h to build full Xen
Quoted 68 lines · Oleksii
Quoted 68 lines
xen/arch/riscv/include/asm/mm.h +12
-0+ +struct page_info +{ + /* Each frame can be threaded onto a doubly-linked list. */ + struct page_list_entry list; + + /* Reference count and various PGC_xxx flags and fields. */ + unsigned long count_info; + + /* Context-dependent fields follow... */ + union { + /* Page is in use: ((count_info & PGC_count_mask) != 0).*/
+ struct {
+ /* Type reference count and variousPGT_xxxflags and fields. */
+ unsigned longtype_info;
+ } inuse;
+ /* Page is on a free list: ((count_info&PGC_count_mask) ==
0). */
+ union {
+ struct {
+ /*
+ * Index of the first *possibly* unscrubbed page in
the buddy.
+ * One more bit than maximum possible order to accommodate
+ *INVALID_DIRTY_IDX.
+ */xen/arch/riscv/include/asm/mm.h +4
-0+#define INVALID_DIRTY_IDX ((1UL << (MAX_ORDER + 1)) - 1) + unsigned long first_dirty:MAX_ORDER + 1; + + /* Do TLBs need flushing for safety before nextpage
use? */
+ bool need_tlbflush:1;xen/arch/riscv/include/asm/mm.h +22
-0+ +#define BUDDY_NOT_SCRUBBING 0 +#define BUDDY_SCRUBBING 1 +#define BUDDY_SCRUB_ABORT 2 + unsigned long scrub_state:2; + }; + + unsigned long val; + } free; + + } u; + + union { + /* Page is in use, but not as a shadow. */ + struct { + /* Owner of this page (zero if page is anonymous). */ + struct domain *domain; + } inuse; + + /* Page is on a free list. */ + struct { + /* Order-size of the free chunk this page is the headof. */
+ unsigned int order;
+ } free;xen/arch/riscv/include/asm/mm.h +5
-0+ + } v; + + union { + /*
Quoted 8 lines
Quoted 8 lines
+ * Timestamp from 'TLB clock', used to avoid extra safety flushes.
+ * Only valid for: a) free pages, and b) pages with zero type count
+ */
+uint32_ttlbflush_timestamp;
+ };
+uint64_tpad;
I think it can be removed too. The changes weren't saved. ( Just another one reminder for me ).
Sorry for the convenience.
~ Oleksii
Quoted 1 line
Re: [PATCH v3 31/34] xen/riscv: add minimal stuff to mm.h to build full Xen
In reply to OleksiiQuoted 3 lines · Oleksii
Quoted 1 line
+#define
PFN_ORDER(_pfn)((_pfn)->v.free.order)I missed saving these changes. It should be
_pfn->pfn_. (Just a reminder for me).
And what purpose would the trailing underscore serve here?
Jan
Re: [PATCH v3 31/34] xen/riscv: add minimal stuff to mm.h to build full Xen
Quoted 6 lines · Jan Beulich
Quoted 3 lines · Oleksii
Quoted 1 line
+#define
PFN_ORDER(_pfn)((_pfn)->v.free.order)I missed saving these changes. It should be
_pfn->pfn_. (Just a reminder for me).And what purpose would the trailing underscore serve here?
There is no any. I'll use just pfn. Thanks for noticing that.
~ Oleksii
Re: [PATCH v3 31/34] xen/riscv: add minimal stuff to mm.h to build full Xen
In reply to Oleksii KurochkoQuoted 4 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- update the commit message
??? (yet again)
Quoted 10 lines
xen/arch/riscv/include/asm/mm.h +4
-0@@ -3,8 +3,251 @@#ifndef _ASM_RISCV_MM_H#define _ASM_RISCV_MM_H +#include <public/xen.h> +#include <xen/pdx.h> +#include <xen/types.h> +
xen/arch/riscv/include/asm/mm.h line 19
Quoted 10 lines
xen/arch/riscv/include/asm/mm.h +8
-0+#include <asm/page.h> #include <asm/page-bits.h> +#define paddr_to_pdx (pa) mfn_to_pdx(maddr_to_mfn(pa)) +#define gfn_to_gaddr (gfn) pfn_to_paddr(gfn_x(gfn)) +#define gaddr_to_gfn (ga) _gfn(paddr_to_pfn(ga)) +#define mfn_to_maddr (mfn) pfn_to_paddr(mfn_x(mfn)) +#define maddr_to_mfn (ma) _mfn(paddr_to_pfn(ma)) +#define vmap_to_mfn (va) maddr_to_mfn(virt_to_maddr((vaddr_t)va)) +#define vmap_to_page (va) mfn_to_page(vmap_to_mfn(va))
Everything you have above ...
xen/arch/riscv/include/asm/mm.h line 19
Quoted 7 lines
xen/arch/riscv/include/asm/mm.h +7
-0+#define paddr_to_pdx (pa) mfn_to_pdx(maddr_to_mfn(pa)) +#define gfn_to_gaddr (gfn) pfn_to_paddr(gfn_x(gfn)) +#define gaddr_to_gfn (ga) _gfn(paddr_to_pfn(ga)) +#define mfn_to_maddr (mfn) pfn_to_paddr(mfn_x(mfn)) +#define maddr_to_mfn (ma) _mfn(paddr_to_pfn(ma)) +#define vmap_to_mfn (va) maddr_to_mfn(virt_to_maddr((vaddr_t)va)) +#define vmap_to_page (va) mfn_to_page(vmap_to_mfn(va))
... appears a 2nd time right afterwards.
xen/arch/riscv/include/asm/mm.h line 33
Quoted 6 lines
xen/arch/riscv/include/asm/mm.h +6
-0+#define virt_to_maddr (va) ((paddr_t)((vaddr_t)(va) & PADDR_MASK)) +#define maddr_to_virt (pa) ((void *)((paddr_t)(pa) | DIRECTMAP_VIRT_START)) + +/* Convert between Xen-heap virtual addresses and machine frame numbers. */ +#define __virt_to_mfn (va) (virt_to_maddr(va) >> PAGE_SHIFT) +#define __mfn_to_virt (mfn) maddr_to_virt((paddr_t)(mfn) << PAGE_SHIFT)
These would imo better use maddr_to_mfn() and mfn_to_maddr(), rather than kind of open-coding them. The former could also use PFN_DOWN() as an alternative.
Quoted 4 lines
xen/arch/riscv/include/asm/mm.h +4
-0+/* Convert between Xen-heap virtual addresses and page-info structures. */ +static inline struct page_info *virt_to_page (const void *v) +{ +BUG ();
xen/arch/riscv/include/asm/mm.h line 48
Quoted 10 lines
xen/arch/riscv/include/asm/mm.h +10
-0+return NULL ; +} + +/* +* We define non-underscored wrappers for above conversion functions. +* These are overriden in various source files while underscored version +* remain intact. +*/ +#define virt_to_mfn (va) __virt_to_mfn(va) +#define mfn_to_virt (mfn) __mfn_to_virt(mfn)
Is this really still needed? Would be pretty nice if in a new port we could get to start cleanly right away (i.e. by not needing per-file overrides, but using type-safe expansions here right away).
Quoted 27 lines
xen/arch/riscv/include/asm/mm.h +27
-0+struct page_info +{ + /* Each frame can be threaded onto a doubly-linked list. */ + struct page_list_entry list; + + /* Reference count and various PGC_xxx flags and fields. */ + unsigned long count_info; + + /* Context-dependent fields follow... */ + union { + /* Page is in use: ((count_info & PGC_count_mask) != 0). */ + struct { + /* Type reference count and various PGT_xxx flags and fields. */ + unsigned long type_info; + } inuse; + /* Page is on a free list: ((count_info & PGC_count_mask) == 0). */ + union { + struct { + /* + * Index of the first *possibly* unscrubbed page in the buddy. + * One more bit than maximum possible order to accommodate + * INVALID_DIRTY_IDX. + */ +#define INVALID_DIRTY_IDX ((1UL << (MAX_ORDER + 1)) - 1) + unsigned long first_dirty:MAX_ORDER + 1; + + /* Do TLBs need flushing for safety before next page use? */
xen/arch/riscv/include/asm/mm.h line 86
Quoted 10 lines
xen/arch/riscv/include/asm/mm.h +10
-0+ bool need_tlbflush:1; + +#define BUDDY_NOT_SCRUBBING 0 +#define BUDDY_SCRUBBING 1 +#define BUDDY_SCRUB_ABORT 2 + unsigned long scrub_state:2; + }; + +unsigned long val; + } free;
Indentation is wrong (and thus misleading) for these two lines.
xen/arch/riscv/include/asm/mm.h line 85
Quoted 2 lines
xen/arch/riscv/include/asm/mm.h +2
-0+ + } u;
Nit: I don't see the value of the trailing blank line inside the union.
xen/arch/riscv/include/asm/mm.h line 87
Quoted 2 lines
xen/arch/riscv/include/asm/mm.h +2
-0+union { +/* Page is in use, but not as a shadow. */
I question the appicability of "shadow" here.
Quoted 17 lines
xen/arch/riscv/include/asm/mm.h +17
-0+struct { +/* Owner of this page (zero if page is anonymous). */ +struct domain *domain; + } inuse; + +/* Page is on a free list. */ +struct { +/* Order-size of the free chunk this page is the head of. */ +unsigned int order; + } free; + + } v; + +union { +/* +* Timestamp from 'TLB clock', used to avoid extra safety flushes. +* Only valid for: a) free pages, and b) pages with zero type count
xen/arch/riscv/include/asm/mm.h line 118
Quoted 10 lines
xen/arch/riscv/include/asm/mm.h +10
-0+*/ +uint32_t tlbflush_timestamp; + }; +uint64_t pad; +}; + +#define frame_table ((struct page_info *)FRAMETABLE_VIRT_START) + +/* PDX of the first page in the frame table. */ +extern unsigned long frametable_base_pdx;
From this I conclude memory on RISC-V systems may not start at (or near) 0?
Quoted 31 lines
xen/arch/riscv/include/asm/mm.h +31
-0+/* Convert between machine frame numbers and page-info structures. */ +#define mfn_to_page (mfn) \ + (frame_table + (mfn_to_pdx(mfn) - frametable_base_pdx)) +#define page_to_mfn (pg) \ + pdx_to_mfn((unsigned long)((pg) - frame_table) + frametable_base_pdx) + +static inline void *page_to_virt (const struct page_info *pg) +{ +return mfn_to_virt (mfn_x (page_to_mfn (pg))); +} + +/* +* Common code requires get_page_type and put_page_type. +* We don't care about typecounts so we just do the minimum to make it +* happy. +*/ +static inline int get_page_type (struct page_info *page,unsigned long type) +{ +return 1 ; +} + +static inline void put_page_type (struct page_info *page) +{ +} + +static inline void put_page_and_type (struct page_info *page) +{ +put_page_type (page); +put_page (page); +} +
xen/arch/riscv/include/asm/mm.h line 160
Quoted 10 lines
xen/arch/riscv/include/asm/mm.h +10
-0+/* +* RISC-V does not have an M2P, but common code expects a handful of +* M2P-related defines and functions. Provide dummy versions of these. +*/ +#define INVALID_M2P_ENTRY (~0UL) +#define SHARED_M2P_ENTRY (~0UL - 1UL) +#define SHARED_M2P (_e) ((_e) == SHARED_M2P_ENTRY) + +/* Xen always owns P2M on RISC-V */ +#define set_gpfn_from_mfn (mfn, pfn) do { (void) (mfn), (void)(pfn); } while (0)
Nit: Stray blank again after cast.
xen/arch/riscv/include/asm/mm.h line 156
Quoted 1 line
xen/arch/riscv/include/asm/mm.h +1
-0+#define mfn_to_gfn (d, mfn) ((void)(d), _gfn(mfn_x(mfn)))
What's the relation of the comment with these two #define-s?
Quoted 23 lines
xen/arch/riscv/include/asm/mm.h +23
-0+#define PDX_GROUP_SHIFT (16 + 5) + +static inline unsigned long domain_get_maximum_gpfn (struct domain *d) +{ +BUG (); +return 0 ; +} + +static inline long arch_memory_op (int op,XEN_GUEST_HANDLE_PARAM (void ) arg) +{ +BUG (); +return 0 ; +} + +/* +* On RISCV, all the RAM is currently direct mapped in Xen. +* Hence return always true. +*/ +static inline bool arch_mfns_in_directmap (unsigned long mfn,unsigned long nr) +{ +return true; +} +
xen/arch/riscv/include/asm/mm.h line 195
Quoted 10 lines
xen/arch/riscv/include/asm/mm.h +10
-0+#define PG_shift (idx) (BITS_PER_LONG - (idx)) +#define PG_mask (x, idx) (x ## UL << PG_shift(idx)) + +#define PGT_none PG_mask(0, 1)/* no special uses of this page */ +#define PGT_writable_page PG_mask(1, 1)/* has writable mappings? */ +#define PGT_type_mask PG_mask(1, 1)/* Bits 31 or 63. */ + +/* Count of uses of this frame as its current type. */ +#define PGT_count_width PG_shift(2) +#define PGT_count_mask ((1UL<<PGT_count_width)-1)
Nit: Style (missing blanks around binary operators). Also a few more times further down.
xen/arch/riscv/include/asm/mm.h line 204
Quoted 8 lines
xen/arch/riscv/include/asm/mm.h +8
-0+/* +* Page needs to be scrubbed. Since this bit can only be set on a page that is +* free (i.e. in PGC_state_free) we can reuse PGC_allocated bit. +*/ +#define _PGC_need_scrub _PGC_allocated +#define PGC_need_scrub PGC_allocated + +// /* Cleared when the owning guest 'frees' this page. */
Why a commented out comment?
xen/arch/riscv/include/asm/mm.h line 213
Quoted 9 lines
xen/arch/riscv/include/asm/mm.h +9
-0+#define _PGC_allocated PG_shift(1) +#define PGC_allocated PG_mask(1, 1) +/* Page is Xen heap? */ +#define _PGC_xen_heap PG_shift(2) +#define PGC_xen_heap PG_mask(1, 2) +/* Page is broken? */ +#define _PGC_broken PG_shift(7) +#define PGC_broken PG_mask(1, 7) +/* Mutually-exclusive page states: { inuse, offlining, offlined, free }. */
Can similar comments in this block please all be similarly indented (or not)?
xen/arch/riscv/include/asm/mm.h line 219
Quoted 6 lines
xen/arch/riscv/include/asm/mm.h +6
-0+#define PGC_state PG_mask(3, 9) +#define PGC_state_inuse PG_mask(0, 9) +#define PGC_state_offlining PG_mask(1, 9) +#define PGC_state_offlined PG_mask(2, 9) +#define PGC_state_free PG_mask(3, 9) +// #define page_state_is(pg, st) (((pg)->count_info&PGC_state) == PGC_state_##st)
???
xen/arch/riscv/include/asm/mm.h line 225
Quoted 5 lines
xen/arch/riscv/include/asm/mm.h +5
-0+/* Count of references to this frame. */ +#define PGC_count_width PG_shift(9) +#define PGC_count_mask ((1UL<<PGC_count_width)-1) + +#define page_state_is (pg, st) (((pg)->count_info&PGC_state) == PGC_state_##st)
And here it then "properly" appears?
xen/arch/riscv/include/asm/mm.h line 236
Quoted 10 lines
xen/arch/riscv/include/asm/mm.h +10
-0+#define _PGC_extra PG_shift(10) +#define PGC_extra PG_mask(1, 10) + +#define is_xen_heap_page (page) ((page)->count_info & PGC_xen_heap) +#define is_xen_heap_mfn (mfn) \ + (mfn_valid(mfn) && is_xen_heap_page(mfn_to_page(mfn))) + +#define is_xen_fixed_mfn (mfn) \ + ((mfn_to_maddr(mfn) >= virt_to_maddr(&_start)) && \ + (mfn_to_maddr(mfn) <= virt_to_maddr((vaddr_t)_end - 1)))
Why does _start need prefixing wuth & and _end prefixing with a cast? First and foremost both want to be consistent. And then preferably with as little extra clutter as possible.
xen/arch/riscv/include/asm/mm.h line 244
Quoted 7 lines
xen/arch/riscv/include/asm/mm.h +7
-0+#define page_get_owner (_p) (_p)->v.inuse.domain +#define page_set_owner (_p,_d) ((_p)->v.inuse.domain = (_d)) + +/* TODO: implement */ +#define mfn_valid (mfn) ({ (void) (mfn); 0; }) + +#define mfn_to_gfn (d, mfn) ((void)(d), _gfn(mfn_x(mfn)))
This appeared further up already.
xen/arch/riscv/include/asm/mm.h line 246
Quoted 1 line
xen/arch/riscv/include/asm/mm.h +1
-0+#define domain_set_alloc_bitsize (d) ((void)0)
Better ((void)(d)) ? And then ...
xen/arch/riscv/include/asm/mm.h line 247
Quoted 1 line
xen/arch/riscv/include/asm/mm.h +1
-0+#define domain_clamp_alloc_bitsize (d, b) (b)
... ((void)(d), (b)) here?
Jan
Re: [PATCH v3 31/34] xen/riscv: add minimal stuff to mm.h to build full Xen
Quoted 7 lines · Jan Beulich
Quoted 4 lines · Oleksii Kurochko
Signed-off-by Oleksii Kurochko <[email protected]>---
Changes in V3:
- update the commit message??? (yet again)
asm/mm.h was changed to mm.h
Quoted 25 lines
Quoted 20 lines
xen/arch/riscv/include/asm/mm.h +0
-0@@ -3,8 +3,251 @@ #ifndef _ASM_RISCV_MM_H #define _ASM_RISCV_MM_Hxen/arch/riscv/include/asm/mm.h +5
-0+#include <public/xen.h> +#include <xen/pdx.h> +#include <xen/types.h> + +#include <asm/page.h> #include <
asm/page-bits.h>xen/arch/riscv/include/asm/mm.h +6
-0+#define paddr_to_pdx (pa) mfn_to_pdx(maddr_to_mfn(pa)) +#define gfn_to_gaddr (gfn) pfn_to_paddr(gfn_x(gfn)) +#define gaddr_to_gfn (ga) _gfn(paddr_to_pfn(ga)) +#define mfn_to_maddr (mfn) pfn_to_paddr(mfn_x(mfn)) +#define maddr_to_mfn (ma) _mfn(paddr_to_pfn(ma)) +#define vmap_to_mfn (va)Quoted 2 lines
maddr_to_mfn(virt_to_maddr((vaddr_t)va)) +#define vmap_to_page(va) mfn_to_page(vmap_to_mfn(va))
Everything you have above ...
Quoted 10 lines
Quoted 8 lines
xen/arch/riscv/include/asm/mm.h +6
-0+#define paddr_to_pdx (pa) mfn_to_pdx(maddr_to_mfn(pa)) +#define gfn_to_gaddr (gfn) pfn_to_paddr(gfn_x(gfn)) +#define gaddr_to_gfn (ga) _gfn(paddr_to_pfn(ga)) +#define mfn_to_maddr (mfn) pfn_to_paddr(mfn_x(mfn)) +#define maddr_to_mfn (ma) _mfn(paddr_to_pfn(ma)) +#define vmap_to_mfn (va)maddr_to_mfn(virt_to_maddr((vaddr_t)va)) +#define vmap_to_page(va) mfn_to_page(vmap_to_mfn(va))
... appears a 2nd time right afterwards.
Hmm, looks like rebase issue. I'll drop a copy. Thanks.
Quoted 15 lines
Quoted 10 lines
xen/arch/riscv/include/asm/mm.h +2
-0+#define virt_to_maddr (va) ((paddr_t)((vaddr_t)(va) & PADDR_MASK)) +#define maddr_to_virt (pa) ((void *)((paddr_t)(pa) |
DIRECTMAP_VIRT_START))xen/arch/riscv/include/asm/mm.h +2
-0+ +/* Convert between Xen-heap virtual addresses and machine frame numbers. */
xen/arch/riscv/include/asm/mm.h +2
-0+#define __virt_to_mfn (va) (virt_to_maddr(va) >> PAGE_SHIFT) +#define __mfn_to_virt (mfn) maddr_to_virt((paddr_t)(mfn) <<
PAGE_SHIFT)These would imo better use
maddr_to_mfn()andmfn_to_maddr(), rather than
kind of open-coding them. The former could also usePFN_DOWN()as an alternative.
Thanks. I'll take that into account.
Quoted 14 lines
Quoted 14 lines
+/* Convert between Xen-heap virtual addresses and page-info structures. */
xen/arch/riscv/include/asm/mm.h +8
-0+static inline struct page_info *virt_to_page (const void *v) +{ + BUG(); + return NULL; +} + +/* +* We define non-underscored wrappers for above conversion functions.
+ * These are overriden in various source files while underscored version
Quoted 8 lines
xen/arch/riscv/include/asm/mm.h line 48
Quoted 4 lines
+ * remain intact.
+ */xen/arch/riscv/include/asm/mm.h +2
-0+#define virt_to_mfn (va) __virt_to_mfn(va) +#define mfn_to_virt (mfn) __mfn_to_virt(mfn)Is this really still needed? Would be pretty nice if in a new port we could get to start cleanly right away (i.e. by not needing per-file overrides, but using type-safe expansions here right away).
Yes, we can just rename __virt_to_mfn and __mfn_to_virt and updated it accordingly to your previous comment.
Quoted 38 lines
Quoted 38 lines
xen/arch/riscv/include/asm/mm.h +11
-0+struct page_info +{ + /* Each frame can be threaded onto a doubly-linked list. */ + struct page_list_entry list; + + /* Reference count and various PGC_xxx flags and fields. */ + unsigned long count_info; + + /* Context-dependent fields follow... */ + union { + /* Page is in use: ((count_info & PGC_count_mask) != 0).*/
+ struct {
+ /* Type reference count and variousPGT_xxxflags and fields. */
+ unsigned longtype_info;
+ } inuse;
+ /* Page is on a free list: ((count_info&PGC_count_mask) == 0). */
+ union {
+ struct {
+ /*
+ * Index of the first *possibly* unscrubbed page in the buddy.
+ * One more bit than maximum possible order to accommodate
+ *INVALID_DIRTY_IDX.
+ */xen/arch/riscv/include/asm/mm.h +4
-0+#define INVALID_DIRTY_IDX ((1UL << (MAX_ORDER + 1)) - 1) + unsigned long first_dirty:MAX_ORDER + 1; + + /* Do TLBs need flushing for safety before nextpage use? */
+ bool need_tlbflush:1;xen/arch/riscv/include/asm/mm.h +3
-0+ +#define BUDDY_NOT_SCRUBBING 0 +#define BUDDY_SCRUBBING 1
Quoted 8 lines
xen/arch/riscv/include/asm/mm.h line 86
Quoted 6 lines
xen/arch/riscv/include/asm/mm.h +6
-0+#define BUDDY_SCRUB_ABORT 2 + unsigned long scrub_state:2; + }; + + unsigned long val; + } free;Indentation is wrong (and thus misleading) for these two lines.
I'll correct it.
Quoted 6 lines
Quoted 3 lines
+
+ } u;Nit: I don't see the value of the trailing blank line inside the union.
Sure, there is no any sense.
Quoted 31 lines
Quoted 3 lines
+ union {
+ /* Page is in use, but not as a shadow. */I question the appicability of "shadow" here.
Quoted 25 lines
+ struct {
+ /* Owner of this page (zero if page is anonymous). */ + struct domain *domain;
+ } inuse;
+
+ /* Page is on a free list. */
+ struct {
+ /* Order-size of the free chunk this page is the head of. */
+ unsigned int order;
+ } free;xen/arch/riscv/include/asm/mm.h +6
-0+ + } v; + + union { + /* +* Timestamp from 'TLB clock', used to avoid extra safety flushes.
+ * Only valid for: a) free pages, and b) pages with zero type count
+ */
+uint32_ttlbflush_timestamp;
+ };
+uint64_tpad;
+};
Quoted 8 lines
xen/arch/riscv/include/asm/mm.h line 118
Quoted 5 lines
xen/arch/riscv/include/asm/mm.h +5
-0+ +#define frame_table ((struct page_info *)FRAMETABLE_VIRT_START) + +/* PDX of the first page in the frame table. */ +extern unsigned long frametable_base_pdx;From this I conclude memory on RISC-V systems may not start at (or near) 0?
I am not sure that it is impossible at all, but all platforms I saw it was always not 0 and pretty big values. For example, on real platform, there is =0000004000000000. In QEMU, it is 0x800...0
Quoted 45 lines
Quoted 45 lines
+/* Convert between machine frame numbers and page-info structures. */
+#define
mfn_to_page(mfn) \
+ (frame_table+ (mfn_to_pdx(mfn)-frametable_base_pdx)) +#define
page_to_mfn(pg) \
+pdx_to_mfn((unsigned long)((pg) - frame_table) + frametable_base_pdx)xen/arch/riscv/include/asm/mm.h +9
-0+ +static inline void *page_to_virt (const struct page_info *pg) +{ + return mfn_to_virt(mfn_x(page_to_mfn(pg))); +} + +/* +* Common code requires get_page_type and put_page_type. +* We don't care about typecounts so we just do the minimum to make it
+ * happy.
+ */
+static inline intget_page_type(struct page_info *page, unsigned long type)xen/arch/riscv/include/asm/mm.h +16
-0+{ + return 1; +} + +static inline void put_page_type (struct page_info *page) +{ +} + +static inline void put_page_and_type (struct page_info *page) +{ + put_page_type(page); + put_page(page); +} + +/* +* RISC-V does not have an M2P, but common code expects a handful of
+ * M2P-related defines and functions. Provide dummy versions of these.
+ */
+#define INVALID_M2P_ENTRY (~0UL)
Quoted 8 lines
Quoted 6 lines
xen/arch/riscv/include/asm/mm.h +5
-0+#define SHARED_M2P_ENTRY (~0UL - 1UL) +#define SHARED_M2P (_e) ((_e) == SHARED_M2P_ENTRY) + +/* Xen always owns P2M on RISC-V */ +#define set_gpfn_from_mfn (mfn, pfn) do { (void) (mfn),(void)(pfn); } while (0)
Nit: Stray blank again after cast.
I'll update this. Thanks.
Quoted 4 lines
Quoted 2 lines
+#define
mfn_to_gfn(d, mfn)((void)(d), _gfn(mfn_x(mfn)))What's the relation of the comment with these two #define-s?
I don't know, it was copied just from Arm. I think it would be better to drop a comment and just define macros as BUG_ON("uimplemented") for time being.
Quoted 35 lines
Quoted 35 lines
xen/arch/riscv/include/asm/mm.h +3
-0+#define PDX_GROUP_SHIFT (16 + 5) + +static inline unsigned long domain_get_maximum_gpfn(struct domain*d)
xen/arch/riscv/include/asm/mm.h +6
-0+{ + BUG(); + return 0; +} + +static inline long arch_memory_op(int op,
XEN_GUEST_HANDLE_PARAM(void)arg)xen/arch/riscv/include/asm/mm.h +10
-0+{ + BUG(); + return 0; +} + +/* +* On RISCV, all the RAM is currently direct mapped in Xen. +* Hence return always true. +*/ +static inline bool arch_mfns_in_directmap(unsigned long mfn,unsigned long nr)
xen/arch/riscv/include/asm/mm.h +8
-0+{ + return true; +} + +#define PG_shift (idx) (BITS_PER_LONG - (idx)) +#define PG_mask (x, idx) (x ## UL << PG_shift(idx)) + +#define PGT_none PG_mask(0, 1)/* no special uses of this page */
+#definePGT_writable_pagePG_mask(1, 1)/* has writable mappings? */
+#define PGT_type_maskPG_mask(1, 1)/* Bits 31 or
Quoted 8 lines
xen/arch/riscv/include/asm/mm.h line 195
Quoted 5 lines
63. */
xen/arch/riscv/include/asm/mm.h +4
-0+ +/* Count of uses of this frame as its current type. */ +#define PGT_count_width PG_shift(2) +#define PGT_count_mask ((1UL<<PGT_count_width)-1)Nit: Style (missing blanks around binary operators). Also a few more times further down.
Thanks. I'll update.
Quoted 12 lines
xen/arch/riscv/include/asm/mm.h line 204
Quoted 10 lines
+/*
+ * Page needs to be scrubbed. Since this bit can only be set on a page that is
+ * free (i.e. inPGC_state_free) we can reusePGC_allocatedbit.
+ */xen/arch/riscv/include/asm/mm.h +4
-0+#define _PGC_need_scrub _PGC_allocated +#define PGC_need_scrub PGC_allocated + +// /* Cleared when the owning guest 'frees' this page. */ Why a commented out comment?
Missed to remove, my IDE using this type of comment by default. and I commented all the file when tried to find minimal of changes needed for Xen build.
Quoted 14 lines
Quoted 11 lines
xen/arch/riscv/include/asm/mm.h +9
-0+#define _PGC_allocated PG_shift(1) +#define PGC_allocated PG_mask(1, 1) + /* Page is Xen heap? */ +#define _PGC_xen_heap PG_shift(2) +#define PGC_xen_heap PG_mask(1, 2) +/* Page is broken? */ +#define _PGC_broken PG_shift(7) +#define PGC_broken PG_mask(1, 7) +/* Mutually-exclusive page states: { inuse, offlining, offlined, free }. */
Can similar comments in this block please all be similarly indented (or not)?
Sure. I'll update that.
Quoted 10 lines
Quoted 8 lines
xen/arch/riscv/include/asm/mm.h +6
-0+#define PGC_state PG_mask(3, 9) +#define PGC_state_inuse PG_mask(0, 9) +#define PGC_state_offlining PG_mask(1, 9) +#define PGC_state_offlined PG_mask(2, 9) +#define PGC_state_free PG_mask(3, 9) +// #define page_state_is(pg, st) (((pg)->count_info&PGC_state) == PGC_state_##st)
???
The same as above, just missed to remove that line.
Quoted 10 lines
Quoted 7 lines
xen/arch/riscv/include/asm/mm.h +5
-0+/* Count of references to this frame. */ +#define PGC_count_width PG_shift(9) +#define PGC_count_mask ((1UL<<PGC_count_width)-1) + +#define page_state_is (pg, st) (((pg)->count_info&PGC_state) ==PGC_state_##st)
And here it then "properly" appears?
Quoted 14 lines
xen/arch/riscv/include/asm/mm.h line 236
Quoted 10 lines
xen/arch/riscv/include/asm/mm.h +10
-0+#define _PGC_extra PG_shift(10) +#define PGC_extra PG_mask(1, 10) + +#define is_xen_heap_page (page) ((page)->count_info & PGC_xen_heap) +#define is_xen_heap_mfn (mfn) \ + (mfn_valid(mfn) && is_xen_heap_page(mfn_to_page(mfn))) + +#define is_xen_fixed_mfn (mfn) \ + ((mfn_to_maddr(mfn) >= virt_to_maddr(&_start)) && \ + (mfn_to_maddr(mfn) <= virt_to_maddr((vaddr_t)_end - 1)))Why does
_startneed prefixing wuth & and_endprefixing with a cast? First and foremost both want to be consistent. And then preferably with as little extra clutter as possible.
This is how it was defined in Arm. I think it both can be casted. I'll update that.
Thanks.
Quoted 11 lines
xen/arch/riscv/include/asm/mm.h line 244
Quoted 8 lines
xen/arch/riscv/include/asm/mm.h +7
-0+#define page_get_owner (_p) (_p)->v.inuse.domain +#define page_set_owner (_p,_d) ((_p)->v.inuse.domain = (_d)) + +/* TODO: implement */ +#define mfn_valid (mfn) ({ (void) (mfn); 0; }) + +#define mfn_to_gfn (d, mfn) ((void)(d), _gfn(mfn_x(mfn)))This appeared further up already.
Quoted 7 lines
Quoted 1 line
+#define
domain_set_alloc_bitsize(d)((void)0)Better ((void)(d)) ? And then ...
Quoted 1 line
+#define
domain_clamp_alloc_bitsize(d, b)(b)... ((void)(d), (b)) here?
I'll update properly. Thanks.
~ Oleksii
Re: [PATCH v3 31/34] xen/riscv: add minimal stuff to mm.h to build full Xen
Quoted 16 lines · Oleksii
Quoted 15 lines · Jan Beulich
xen/arch/riscv/include/asm/mm.h line 236
Quoted 10 lines · Oleksii Kurochko
xen/arch/riscv/include/asm/mm.h +10
-0+#define _PGC_extra PG_shift(10) +#define PGC_extra PG_mask(1, 10) + +#define is_xen_heap_page (page) ((page)->count_info & PGC_xen_heap) +#define is_xen_heap_mfn (mfn) \ + (mfn_valid(mfn) && is_xen_heap_page(mfn_to_page(mfn))) + +#define is_xen_fixed_mfn (mfn) \ + ((mfn_to_maddr(mfn) >= virt_to_maddr(&_start)) && \ + (mfn_to_maddr(mfn) <= virt_to_maddr((vaddr_t)_end - 1)))Why does
_startneed prefixing wuth & and_endprefixing with a cast? First and foremost both want to be consistent. And then preferably with as little extra clutter as possible.
Quoted 2 lines
This is how it was defined in Arm. I think it both can be casted. I'll update that.
Judging from your present use of virt_to_maddr(&_start), I'd assume you're fine without casts. And when casts aren't needed, they're better avoided.
Jan