diff mbox series

[v2,08/15] xen/asm-generic: introduce generic header percpu.h

Message ID d0ecdf04ceea49f57a54e15cc129c165a142a5cb.1699633310.git.oleksii.kurochko@gmail.com (mailing list archive)
State Superseded
Headers show
Series Introduce generic headers | expand

Commit Message

Oleksii Kurochko Nov. 10, 2023, 4:30 p.m. UTC
Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
---
Changes in V2:
	- use smp_processor_id() instead of get_processor_id().
 	- update commit message .
---
 xen/include/asm-generic/percpu.h | 35 ++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)
 create mode 100644 xen/include/asm-generic/percpu.h

Comments

Oleksii Kurochko Nov. 15, 2023, 3:27 p.m. UTC | #1
I have to drop arch specific headers and switch to asm-generic version.
I'll do the same for patches 09-12 in the next patch version.

~ Oleksii
On Fri, 2023-11-10 at 18:30 +0200, Oleksii Kurochko wrote:
> Signed-off-by: Oleksii Kurochko <oleksii.kurochko@gmail.com>
> ---
> Changes in V2:
>         - use smp_processor_id() instead of get_processor_id().
>         - update commit message .
> ---
>  xen/include/asm-generic/percpu.h | 35
> ++++++++++++++++++++++++++++++++
>  1 file changed, 35 insertions(+)
>  create mode 100644 xen/include/asm-generic/percpu.h
> 
> diff --git a/xen/include/asm-generic/percpu.h b/xen/include/asm-
> generic/percpu.h
> new file mode 100644
> index 0000000000..85a3f3ef17
> --- /dev/null
> +++ b/xen/include/asm-generic/percpu.h
> @@ -0,0 +1,35 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +#ifndef __ASM_GENERIC_PERCPU_H__
> +#define __ASM_GENERIC_PERCPU_H__
> +
> +#ifndef __ASSEMBLY__
> +
> +#include <xen/types.h>
> +
> +extern char __per_cpu_start[], __per_cpu_data_end[];
> +extern unsigned long __per_cpu_offset[NR_CPUS];
> +void percpu_init_areas(void);
> +
> +#define per_cpu(var, cpu)  \
> +    (*RELOC_HIDE(&per_cpu__##var, __per_cpu_offset[cpu]))
> +
> +#define this_cpu(var) \
> +    (*RELOC_HIDE(&per_cpu__##var,
> __per_cpu_offset[smp_processor_id()]))
> +
> +#define per_cpu_ptr(var, cpu)  \
> +    (*RELOC_HIDE(var, __per_cpu_offset[cpu]))
> +#define this_cpu_ptr(var) \
> +    (*RELOC_HIDE(var, smp_processor_id()))
> +
> +#endif
> +
> +#endif /* __ASM_GENERIC_PERCPU_H__ */
> +
> +/*
> + * Local variables:
> + * mode: C
> + * c-file-style: "BSD"
> + * c-basic-offset: 4
> + * indent-tabs-mode: nil
> + * End:
> + */
Jan Beulich Nov. 16, 2023, 7:36 a.m. UTC | #2
On 10.11.2023 17:30, Oleksii Kurochko wrote:
> --- /dev/null
> +++ b/xen/include/asm-generic/percpu.h
> @@ -0,0 +1,35 @@
> +/* SPDX-License-Identifier: GPL-2.0-only */
> +#ifndef __ASM_GENERIC_PERCPU_H__
> +#define __ASM_GENERIC_PERCPU_H__
> +
> +#ifndef __ASSEMBLY__
> +
> +#include <xen/types.h>
> +
> +extern char __per_cpu_start[], __per_cpu_data_end[];

Can we go one tiny step beyond what Arm presently has and make the
latter of the two const?

Jan
Oleksii Kurochko Nov. 16, 2023, 12:04 p.m. UTC | #3
On Thu, 2023-11-16 at 08:36 +0100, Jan Beulich wrote:
> On 10.11.2023 17:30, Oleksii Kurochko wrote:
> > --- /dev/null
> > +++ b/xen/include/asm-generic/percpu.h
> > @@ -0,0 +1,35 @@
> > +/* SPDX-License-Identifier: GPL-2.0-only */
> > +#ifndef __ASM_GENERIC_PERCPU_H__
> > +#define __ASM_GENERIC_PERCPU_H__
> > +
> > +#ifndef __ASSEMBLY__
> > +
> > +#include <xen/types.h>
> > +
> > +extern char __per_cpu_start[], __per_cpu_data_end[];
> 
> Can we go one tiny step beyond what Arm presently has and make the
> latter of the two const?
I am not sure I think we will have compilation issue with the following
code in Arm and x86 because of [-Werror=discarded-qualifiers]:

static void cf_check _free_percpu_area(struct rcu_head *head)
{
    struct free_info *info = container_of(head, struct free_info, rcu);
    unsigned int cpu = info->cpu;
    char *p = __per_cpu_start + __per_cpu_offset[cpu];

    free_xenheap_pages(p, PERCPU_ORDER);
    __per_cpu_offset[cpu] = INVALID_PERCPU_AREA;
}

I guess cast can help.


~ Oleksii
Jan Beulich Nov. 16, 2023, 12:28 p.m. UTC | #4
On 16.11.2023 13:04, Oleksii wrote:
> On Thu, 2023-11-16 at 08:36 +0100, Jan Beulich wrote:
>> On 10.11.2023 17:30, Oleksii Kurochko wrote:
>>> --- /dev/null
>>> +++ b/xen/include/asm-generic/percpu.h
>>> @@ -0,0 +1,35 @@
>>> +/* SPDX-License-Identifier: GPL-2.0-only */
>>> +#ifndef __ASM_GENERIC_PERCPU_H__
>>> +#define __ASM_GENERIC_PERCPU_H__
>>> +
>>> +#ifndef __ASSEMBLY__
>>> +
>>> +#include <xen/types.h>
>>> +
>>> +extern char __per_cpu_start[], __per_cpu_data_end[];
>>
>> Can we go one tiny step beyond what Arm presently has and make the
>> latter of the two const?
> I am not sure I think we will have compilation issue with the following
> code in Arm and x86 because of [-Werror=discarded-qualifiers]:
> 
> static void cf_check _free_percpu_area(struct rcu_head *head)
> {
>     struct free_info *info = container_of(head, struct free_info, rcu);
>     unsigned int cpu = info->cpu;
>     char *p = __per_cpu_start + __per_cpu_offset[cpu];
> 
>     free_xenheap_pages(p, PERCPU_ORDER);
>     __per_cpu_offset[cpu] = INVALID_PERCPU_AREA;
> }

There's no use of __per_cpu_data_end here; I specifically didn't ask for both
of the declarations to have const added.

> I guess cast can help.

There may not be casts casting away constness, except maybe in very delicate
situations.

Jan
Oleksii Kurochko Nov. 17, 2023, 9:01 a.m. UTC | #5
On Thu, 2023-11-16 at 13:28 +0100, Jan Beulich wrote:
> On 16.11.2023 13:04, Oleksii wrote:
> > On Thu, 2023-11-16 at 08:36 +0100, Jan Beulich wrote:
> > > On 10.11.2023 17:30, Oleksii Kurochko wrote:
> > > > --- /dev/null
> > > > +++ b/xen/include/asm-generic/percpu.h
> > > > @@ -0,0 +1,35 @@
> > > > +/* SPDX-License-Identifier: GPL-2.0-only */
> > > > +#ifndef __ASM_GENERIC_PERCPU_H__
> > > > +#define __ASM_GENERIC_PERCPU_H__
> > > > +
> > > > +#ifndef __ASSEMBLY__
> > > > +
> > > > +#include <xen/types.h>
> > > > +
> > > > +extern char __per_cpu_start[], __per_cpu_data_end[];
> > > 
> > > Can we go one tiny step beyond what Arm presently has and make
> > > the
> > > latter of the two const?
> > I am not sure I think we will have compilation issue with the
> > following
> > code in Arm and x86 because of [-Werror=discarded-qualifiers]:
> > 
> > static void cf_check _free_percpu_area(struct rcu_head *head)
> > {
> >     struct free_info *info = container_of(head, struct free_info,
> > rcu);
> >     unsigned int cpu = info->cpu;
> >     char *p = __per_cpu_start + __per_cpu_offset[cpu];
> > 
> >     free_xenheap_pages(p, PERCPU_ORDER);
> >     __per_cpu_offset[cpu] = INVALID_PERCPU_AREA;
> > }
> 
> There's no use of __per_cpu_data_end here; I specifically didn't ask
> for both
> of the declarations to have const added.
Yes, I misread your comment.

> 
> > I guess cast can help.
> 
> There may not be casts casting away constness, except maybe in very
> delicate
> situations.
> 

~ Oleksii
diff mbox series

Patch

diff --git a/xen/include/asm-generic/percpu.h b/xen/include/asm-generic/percpu.h
new file mode 100644
index 0000000000..85a3f3ef17
--- /dev/null
+++ b/xen/include/asm-generic/percpu.h
@@ -0,0 +1,35 @@ 
+/* SPDX-License-Identifier: GPL-2.0-only */
+#ifndef __ASM_GENERIC_PERCPU_H__
+#define __ASM_GENERIC_PERCPU_H__
+
+#ifndef __ASSEMBLY__
+
+#include <xen/types.h>
+
+extern char __per_cpu_start[], __per_cpu_data_end[];
+extern unsigned long __per_cpu_offset[NR_CPUS];
+void percpu_init_areas(void);
+
+#define per_cpu(var, cpu)  \
+    (*RELOC_HIDE(&per_cpu__##var, __per_cpu_offset[cpu]))
+
+#define this_cpu(var) \
+    (*RELOC_HIDE(&per_cpu__##var, __per_cpu_offset[smp_processor_id()]))
+
+#define per_cpu_ptr(var, cpu)  \
+    (*RELOC_HIDE(var, __per_cpu_offset[cpu]))
+#define this_cpu_ptr(var) \
+    (*RELOC_HIDE(var, smp_processor_id()))
+
+#endif
+
+#endif /* __ASM_GENERIC_PERCPU_H__ */
+
+/*
+ * Local variables:
+ * mode: C
+ * c-file-style: "BSD"
+ * c-basic-offset: 4
+ * indent-tabs-mode: nil
+ * End:
+ */