[ANNOUNCE] Linux Security Summit North Americ (LSS-NA) CfP

2023-01-20 Thread James Morris
The Call for Participation for the 2023 LSS-NA conference is open!

See details of the event and information on submitting proposals here:
https://events.linuxfoundation.org/linux-security-summit-north-america/

LSS-NA 2023 will be in Vancouver, BC, Canada, from May 10th to May 12th. 
This will be a three day event, co-located with Open Source Summit North 
America [1].

The LSS-NA CfP is open until March 1st, 2023.


Note that announcements relating to the Linux Security Summit may be found 
now on the Fediverse, via: https://social.kernel.org/LinuxSecSummit


-- 
James Morris



[1] https://events.linuxfoundation.org/open-source-summit-north-america/

--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



[RFC PATCH v2 15/31] irqchip: Add irq-kvx-apic-gic driver

2023-01-20 Thread Yann Sionneau
Each Cluster of the Coolidge SoC includes an Advanced Programmable
Interrupt Controller (APIC) and Generic Interrupt Controller (GIC).

The APIC GIC acts as an intermediary interrupt controller, muxing/routing
incoming interrupts to cores in the cluster.

The 139 possible input interrupt lines are organized as follow:
 - 128 from the mailbox controller (one it per mailboxes)
 - 1   from the NoC router
 - 5   from IOMMUs
 - 1   from L2 cache DMA job FIFO
 - 1   from cluster watchdog
 - 2   for SECC, DECC
 - 1   from Data NoC

The 72 possible output interrupt line:
 -  68 : 4 interrupts per cores (17 cores)
 -  1 for L2 cache controller
 -  3 extra that are for padding

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Co-developed-by: Vincent Chardon 
Signed-off-by: Vincent Chardon 
Signed-off-by: Jules Maselbas 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2:
 - removed irq-kvx-itgen driver (moved in its own patch)
 - removed irq-kvx-apic-mailbox driver (moved in its own patch)
 - removed irq-kvx-core-intc driver (moved in its own patch)
 - removed print on probe success

 drivers/irqchip/Kconfig|   6 +
 drivers/irqchip/Makefile   |   1 +
 drivers/irqchip/irq-kvx-apic-gic.c | 356 +
 3 files changed, 363 insertions(+)
 create mode 100644 drivers/irqchip/irq-kvx-apic-gic.c

diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
index 7ef9f5e696d3..2433e4ba0759 100644
--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -334,6 +334,12 @@ config MIPS_GIC
select IRQ_DOMAIN_HIERARCHY
select MIPS_CM
 
+config KVX_APIC_GIC
+   bool
+   depends on KVX
+   select IRQ_DOMAIN
+   select IRQ_DOMAIN_HIERARCHY
+
 config INGENIC_IRQ
bool
depends on MACH_INGENIC
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index 87b49a10962c..8ac1dd880420 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -69,6 +69,7 @@ obj-$(CONFIG_BCM7120_L2_IRQ)  += irq-bcm7120-l2.o
 obj-$(CONFIG_BRCMSTB_L2_IRQ)   += irq-brcmstb-l2.o
 obj-$(CONFIG_KEYSTONE_IRQ) += irq-keystone.o
 obj-$(CONFIG_MIPS_GIC) += irq-mips-gic.o
+obj-$(CONFIG_KVX_APIC_GIC) += irq-kvx-apic-gic.o
 obj-$(CONFIG_ARCH_MEDIATEK)+= irq-mtk-sysirq.o irq-mtk-cirq.o
 obj-$(CONFIG_ARCH_DIGICOLOR)   += irq-digicolor.o
 obj-$(CONFIG_ARCH_SA1100)  += irq-sa11x0.o
diff --git a/drivers/irqchip/irq-kvx-apic-gic.c 
b/drivers/irqchip/irq-kvx-apic-gic.c
new file mode 100644
index ..cc234a075473
--- /dev/null
+++ b/drivers/irqchip/irq-kvx-apic-gic.c
@@ -0,0 +1,356 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2017 - 2022 Kalray Inc.
+ * Author(s): Clement Leger
+ *Julian Vetter
+ */
+
+#define pr_fmt(fmt)"kvx_apic_gic: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* APIC is organized in 18 groups of 4 output lines
+ * However, the two upper lines are for Secure RM and DMA engine
+ * Thus, we do not have to use them
+ */
+#define KVX_GIC_PER_CPU_IT_COUNT   4
+#define KVX_GIC_INPUT_IT_COUNT 0x9D
+#define KVX_GIC_OUTPUT_IT_COUNT0x10
+
+/* GIC enable register definitions */
+#define KVX_GIC_ENABLE_OFFSET  0x0
+#define KVX_GIC_ENABLE_ELEM_SIZE   0x1
+#define KVX_GIC_ELEM_SIZE  0x400
+
+/* GIC status lac register definitions */
+#define KVX_GIC_STATUS_LAC_OFFSET  0x120
+#define KVX_GIC_STATUS_LAC_ELEM_SIZE   0x8
+#define KVX_GIC_STATUS_LAC_ARRAY_SIZE  0x3
+
+/**
+ * For each CPU, there is 4 output lines coming from the apic GIC.
+ * We only use 1 line and this structure represent this line.
+ * @base Output line base address
+ * @cpu CPU associated to this line
+ */
+struct gic_out_irq_line {
+   void __iomem *base;
+   unsigned int cpu;
+};
+
+/**
+ * Input irq line.
+ * This structure is used to store the status of the input line and the
+ * associated output line.
+ * @enabled Boolean for line status
+ * @cpu CPU currently receiving this interrupt
+ * @it_num Interrupt number
+ */
+struct gic_in_irq_line {
+   bool enabled;
+   struct gic_out_irq_line *out_line;
+   unsigned int it_num;
+};
+
+/**
+ * struct kvx_apic_gic - kvx apic gic
+ * @base: Base address of the controller
+ * @domain Domain for this controller
+ * @input_nr_irqs: maximum number of supported input interrupts
+ * @cpus: Per cpu interrupt configuration
+ * @output_irq: Array of output irq lines
+ * @input_irq: Array of input irq lines
+ */
+struct kvx_apic_gic {
+   raw_spinlock_t lock;
+   void __iomem *base;
+   struct irq_domain *domain;
+   uint32_t input_nr_irqs;
+   /* For each cpu, there is an output IT line */
+   struct gic_out_irq_line output_irq[KVX_GIC_OUTPUT_IT_COUN

[RFC PATCH v2 05/31] Documentation: Add binding for kalray,coolidge-itgen

2023-01-20 Thread Yann Sionneau
From: Jules Maselbas 

Add documentation for `kalray,coolidge-itgen` binding.

Co-developed-by: Jules Maselbas 
Signed-off-by: Jules Maselbas 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: new patch

 .../kalray,coolidge-itgen.yaml| 48 +++
 1 file changed, 48 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/interrupt-controller/kalray,coolidge-itgen.yaml

diff --git 
a/Documentation/devicetree/bindings/interrupt-controller/kalray,coolidge-itgen.yaml
 
b/Documentation/devicetree/bindings/interrupt-controller/kalray,coolidge-itgen.yaml
new file mode 100644
index ..47b503bff1d9
--- /dev/null
+++ 
b/Documentation/devicetree/bindings/interrupt-controller/kalray,coolidge-itgen.yaml
@@ -0,0 +1,48 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/interrupt-controller/kalray,coolidge-itgen#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Kalray Coolidge SoC Interrupt Generator (ITGEN)
+
+description: |
+  The Interrupt Generator (ITGEN) is an interrupt controller block.
+  It's purpose is to convert IRQ lines coming from SoC peripherals into writes
+  on the AXI bus. The ITGEN intended purpose is to write into the APIC 
mailboxes.
+
+allOf:
+  - $ref: /schemas/interrupt-controller.yaml#
+
+properties:
+  compatible:
+const: kalray,coolidge-itgen
+
+  "#interrupt-cells":
+const: 2
+description: |
+  - 1st cell is for the IRQ number
+  - 2nd cell is for the trigger type as defined 
dt-bindings/interrupt-controller/irq.h
+
+  interrupt-controller: true
+
+  msi-parent: true
+
+required:
+  - compatible
+  - reg
+  - "#interrupt-cells"
+  - interrupt-controller
+  - msi-parent
+
+examples:
+  - |
+itgen: interrupt-controller@2700 {
+compatible = "kalray,coolidge-itgen";
+reg = <0 0x2700 0 0x1104>;
+#interrupt-cells = <2>;
+interrupt-controller;
+msi-parent = <&apic_mailbox>;
+};
+
+...
-- 
2.37.2





--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



[RFC PATCH v2 20/31] kvx: Add memory management

2023-01-20 Thread Yann Sionneau
Add memory management support for kvx, including: cache and tlb
management, page fault handling, ioremap/mmap and streaming dma support.

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Guillaume Thouvenin 
Signed-off-by: Guillaume Thouvenin 
Co-developed-by: Jean-Christophe Pince 
Signed-off-by: Jean-Christophe Pince 
Co-developed-by: Jules Maselbas 
Signed-off-by: Jules Maselbas 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Co-developed-by: Julien Hascoet 
Signed-off-by: Julien Hascoet 
Co-developed-by: Louis Morhet 
Signed-off-by: Louis Morhet 
Co-developed-by: Marc Poulhiès 
Signed-off-by: Marc Poulhiès 
Co-developed-by: Marius Gligor 
Signed-off-by: Marius Gligor 
Co-developed-by: Vincent Chardon 
Signed-off-by: Vincent Chardon 
Co-developed-by: Yann Sionneau 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: removed L2 cache management

 arch/kvx/include/asm/cache.h|  43 +++
 arch/kvx/include/asm/cacheflush.h   | 158 ++
 arch/kvx/include/asm/fixmap.h   |  47 +++
 arch/kvx/include/asm/hugetlb.h  |  36 +++
 arch/kvx/include/asm/mem_map.h  |  44 +++
 arch/kvx/include/asm/mmu.h  | 289 ++
 arch/kvx/include/asm/mmu_context.h  | 156 ++
 arch/kvx/include/asm/mmu_stats.h|  38 +++
 arch/kvx/include/asm/page.h | 187 
 arch/kvx/include/asm/page_size.h|  29 ++
 arch/kvx/include/asm/pgalloc.h  | 101 +++
 arch/kvx/include/asm/pgtable-bits.h | 102 +++
 arch/kvx/include/asm/pgtable.h  | 451 
 arch/kvx/include/asm/rm_fw.h|  16 +
 arch/kvx/include/asm/sparsemem.h|  15 +
 arch/kvx/include/asm/symbols.h  |  16 +
 arch/kvx/include/asm/tlb.h  |  24 ++
 arch/kvx/include/asm/tlb_defs.h | 131 
 arch/kvx/include/asm/tlbflush.h |  58 
 arch/kvx/include/asm/vmalloc.h  |  10 +
 arch/kvx/mm/cacheflush.c| 154 ++
 arch/kvx/mm/dma-mapping.c   |  85 ++
 arch/kvx/mm/extable.c   |  24 ++
 arch/kvx/mm/fault.c | 264 
 arch/kvx/mm/init.c  | 277 +
 arch/kvx/mm/mmap.c  |  31 ++
 arch/kvx/mm/mmu.c   | 202 +
 arch/kvx/mm/mmu_stats.c |  94 ++
 arch/kvx/mm/tlb.c   | 433 ++
 29 files changed, 3515 insertions(+)
 create mode 100644 arch/kvx/include/asm/cache.h
 create mode 100644 arch/kvx/include/asm/cacheflush.h
 create mode 100644 arch/kvx/include/asm/fixmap.h
 create mode 100644 arch/kvx/include/asm/hugetlb.h
 create mode 100644 arch/kvx/include/asm/mem_map.h
 create mode 100644 arch/kvx/include/asm/mmu.h
 create mode 100644 arch/kvx/include/asm/mmu_context.h
 create mode 100644 arch/kvx/include/asm/mmu_stats.h
 create mode 100644 arch/kvx/include/asm/page.h
 create mode 100644 arch/kvx/include/asm/page_size.h
 create mode 100644 arch/kvx/include/asm/pgalloc.h
 create mode 100644 arch/kvx/include/asm/pgtable-bits.h
 create mode 100644 arch/kvx/include/asm/pgtable.h
 create mode 100644 arch/kvx/include/asm/rm_fw.h
 create mode 100644 arch/kvx/include/asm/sparsemem.h
 create mode 100644 arch/kvx/include/asm/symbols.h
 create mode 100644 arch/kvx/include/asm/tlb.h
 create mode 100644 arch/kvx/include/asm/tlb_defs.h
 create mode 100644 arch/kvx/include/asm/tlbflush.h
 create mode 100644 arch/kvx/include/asm/vmalloc.h
 create mode 100644 arch/kvx/mm/cacheflush.c
 create mode 100644 arch/kvx/mm/dma-mapping.c
 create mode 100644 arch/kvx/mm/extable.c
 create mode 100644 arch/kvx/mm/fault.c
 create mode 100644 arch/kvx/mm/init.c
 create mode 100644 arch/kvx/mm/mmap.c
 create mode 100644 arch/kvx/mm/mmu.c
 create mode 100644 arch/kvx/mm/mmu_stats.c
 create mode 100644 arch/kvx/mm/tlb.c

diff --git a/arch/kvx/include/asm/cache.h b/arch/kvx/include/asm/cache.h
new file mode 100644
index ..a51a68d23cfc
--- /dev/null
+++ b/arch/kvx/include/asm/cache.h
@@ -0,0 +1,43 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#ifndef _ASM_KVX_CACHE_H
+#define _ASM_KVX_CACHE_H
+
+/**
+ * On kvx I$ and D$ have the same size (16KB).
+ * Caches are 16K bytes big, VIPT 4-way set associative, true LRU, with 64-byte
+ * lines. The D$ is also write-through.
+ */
+#define KVX_ICACHE_WAY_COUNT   4
+#define KVX_ICACHE_SET_COUNT   64
+#define KVX_ICACHE_LINE_SHIFT  6
+#define KVX_ICACHE_LINE_SIZE   (1 << KVX_ICACHE_LINE_SHIFT)
+#define KVX_ICACHE_SIZE\
+   (KVX_ICACHE_WAY_COUNT * KVX_ICACHE_SET_COUNT * KVX_ICACHE_LINE_SIZE)
+
+/**
+ * Invalidate the whole I-cache if the size to flush is more than this value
+ */
+#define KVX_ICACHE_INVAL_SIZE  (KVX_ICACHE_SIZE)
+
+/* D-Cache */
+#define KVX_DCACHE_WAY_COUNT   4
+#define KVX_DCACHE_SET_COUNT   64
+#define KVX_DCACHE_LINE_SHIFT  6
+#define KVX_DCACHE_LINE_SIZE   (1 << KVX_DCACHE_LINE_SHIFT)
+#defin

[RFC PATCH v2 21/31] kvx: Add system call support

2023-01-20 Thread Yann Sionneau
Add system call support and related uaccess.h for kvx.

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Guillaume Thouvenin 
Signed-off-by: Guillaume Thouvenin 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Co-developed-by: Julien Villette 
Signed-off-by: Julien Villette 
Co-developed-by: Marius Gligor 
Signed-off-by: Marius Gligor 
Co-developed-by: Yann Sionneau 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2:
 - typo fixes (clober* -> clobber*)
 - use generic __access_ok

 arch/kvx/include/asm/syscall.h   |   73 ++
 arch/kvx/include/asm/syscalls.h  |   21 +
 arch/kvx/include/asm/uaccess.h   |  317 +
 arch/kvx/include/asm/unistd.h|   11 +
 arch/kvx/include/uapi/asm/cachectl.h |   25 +
 arch/kvx/include/uapi/asm/unistd.h   |   16 +
 arch/kvx/kernel/entry.S  | 1759 ++
 arch/kvx/kernel/sys_kvx.c|   58 +
 arch/kvx/kernel/syscall_table.c  |   19 +
 9 files changed, 2299 insertions(+)
 create mode 100644 arch/kvx/include/asm/syscall.h
 create mode 100644 arch/kvx/include/asm/syscalls.h
 create mode 100644 arch/kvx/include/asm/uaccess.h
 create mode 100644 arch/kvx/include/asm/unistd.h
 create mode 100644 arch/kvx/include/uapi/asm/cachectl.h
 create mode 100644 arch/kvx/include/uapi/asm/unistd.h
 create mode 100644 arch/kvx/kernel/entry.S
 create mode 100644 arch/kvx/kernel/sys_kvx.c
 create mode 100644 arch/kvx/kernel/syscall_table.c

diff --git a/arch/kvx/include/asm/syscall.h b/arch/kvx/include/asm/syscall.h
new file mode 100644
index ..a3f6cef73e4a
--- /dev/null
+++ b/arch/kvx/include/asm/syscall.h
@@ -0,0 +1,73 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#ifndef _ASM_KVX_SYSCALL_H
+#define _ASM_KVX_SYSCALL_H
+
+#include 
+#include 
+
+#include 
+
+/* The array of function pointers for syscalls. */
+extern void *sys_call_table[];
+
+void scall_machine_exit(unsigned char value);
+
+/**
+ * syscall_get_nr - find which system call a task is executing
+ * @task:  task of interest, must be blocked
+ * @regs:  task_pt_regs() of @task
+ *
+ * If @task is executing a system call or is at system call
+ * tracing about to attempt one, returns the system call number.
+ * If @task is not executing a system call, i.e. it's blocked
+ * inside the kernel for a fault or signal, returns -1.
+ *
+ * Note this returns int even on 64-bit machines.  Only 32 bits of
+ * system call number can be meaningful.  If the actual arch value
+ * is 64 bits, this truncates to 32 bits so 0x means -1.
+ *
+ * It's only valid to call this when @task is known to be blocked.
+ */
+static inline int syscall_get_nr(struct task_struct *task, struct pt_regs 
*regs)
+{
+   if (!in_syscall(regs))
+   return -1;
+
+   return es_sysno(regs);
+}
+
+static inline long syscall_get_error(struct task_struct *task,
+struct pt_regs *regs)
+{
+   /* 0 if syscall succeeded, otherwise -Errorcode */
+   return IS_ERR_VALUE(regs->r0) ? regs->r0 : 0;
+}
+
+static inline long syscall_get_return_value(struct task_struct *task,
+   struct pt_regs *regs)
+{
+   return regs->r0;
+}
+
+static inline int syscall_get_arch(struct task_struct *task)
+{
+   return AUDIT_ARCH_KVX;
+}
+
+static inline void syscall_get_arguments(struct task_struct *task,
+struct pt_regs *regs,
+unsigned long *args)
+{
+   args[0] = regs->orig_r0;
+   args++;
+   memcpy(args, ®s->r1, 5 * sizeof(args[0]));
+}
+
+int __init setup_syscall_sigreturn_page(void *sigpage_addr);
+
+#endif
diff --git a/arch/kvx/include/asm/syscalls.h b/arch/kvx/include/asm/syscalls.h
new file mode 100644
index ..beec95ebb97a
--- /dev/null
+++ b/arch/kvx/include/asm/syscalls.h
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#ifndef _ASM_KVX_SYSCALLS_H
+#define _ASM_KVX_SYSCALLS_H
+
+#include 
+
+/* We redefine clone in assembly for special slowpath */
+asmlinkage long __sys_clone(unsigned long clone_flags, unsigned long newsp,
+   int __user *parent_tid, int __user *child_tid, int tls);
+
+#define sys_clone __sys_clone
+
+long sys_cachectl(unsigned long addr, unsigned long len, unsigned long cache,
+ unsigned long flags);
+
+#endif
diff --git a/arch/kvx/include/asm/uaccess.h b/arch/kvx/include/asm/uaccess.h
new file mode 100644
index ..24f91d75c1dd
--- /dev/null
+++ b/arch/kvx/include/asm/uaccess.h
@@ -0,0 +1,317 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * derived from arch/riscv/include/asm/uaccess.h
+ *
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ *Guillaume Thouvenin
+ */

Re: [RFC PATCH v2 11/31] kvx: Add atomic/locking headers

2023-01-20 Thread Mark Rutland
On Fri, Jan 20, 2023 at 03:09:42PM +0100, Yann Sionneau wrote:
> Add common headers (atomic, bitops, barrier and locking) for basic
> kvx support.
> 
> Co-developed-by: Clement Leger 
> Signed-off-by: Clement Leger 
> Co-developed-by: Jules Maselbas 
> Signed-off-by: Jules Maselbas 
> Co-developed-by: Julian Vetter 
> Signed-off-by: Julian Vetter 
> Co-developed-by: Julien Villette 
> Signed-off-by: Julien Villette 
> Co-developed-by: Yann Sionneau 
> Signed-off-by: Yann Sionneau 
> ---
> 
> Notes:
> V1 -> V2:
>  - use {READ,WRITE}_ONCE for arch_atomic64_{read,set}
>  - use asm-generic/bitops/atomic.h instead of __test_and_*_bit
>  - removed duplicated includes
>  - rewrite xchg and cmpxchg in C using builtins for acswap insn

Thanks for those changes. I see one issue below (instantiated a few times), but
other than that this looks good to me.

[...]

> +#define ATOMIC64_RETURN_OP(op, c_op) \
> +static inline long arch_atomic64_##op##_return(long i, atomic64_t *v)
> \
> +{\
> + long new, old, ret; \
> + \
> + do {\
> + old = v->counter;   \

This should be arch_atomic64_read(v), in order to avoid the potential for the
compiler to replay the access and introduce ABA races and other such problems.

For details, see:

  https://lore.kernel.org/lkml/Y70SWXHDmOc3RhMd@osiris/
  https://lore.kernel.org/lkml/Y71LoCIl+IFdy9D8@FVFF77S0Q05N/

I see that the generic 32-bit atomic code suffers from that issue, and we
should fix it.

> + new = old c_op i;   \
> + ret = arch_cmpxchg(&v->counter, old, new);  \
> + } while (ret != old);   \
> + \
> + return new; \
> +}
> +
> +#define ATOMIC64_OP(op, c_op)
> \
> +static inline void arch_atomic64_##op(long i, atomic64_t *v) \
> +{\
> + long new, old, ret; \
> + \
> + do {\
> + old = v->counter;   \

Likewise, arch_atomic64_read(v) here.

> + new = old c_op i;   \
> + ret = arch_cmpxchg(&v->counter, old, new);  \
> + } while (ret != old);   \
> +}
> +
> +#define ATOMIC64_FETCH_OP(op, c_op)  \
> +static inline long arch_atomic64_fetch_##op(long i, atomic64_t *v)   \
> +{\
> + long new, old, ret; \
> + \
> + do {\
> + old = v->counter;   \

Likewise, arch_atomic64_read(v) here.

> + new = old c_op i;   \
> + ret = arch_cmpxchg(&v->counter, old, new);  \
> + } while (ret != old);   \
> + \
> + return old; \
> +}
> +
> +#define ATOMIC64_OPS(op, c_op)   
> \
> + ATOMIC64_OP(op, c_op)   \
> + ATOMIC64_RETURN_OP(op, c_op)\
> + ATOMIC64_FETCH_OP(op, c_op)
> +
> +ATOMIC64_OPS(and, &)
> +ATOMIC64_OPS(or, |)
> +ATOMIC64_OPS(xor, ^)
> +ATOMIC64_OPS(add, +)
> +ATOMIC64_OPS(sub, -)
> +
> +#undef ATOMIC64_OPS
> +#undef ATOMIC64_FETCH_OP
> +#undef ATOMIC64_OP
> +
> +static inline int arch_atomic_add_return(int i, atomic_t *v)
> +{
> + int new, old, ret;
> +
> + do {
> + old = v->counter;

Likewise, arch_atomic64_read(v) here.

> + new = old + i;
> + ret = arch_cmpxchg(&v->counter, old, new);
> + } while (ret != old);
> +
> + return new;
> +}
> +
> +static inline int arch_atomic_sub_return(int i, atomic_t *v)
> +{
> + return arch_atomic_add_return(-i, v);
> +}
> +
> +#include 
> +
> +#endif   /* _ASM_KVX_ATOMIC_H */

Otherwise, the atomics look good to me.

Thanks,
Mark.

--
Linux-audit mailing list
Linu

[RFC PATCH v2 14/31] kvx: Add exception/interrupt handling

2023-01-20 Thread Yann Sionneau
Add the exception and interrupt handling machanism for basic kvx
support.

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Guillaume Thouvenin 
Signed-off-by: Guillaume Thouvenin 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Co-developed-by: Luc Michel 
Signed-off-by: Luc Michel 
Co-developed-by: Marius Gligor 
Signed-off-by: Marius Gligor 
Co-developed-by: Yann Sionneau 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2:
 - removed ipi.h headers and driver (moved into ipi driver patch)

 arch/kvx/include/asm/break_hook.h |  69 +
 arch/kvx/include/asm/bug.h|  67 
 arch/kvx/include/asm/dame.h   |  31 
 arch/kvx/include/asm/hardirq.h|  14 ++
 arch/kvx/include/asm/hw_irq.h |  14 ++
 arch/kvx/include/asm/irqflags.h   |  58 +++
 arch/kvx/include/asm/stacktrace.h |  44 ++
 arch/kvx/include/asm/traps.h  |  76 ++
 arch/kvx/kernel/dame_handler.c| 113 ++
 arch/kvx/kernel/irq.c |  78 ++
 arch/kvx/kernel/traps.c   | 243 ++
 11 files changed, 807 insertions(+)
 create mode 100644 arch/kvx/include/asm/break_hook.h
 create mode 100644 arch/kvx/include/asm/bug.h
 create mode 100644 arch/kvx/include/asm/dame.h
 create mode 100644 arch/kvx/include/asm/hardirq.h
 create mode 100644 arch/kvx/include/asm/hw_irq.h
 create mode 100644 arch/kvx/include/asm/irqflags.h
 create mode 100644 arch/kvx/include/asm/stacktrace.h
 create mode 100644 arch/kvx/include/asm/traps.h
 create mode 100644 arch/kvx/kernel/dame_handler.c
 create mode 100644 arch/kvx/kernel/irq.c
 create mode 100644 arch/kvx/kernel/traps.c

diff --git a/arch/kvx/include/asm/break_hook.h 
b/arch/kvx/include/asm/break_hook.h
new file mode 100644
index ..333b2c440c81
--- /dev/null
+++ b/arch/kvx/include/asm/break_hook.h
@@ -0,0 +1,69 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#ifndef __ASM_KVX_BREAK_HOOK_H_
+#define __ASM_KVX_BREAK_HOOK_H_
+
+#include 
+
+#include 
+#include 
+
+/*
+ * The following macros define the different causes of break:
+ * We use the `set $vsfr0 = $rXX` instruction which will raise a trap into the
+ * debugger. The trapping instruction is read and decoded to extract the source
+ * register number. The source register number is used to differentiate the
+ * trap cause.
+ */
+#define BREAK_CAUSE_BUGKVX_REG_R1
+#define BREAK_CAUSE_KGDB_DYN   KVX_REG_R2
+#define BREAK_CAUSE_KGDB_COMP  KVX_REG_R3
+#define BREAK_CAUSE_BKPT   KVX_REG_R63
+
+/**
+ * enum break_ret - Break return value
+ * @BREAK_HOOK_HANDLED: Hook handled successfully
+ * @BREAK_HOOK_ERROR: Hook was not handled
+ */
+enum break_ret {
+   BREAK_HOOK_HANDLED = 0,
+   BREAK_HOOK_ERROR = 1,
+};
+
+/*
+ * The following macro assembles a `set` instruction targeting $vsfr0
+ * using the source register whose number is __id.
+ */
+#define KVX_BREAK_INSN(__id) \
+   KVX_INSN_SET_SYLLABLE_0(KVX_INSN_PARALLEL_EOB, KVX_SFR_VSFR0, __id)
+
+#define KVX_BREAK_INSN_SIZE (KVX_INSN_SET_SIZE * KVX_INSN_SYLLABLE_WIDTH)
+
+struct pt_regs;
+
+/**
+ * struct break_hook - Break hook description
+ * @node: List node
+ * @handler: handler called when break matches this hook
+ * @imm: Immediate value expected for break insn
+ * @mode: Hook mode (user/kernel)
+ */
+struct break_hook {
+   struct list_head node;
+   int (*handler)(struct break_hook *brk_hook, struct pt_regs *regs);
+   u8 id;
+   u8 mode;
+};
+
+void kvx_skip_break_insn(struct pt_regs *regs);
+
+void break_hook_register(struct break_hook *brk_hook);
+void break_hook_unregister(struct break_hook *brk_hook);
+
+int break_hook_handler(u64 es, struct pt_regs *regs);
+
+#endif /* __ASM_KVX_BREAK_HOOK_H_ */
diff --git a/arch/kvx/include/asm/bug.h b/arch/kvx/include/asm/bug.h
new file mode 100644
index ..62f556b00d5a
--- /dev/null
+++ b/arch/kvx/include/asm/bug.h
@@ -0,0 +1,67 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#ifndef _ASM_KVX_BUG_H
+#define _ASM_KVX_BUG_H
+
+#include 
+#include 
+#include 
+
+#include 
+
+#ifdef CONFIG_GENERIC_BUG
+
+#define BUG_INSN   KVX_BREAK_INSN(BREAK_CAUSE_BUG)
+
+#define __BUG_ENTRY_ADDR   ".dword 1b"
+
+#ifdef CONFIG_DEBUG_BUGVERBOSE
+#define __BUG_ENTRY_LAST_MEMBERflags
+#define __BUG_ENTRY\
+   __BUG_ENTRY_ADDR "\n\t" \
+   ".dword %0\n\t" \
+   ".short %1\n\t"
+#else
+#define __BUG_ENTRY_LAST_MEMBERfile
+#define __BUG_ENTRY\
+   __BUG_ENTRY_ADDR "\n\t"
+#endif
+
+#define BUG()  \
+do {   \
+   __asm__ __volatile__ (  \
+   "1:

[RFC PATCH v2 01/31] Documentation: kvx: Add basic documentation

2023-01-20 Thread Yann Sionneau
Add some documentation for the kvx architecture and its Linux port.

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Jules Maselbas 
Signed-off-by: Jules Maselbas 
Co-developed-by: Guillaume Thouvenin 
Signed-off-by: Guillaume Thouvenin 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2:
 - converted to .rst, typos and formatting fixes
 - reword few paragraphs

 Documentation/arch.rst   |   1 +
 Documentation/kvx/index.rst  |  17 ++
 Documentation/kvx/kvx-exceptions.rst | 256 
 Documentation/kvx/kvx-iommu.rst  | 191 ++
 Documentation/kvx/kvx-mmu.rst| 287 +++
 Documentation/kvx/kvx-smp.rst|  39 
 Documentation/kvx/kvx.rst| 273 +
 7 files changed, 1064 insertions(+)
 create mode 100644 Documentation/kvx/index.rst
 create mode 100644 Documentation/kvx/kvx-exceptions.rst
 create mode 100644 Documentation/kvx/kvx-iommu.rst
 create mode 100644 Documentation/kvx/kvx-mmu.rst
 create mode 100644 Documentation/kvx/kvx-smp.rst
 create mode 100644 Documentation/kvx/kvx.rst

diff --git a/Documentation/arch.rst b/Documentation/arch.rst
index 41a66a8b38e4..1ccda8ef6eef 100644
--- a/Documentation/arch.rst
+++ b/Documentation/arch.rst
@@ -13,6 +13,7 @@ implementation.
arm/index
arm64/index
ia64/index
+   kvx/index
loongarch/index
m68k/index
mips/index
diff --git a/Documentation/kvx/index.rst b/Documentation/kvx/index.rst
new file mode 100644
index ..0bac597b5fbe
--- /dev/null
+++ b/Documentation/kvx/index.rst
@@ -0,0 +1,17 @@
+.. SPDX-License-Identifier: GPL-2.0
+
+===
+Kalray kvx Architecture
+===
+
+.. toctree::
+   :maxdepth: 2
+   :numbered:
+
+   kvx
+   kvx-exceptions
+   kvx-smp
+   kvx-mmu
+   kvx-iommu
+
+
diff --git a/Documentation/kvx/kvx-exceptions.rst 
b/Documentation/kvx/kvx-exceptions.rst
new file mode 100644
index ..5e01e934192f
--- /dev/null
+++ b/Documentation/kvx/kvx-exceptions.rst
@@ -0,0 +1,256 @@
+==
+Exceptions
+==
+
+On kvx, handlers are set using ``$ev`` (exception vector) register which
+specifies a base address. An offset is added to ``$ev`` upon exception
+and the result is used as the new ``$pc``.
+The offset depends on which exception vector the cpu wants to jump to:
+
+  == =
+  ``$ev + 0x00`` debug
+  ``$ev + 0x40`` trap
+  ``$ev + 0x80`` interrupt
+  ``$ev + 0xc0`` syscall
+  == =
+
+Then, handlers are laid in the following order::
+
+ _
+| |
+|   Syscall   |
+|_|
+| |
+|  Interrupts |
+|_|
+| |
+|Traps|
+|_|
+| | ^
+|Debug| | Stride
+BASE -> |_| v
+
+
+Interrupts and traps are serviced similarly, ie:
+
+ - Jump to handler
+ - Save all registers
+ - Prepare the call (do_IRQ or trap_handler)
+ - restore all registers
+ - return from exception
+
+entry.S file is (as for other architectures) the entry point into the kernel.
+It contains all assembly routines related to interrupts/traps/syscall.
+
+Syscall handling
+
+
+When executing a syscall, it must be done using ``scall $r6`` where ``$r6``
+contains the syscall number. This convention allows to modify and restart
+a syscall from the kernel.
+
+Syscalls are handled differently than interrupts/exceptions. From an ABI
+point of view, syscalls are like function calls: any caller-saved register
+can be clobbered by the syscall. However, syscall parameters are passed
+using registers r0 through r7. These registers must be preserved to avoid
+clobberring them before the actual syscall function.
+
+On syscall from userspace (``scall`` instruction), the processor will put
+the syscall number in $es.sn and switch from user to kernel privilege
+mode. ``kvx_syscall_handler`` will be called in kernel mode.
+
+The following steps are then taken:
+
+ 1. Switch to kernel stack
+ 2. Extract syscall number
+ 3. If the syscall number is bogus, set the syscall function to 
``sys_ni_syscall``
+ 4. If tracing is enabled
+
+- Jump to ``trace_syscall_enter``
+- Save syscall arguments (``r0`` -> ``r7``) on stack in ``pt_regs``.
+- Call ``do_trace_syscall_enter`` function.
+
+ 5. Restore syscall arguments since they have been modified by C call
+ 6. Call the syscall function
+ 7. Save ``$r0`` in ``pt_regs`` since it can be clobberred afterward
+ 8. If tracing is enabled, call ``trace_syscall_exit``.
+ 9. Call ``work_pending``
+ 10. Return to user !
+
+The trace call is handled out of the fast path. All slow path handling
+is done in another part of code to avoid messing with the cache.
+
+Signals
+---
+
+Signals are handled when exiting kern

Re: [RFC PATCH v2 02/31] Documentation: Add binding for kalray,kv3-1-core-intc

2023-01-20 Thread Rob Herring


On Fri, 20 Jan 2023 15:09:33 +0100, Yann Sionneau wrote:
> From: Jules Maselbas 
> 
> Add documentation for `kalray,kv3-1-core-intc` binding.
> 
> Co-developed-by: Jules Maselbas 
> Signed-off-by: Jules Maselbas 
> Signed-off-by: Yann Sionneau 
> ---
> 
> Notes:
> V1 -> V2: new patch
> 
>  .../kalray,kv3-1-core-intc.yaml   | 46 +++
>  1 file changed, 46 insertions(+)
>  create mode 100644 
> Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-core-intc.yaml
> 

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-core-intc.yaml:
 properties:reg:maxItems: 0 is less than the minimum of 1
from schema $id: http://devicetree.org/meta-schemas/keywords.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-core-intc.yaml:
 $id: 
'http://devicetree.org/schemas/interrupt-controller/kalray,kv3-1-core-intc#' 
does not match 'http://devicetree.org/schemas/.*\\.yaml#'
from schema $id: http://devicetree.org/meta-schemas/base.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-core-intc.yaml:
 'maintainers' is a required property
hint: Metaschema for devicetree binding documentation
from schema $id: http://devicetree.org/meta-schemas/base.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-core-intc.yaml:
 'oneOf' conditional failed, one must be fixed:
'unevaluatedProperties' is a required property
'additionalProperties' is a required property
hint: Either unevaluatedProperties or additionalProperties must be 
present
from schema $id: http://devicetree.org/meta-schemas/core.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-core-intc.yaml:
 properties:reg: 'anyOf' conditional failed, one must be fixed:
'maxItems' is not one of ['description', 'deprecated', 'const', 'enum', 
'minimum', 'maximum', 'multipleOf', 'default', '$ref', 'oneOf']
1 was expected
hint: Only "maxItems" is required for a single entry if there 
are no constraints defined for the values.
0 is less than the minimum of 2
hint: Arrays must be described with a combination of 
minItems/maxItems/items
hint: cell array properties must define how many entries and what the 
entries are when there is more than one entry.
from schema $id: http://devicetree.org/meta-schemas/core.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-core-intc.yaml:
 properties: 'anyOf' conditional failed, one must be fixed:
'interrupt-controller' is a required property
'interrupt-map' is a required property
from schema $id: http://devicetree.org/meta-schemas/interrupts.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-core-intc.yaml:
 properties:kalray,intc-nr-irqs: 'oneOf' conditional failed, one must be fixed:
'type' is a required property
hint: A vendor boolean property can use "type: boolean"

/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-core-intc.yaml:
 properties:kalray,intc-nr-irqs: 'oneOf' conditional failed, one must be fixed:
'enum' is a required property
'const' is a required property
hint: A vendor string property with exact values has an 
implicit type
from schema $id: 
http://devicetree.org/meta-schemas/vendor-props.yaml#

/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-core-intc.yaml:
 properties:kalray,intc-nr-irqs: 'oneOf' conditional failed, one must be fixed:
'$ref' is a required property
'allOf' is a required property
hint: A vendor property needs a $ref to types.yaml
from schema $id: 
http://devicetree.org/meta-schemas/vendor-props.yaml#
hint: Vendor specific properties must have a type and description 
unless they have a defined, common suffix.
from schema $id: http://devicetree.org/meta-schemas/vendor-props.yaml#
./Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-core-intc.yaml:
 $id: relative path/filename doesn't match actual path or filename
expected: 
http://devicetree.org/schemas/interrupt-controller/kalray,kv3-1-core-intc.yaml#

doc reference errors (make refcheckdocs):

See 
https://patchwork.ozlabs.org/project/devicetree-bindings/patch/2023012

[RFC PATCH v2 07/31] Documentation: Add binding for kalray,kv3-1-pwr-ctrl

2023-01-20 Thread Yann Sionneau
From: Jules Maselbas 

Add documentation for `kalray,kv3-1-pwr-ctrl` binding.

Co-developed-by: Jules Maselbas 
Signed-off-by: Jules Maselbas 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: new patch

 .../kalray/kalray,kv3-1-pwr-ctrl.yaml | 29 +++
 1 file changed, 29 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/kalray/kalray,kv3-1-pwr-ctrl.yaml

diff --git 
a/Documentation/devicetree/bindings/kalray/kalray,kv3-1-pwr-ctrl.yaml 
b/Documentation/devicetree/bindings/kalray/kalray,kv3-1-pwr-ctrl.yaml
new file mode 100644
index ..968674bb0c63
--- /dev/null
+++ b/Documentation/devicetree/bindings/kalray/kalray,kv3-1-pwr-ctrl.yaml
@@ -0,0 +1,29 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/kalray/kalray,kv3-1-pwr-ctrl#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Kalray cluster Power Controller (pwr-ctrl)
+
+description: |
+  The Power Controller (pwr-ctrl) control cores reset and wake-up procedure.
+
+properties:
+  compatible:
+const: kalray,kv3-1-pwr-ctrl
+  reg:
+maxItems: 1
+
+required:
+  - compatible
+  - reg
+
+examples:
+  - |
+pwr_ctrl: power-controller@a4 {
+compatible = "kalray,kv3-1-pwr-ctrl";
+reg = <0x00 0xa4 0x00 0x4158>;
+};
+
+...
-- 
2.37.2





--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



Re: [RFC PATCH v2 07/31] Documentation: Add binding for kalray, kv3-1-pwr-ctrl

2023-01-20 Thread Rob Herring


On Fri, 20 Jan 2023 15:09:38 +0100, Yann Sionneau wrote:
> From: Jules Maselbas 
> 
> Add documentation for `kalray,kv3-1-pwr-ctrl` binding.
> 
> Co-developed-by: Jules Maselbas 
> Signed-off-by: Jules Maselbas 
> Signed-off-by: Yann Sionneau 
> ---
> 
> Notes:
> V1 -> V2: new patch
> 
>  .../kalray/kalray,kv3-1-pwr-ctrl.yaml | 29 +++
>  1 file changed, 29 insertions(+)
>  create mode 100644 
> Documentation/devicetree/bindings/kalray/kalray,kv3-1-pwr-ctrl.yaml
> 

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/kalray/kalray,kv3-1-pwr-ctrl.yaml:
 $id: 'http://devicetree.org/schemas/kalray/kalray,kv3-1-pwr-ctrl#' does not 
match 'http://devicetree.org/schemas/.*\\.yaml#'
from schema $id: http://devicetree.org/meta-schemas/base.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/kalray/kalray,kv3-1-pwr-ctrl.yaml:
 'maintainers' is a required property
hint: Metaschema for devicetree binding documentation
from schema $id: http://devicetree.org/meta-schemas/base.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/kalray/kalray,kv3-1-pwr-ctrl.yaml:
 'oneOf' conditional failed, one must be fixed:
'unevaluatedProperties' is a required property
'additionalProperties' is a required property
hint: Either unevaluatedProperties or additionalProperties must be 
present
from schema $id: http://devicetree.org/meta-schemas/core.yaml#
./Documentation/devicetree/bindings/kalray/kalray,kv3-1-pwr-ctrl.yaml: $id: 
relative path/filename doesn't match actual path or filename
expected: 
http://devicetree.org/schemas/kalray/kalray,kv3-1-pwr-ctrl.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/kalray/kalray,kv3-1-pwr-ctrl.example.dtb:
 power-controller@a4: reg: [[0, 10747904], [0, 16728]] is too long
From schema: 
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/kalray/kalray,kv3-1-pwr-ctrl.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/kalray/kalray,kv3-1-pwr-ctrl.example.dtb:
 power-controller@a4: '#power-domain-cells' is a required property
From schema: 
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/power/power-domain.yaml

doc reference errors (make refcheckdocs):

See 
https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20230120141002.2442-8-ysionn...@kalray.eu

The base for the series is generally the latest rc1. A different dependency
should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note
that DT_SCHEMA_FILES can be set to your schema file to speed up checking
your schema. However, it must be unset to test all examples with your schema.

--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



[RFC PATCH v2 13/31] kvx: Add boot and setup routines

2023-01-20 Thread Yann Sionneau
Add basic boot, setup and reset routines for kvx.

Co-developed-by: Alex Michon 
Signed-off-by: Alex Michon 
Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Guillaume Missonnier 
Signed-off-by: Guillaume Missonnier 
Co-developed-by: Guillaume Thouvenin 
Signed-off-by: Guillaume Thouvenin 
Co-developed-by: Jules Maselbas 
Signed-off-by: Jules Maselbas 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Co-developed-by: Julien Hascoet 
Signed-off-by: Julien Hascoet 
Co-developed-by: Julien Villette 
Signed-off-by: Julien Villette 
Co-developed-by: Marc Poulhiès 
Signed-off-by: Marc Poulhiès 
Co-developed-by: Luc Michel 
Signed-off-by: Luc Michel 
Co-developed-by: Marius Gligor 
Signed-off-by: Marius Gligor 
Co-developed-by: Yann Sionneau 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: removed L2 cache firmware starting code

 arch/kvx/include/asm/setup.h |  29 ++
 arch/kvx/kernel/common.c |  11 +
 arch/kvx/kernel/head.S   | 568 +++
 arch/kvx/kernel/prom.c   |  24 ++
 arch/kvx/kernel/reset.c  |  37 +++
 arch/kvx/kernel/setup.c  | 177 +++
 arch/kvx/kernel/time.c   | 242 +++
 7 files changed, 1088 insertions(+)
 create mode 100644 arch/kvx/include/asm/setup.h
 create mode 100644 arch/kvx/kernel/common.c
 create mode 100644 arch/kvx/kernel/head.S
 create mode 100644 arch/kvx/kernel/prom.c
 create mode 100644 arch/kvx/kernel/reset.c
 create mode 100644 arch/kvx/kernel/setup.c
 create mode 100644 arch/kvx/kernel/time.c

diff --git a/arch/kvx/include/asm/setup.h b/arch/kvx/include/asm/setup.h
new file mode 100644
index ..9c27d5981442
--- /dev/null
+++ b/arch/kvx/include/asm/setup.h
@@ -0,0 +1,29 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#ifndef _ASM_KVX_SETUP_H
+#define _ASM_KVX_SETUP_H
+
+#include 
+
+#include 
+
+/* Magic is found in r0 when some parameters are given to kernel */
+#define LINUX_BOOT_PARAM_MAGIC ULL(0x31564752414E494C)
+
+#ifndef __ASSEMBLY__
+
+void early_fixmap_init(void);
+
+void setup_device_tree(void);
+
+void setup_arch_memory(void);
+
+void kvx_init_mmu(void);
+
+#endif
+
+#endif /* _ASM_KVX_SETUP_H */
diff --git a/arch/kvx/kernel/common.c b/arch/kvx/kernel/common.c
new file mode 100644
index ..322498f034fd
--- /dev/null
+++ b/arch/kvx/kernel/common.c
@@ -0,0 +1,11 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#include 
+#include 
+
+DEFINE_PER_CPU(int, __preempt_count) = INIT_PREEMPT_COUNT;
+EXPORT_PER_CPU_SYMBOL(__preempt_count);
diff --git a/arch/kvx/kernel/head.S b/arch/kvx/kernel/head.S
new file mode 100644
index ..6badd2f6a2a6
--- /dev/null
+++ b/arch/kvx/kernel/head.S
@@ -0,0 +1,568 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ *Guillaume Thouvenin
+ *Marius Gligor
+ *Julian Vetter
+ *Julien Hascoet
+ *Yann Sionneau
+ *Marc Poulhiès
+ */
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#ifdef CONFIG_SMP
+#define SECONDARY_START_ADDR   smp_secondary_start
+#else
+#define SECONDARY_START_ADDR   proc_power_off
+#endif
+
+#define PS_VAL_WFXL(__field, __val) \
+   SFR_SET_VAL_WFXL(PS, __field, __val)
+
+#define PS_WFXL_VALUE  PS_VAL_WFXL(HLE, 1) | \
+   PS_VAL_WFXL(USE, 1) | \
+   PS_VAL_WFXL(DCE, 1) | \
+   PS_VAL_WFXL(ICE, 1) | \
+   PS_VAL_WFXL(MME, 1) | \
+   PS_VAL_WFXL(MMUP, 1) | \
+   PS_VAL_WFXL(ET, 0) | \
+   PS_VAL_WFXL(HTD, 0) | \
+   PS_VAL_WFXL(PMJ, KVX_SUPPORTED_PSIZE)
+
+#define PCR_VAL_WFXM(__field, __val) \
+   SFR_SET_VAL_WFXM(PCR, __field, __val)
+
+#define PCR_WFXM_VALUE PCR_VAL_WFXM(L1CE, 1)
+
+/* 30 sec for primary watchdog timeout */
+#define PRIMARY_WATCHDOG_VALUE (300UL)
+
+#define TCR_WFXL_VALUE SFR_SET_VAL_WFXL(TCR, WUI, 1) | \
+   SFR_SET_VAL_WFXL(TCR, WCE, 1)
+
+/* Enable STOP in WS */
+#define WS_ENABLE_WU2  (KVX_SFR_WS_WU2_MASK)
+/* We only want to clear bits in ws */
+#define WS_WFXL_VALUE  (WS_ENABLE_WU2)
+
+/* SMP stuff */
+#define RM_PID_MASK((KVX_RM_ID) << KVX_SFR_PCR_PID_SHIFT)
+
+#define PWR_CTRL_ADDR 0xA4
+
+#define PWR_CTRL_GLOBAL_CONFIG_VALUE \
+   (1 << KVX_PWR_CTRL_GLOBAL_SET_PE_EN_SHIFT)
+
+/* Clean error and selected buffer */
+#define MMC_CLEAR_ERROR (KVX_SFR_MMC_E_MASK)
+
+#define TEH_VIRTUAL_MEMORY \
+   TLB_MK_TEH_ENTRY(PAGE_OFFSET, 0, TLB_G_GLOBAL, 0)
+
+#define TEL_VIRTUAL_MEMORY \
+   TLB_MK_TEL_ENTRY(PHYS_OFFSET, TLB_PS_512M, TLB_ES_A_MODIFIED,\
+   

Re: [RFC PATCH v2 06/31] Documentation: Add binding for kalray, kv3-1-ipi-ctrl

2023-01-20 Thread Rob Herring


On Fri, 20 Jan 2023 15:09:37 +0100, Yann Sionneau wrote:
> From: Jules Maselbas 
> 
> Add documentation for `kalray,kv3-1-ipi-ctrl` binding.
> 
> Co-developed-by: Jules Maselbas 
> Signed-off-by: Jules Maselbas 
> Signed-off-by: Yann Sionneau 
> ---
> 
> Notes:
> V1 -> V2: new patch
> 
>  .../kalray/kalray,kv3-1-ipi-ctrl.yaml | 44 +++
>  1 file changed, 44 insertions(+)
>  create mode 100644 
> Documentation/devicetree/bindings/kalray/kalray,kv3-1-ipi-ctrl.yaml
> 

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/kalray/kalray,kv3-1-ipi-ctrl.yaml:
 $id: 'http://devicetree.org/schemas/kalray/kalray,kv3-1-ipi-ctrl#' does not 
match 'http://devicetree.org/schemas/.*\\.yaml#'
from schema $id: http://devicetree.org/meta-schemas/base.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/kalray/kalray,kv3-1-ipi-ctrl.yaml:
 'maintainers' is a required property
hint: Metaschema for devicetree binding documentation
from schema $id: http://devicetree.org/meta-schemas/base.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/kalray/kalray,kv3-1-ipi-ctrl.yaml:
 'oneOf' conditional failed, one must be fixed:
'unevaluatedProperties' is a required property
'additionalProperties' is a required property
hint: Either unevaluatedProperties or additionalProperties must be 
present
from schema $id: http://devicetree.org/meta-schemas/core.yaml#
./Documentation/devicetree/bindings/kalray/kalray,kv3-1-ipi-ctrl.yaml: $id: 
relative path/filename doesn't match actual path or filename
expected: 
http://devicetree.org/schemas/kalray/kalray,kv3-1-ipi-ctrl.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/kalray/kalray,kv3-1-ipi-ctrl.example.dtb:
 inter-processor-interrupt@ad: reg: [[0, 11337728], [0, 4096]] is too long
From schema: 
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/kalray/kalray,kv3-1-ipi-ctrl.yaml
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/kalray/kalray,kv3-1-ipi-ctrl.example.dtb:
 inter-processor-interrupt@ad: 'interrupt-parent' is a required property
From schema: 
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/kalray/kalray,kv3-1-ipi-ctrl.yaml

doc reference errors (make refcheckdocs):

See 
https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20230120141002.2442-7-ysionn...@kalray.eu

The base for the series is generally the latest rc1. A different dependency
should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note
that DT_SCHEMA_FILES can be set to your schema file to speed up checking
your schema. However, it must be unset to test all examples with your schema.

--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



[RFC PATCH v2 03/31] Documentation: Add binding for kalray,kv3-1-apic-gic

2023-01-20 Thread Yann Sionneau
From: Jules Maselbas 

Add documentation for `kalray,kv3-1-apic-gic` binding.

Co-developed-by: Jules Maselbas 
Signed-off-by: Jules Maselbas 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: new patch

 .../kalray,kv3-1-apic-gic.yaml| 66 +++
 1 file changed, 66 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-apic-gic.yaml

diff --git 
a/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-apic-gic.yaml
 
b/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-apic-gic.yaml
new file mode 100644
index ..7a37f19db2fb
--- /dev/null
+++ 
b/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-apic-gic.yaml
@@ -0,0 +1,66 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/interrupt-controller/kalray,kv3-1-apic-gic#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Kalray kv3-1 APIC-GIC
+
+description: |
+  Each cluster in the Coolidge SoC includes an Advanced Programmable Interrupt
+  Controller (APIC) which is split in two part:
+- a Generic Interrupt Controller (referred as APIC-GIC)
+- a Mailbox Controller   (referred as APIC-Mailbox)
+  The APIC-GIC acts as an intermediary interrupt controller, muxing/routing
+  incoming interrupts to output interrupts connected to kvx cores interrupts 
lines.
+  The 139 possible input interrupt lines are organized as follow:
+ - 128 from the mailbox controller (one it per mailboxes)
+ - 1   from the NoC router
+ - 5   from IOMMUs
+ - 1   from L2 cache DMA job FIFO
+ - 1   from cluster watchdog
+ - 2   for SECC, DECC
+ - 1   from Data NoC
+  The 72 possible output interrupt lines:
+ -  68 : 4 interrupts per cores (17 cores)
+ -  1 for L2 cache controller
+ -  3 extra that are for padding
+
+allOf:
+  - $ref: /schemas/interrupt-controller.yaml#
+
+properties:
+  compatible:
+const: kalray,kv3-1-apic-gic
+  "#interrupt-cells":
+const: 1
+description:
+  The IRQ number.
+  interrupt-controller: true
+  interrupt-parent: true
+  interrupts:
+maxItems: 4
+description: |
+ Specifies the interrupt line(s) in the interrupt-parent controller node;
+ valid values depend on the type of parent interrupt controller
+
+required:
+  - compatible
+  - reg
+  - "#interrupt-cells"
+  - interrupt-controller
+  - interrupt-parent
+  - interrupts
+
+examples:
+  - |
+apic_gic: interrupt-controller@a2 {
+compatible = "kalray,kv3-1-apic-gic";
+reg = <0 0xa2 0 0x12000>;
+#interrupt-cells = <1>;
+interrupt-controller;
+interrupt-parent = <&intc>;
+interrups = <4 5 6 7>;
+};
+
+...
-- 
2.37.2





--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



[RFC PATCH v2 25/31] kvx: Add some library functions

2023-01-20 Thread Yann Sionneau
Add some library functions for kvx, including: delay, memset,
memcpy, strlen, clear_page, copy_page, raw_copy_from/to_user,
asm_clear_user.

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Jules Maselbas 
Signed-off-by: Jules Maselbas 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Co-developed-by: Marius Gligor 
Signed-off-by: Marius Gligor 
Co-developed-by: Yann Sionneau 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: no changes

 arch/kvx/include/asm/string.h |  20 ++
 arch/kvx/kernel/kvx_ksyms.c   |   5 +
 arch/kvx/lib/clear_page.S |  40 
 arch/kvx/lib/copy_page.S  |  90 +
 arch/kvx/lib/delay.c  |  39 
 arch/kvx/lib/memcpy.c |  70 +++
 arch/kvx/lib/memset.S | 351 ++
 arch/kvx/lib/strlen.S | 122 
 arch/kvx/lib/usercopy.S   |  90 +
 9 files changed, 827 insertions(+)
 create mode 100644 arch/kvx/include/asm/string.h
 create mode 100644 arch/kvx/lib/clear_page.S
 create mode 100644 arch/kvx/lib/copy_page.S
 create mode 100644 arch/kvx/lib/delay.c
 create mode 100644 arch/kvx/lib/memcpy.c
 create mode 100644 arch/kvx/lib/memset.S
 create mode 100644 arch/kvx/lib/strlen.S
 create mode 100644 arch/kvx/lib/usercopy.S

diff --git a/arch/kvx/include/asm/string.h b/arch/kvx/include/asm/string.h
new file mode 100644
index ..677c1393a5cd
--- /dev/null
+++ b/arch/kvx/include/asm/string.h
@@ -0,0 +1,20 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ *Jules Maselbas
+ */
+
+#ifndef _ASM_KVX_STRING_H
+#define _ASM_KVX_STRING_H
+
+#define __HAVE_ARCH_MEMSET
+extern void *memset(void *s, int c, size_t n);
+
+#define __HAVE_ARCH_MEMCPY
+extern void *memcpy(void *dest, const void *src, size_t n);
+
+#define __HAVE_ARCH_STRLEN
+extern size_t strlen(const char *s);
+
+#endif /* _ASM_KVX_STRING_H */
diff --git a/arch/kvx/kernel/kvx_ksyms.c b/arch/kvx/kernel/kvx_ksyms.c
index 18990aaf259f..678f81716dea 100644
--- a/arch/kvx/kernel/kvx_ksyms.c
+++ b/arch/kvx/kernel/kvx_ksyms.c
@@ -22,3 +22,8 @@ DECLARE_EXPORT(__umoddi3);
 DECLARE_EXPORT(__divdi3);
 DECLARE_EXPORT(__udivdi3);
 DECLARE_EXPORT(__multi3);
+
+DECLARE_EXPORT(clear_page);
+DECLARE_EXPORT(copy_page);
+DECLARE_EXPORT(memset);
+DECLARE_EXPORT(asm_clear_user);
diff --git a/arch/kvx/lib/clear_page.S b/arch/kvx/lib/clear_page.S
new file mode 100644
index ..364fe0663ca2
--- /dev/null
+++ b/arch/kvx/lib/clear_page.S
@@ -0,0 +1,40 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Marius Gligor
+ *Clement Leger
+ */
+
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+#define CLEAR_PAGE_LOOP_COUNT  (PAGE_SIZE / 32)
+
+/*
+ * Clear page @dest.
+ *
+ * Parameters:
+ * r0 - dest page
+ */
+ENTRY(clear_page)
+   make $r1 = CLEAR_PAGE_LOOP_COUNT
+   ;;
+   make $r4 = 0
+   make $r5 = 0
+   make $r6 = 0
+   make $r7 = 0
+   ;;
+
+   loopdo $r1, clear_page_done
+   ;;
+   so 0[$r0] = $r4r5r6r7
+   addd $r0 = $r0, 32
+   ;;
+   clear_page_done:
+   ret
+   ;;
+ENDPROC(clear_page)
diff --git a/arch/kvx/lib/copy_page.S b/arch/kvx/lib/copy_page.S
new file mode 100644
index ..4bb82d1c964c
--- /dev/null
+++ b/arch/kvx/lib/copy_page.S
@@ -0,0 +1,90 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#include 
+#include 
+
+#include 
+
+/* We have 8 load/store octuple (32 bytes) per hardware loop */
+#define COPY_SIZE_PER_LOOP (32 * 8)
+#define COPY_PAGE_LOOP_COUNT   (PAGE_SIZE / COPY_SIZE_PER_LOOP)
+
+/*
+ * Copy a page from src to dest (both are page aligned)
+ * In order to recover from smem latency, unroll the loop to trigger multiple
+ * onfly loads and avoid waiting too much for them to return.
+ * We use 8 * 32 load even though we could use more (up to 10 loads) to 
simplify
+ * the handling using a single hardware loop
+ *
+ * Parameters:
+ * r0 - dest
+ * r1 - src
+ */
+ENTRY(copy_page)
+   make $r2 = COPY_PAGE_LOOP_COUNT
+   make $r3 = 0
+   ;;
+   loopdo $r2, copy_page_done
+   ;;
+   /*
+* Load 8 * 32 bytes using uncached access to avoid hitting
+* the cache
+*/
+   lo.xs $r32r33r34r35 = $r3[$r1]
+   /* Copy current copy index for store */
+   copyd $r2 = $r3
+   addd $r3 = $r3, 1
+   ;;
+   lo.xs $r36r37r38r39 = $r3[$r1]
+   addd $r3 = $r3, 1
+   ;;
+   lo.xs $r40r41r42r43 = $r3[$r1]
+   addd $r3 = $r3, 1
+   ;;
+   lo.xs $r44r45r46r47 = $r3[$r1]
+   addd $r3 = $r3, 1
+   ;;
+ 

[RFC PATCH v2 09/31] kvx: Add build infrastructure

2023-01-20 Thread Yann Sionneau
Add Kbuild, Makefile, Kconfig and link script for kvx build infrastructure.

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Guillaume Thouvenin 
Signed-off-by: Guillaume Thouvenin 
Co-developed-by: Jonathan Borne 
Signed-off-by: Jonathan Borne 
Co-developed-by: Jules Maselbas 
Signed-off-by: Jules Maselbas 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Co-developed-by: Marc Poulhiès 
Signed-off-by: Marc Poulhiès 
Co-developed-by: Marius Gligor 
Signed-off-by: Marius Gligor 
Co-developed-by: Samuel Jones 
Signed-off-by: Samuel Jones 
Co-developed-by: Vincent Chardon 
Signed-off-by: Vincent Chardon 
Co-developed-by: Yann Sionneau 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2:
 - typos and formatting fixes, removed int from PGTABLE_LEVELS
 - renamed default_defconfig to defconfig in arch/kvx/Makefile
 - Fix clean target raising an error from gcc (LIBGCC)

 arch/kvx/Kconfig | 224 +++
 arch/kvx/Kconfig.debug   |  70 ++
 arch/kvx/Makefile|  53 
 arch/kvx/include/asm/Kbuild  |  20 +++
 arch/kvx/include/uapi/asm/Kbuild |   1 +
 arch/kvx/kernel/Makefile |  15 +++
 arch/kvx/kernel/kvx_ksyms.c  |  24 
 arch/kvx/kernel/vmlinux.lds.S| 150 +
 arch/kvx/lib/Makefile|   6 +
 arch/kvx/mm/Makefile |   8 ++
 10 files changed, 571 insertions(+)
 create mode 100644 arch/kvx/Kconfig
 create mode 100644 arch/kvx/Kconfig.debug
 create mode 100644 arch/kvx/Makefile
 create mode 100644 arch/kvx/include/asm/Kbuild
 create mode 100644 arch/kvx/include/uapi/asm/Kbuild
 create mode 100644 arch/kvx/kernel/Makefile
 create mode 100644 arch/kvx/kernel/kvx_ksyms.c
 create mode 100644 arch/kvx/kernel/vmlinux.lds.S
 create mode 100644 arch/kvx/lib/Makefile
 create mode 100644 arch/kvx/mm/Makefile

diff --git a/arch/kvx/Kconfig b/arch/kvx/Kconfig
new file mode 100644
index ..0bdba6a3b08a
--- /dev/null
+++ b/arch/kvx/Kconfig
@@ -0,0 +1,224 @@
+#
+# For a description of the syntax of this configuration file,
+# see Documentation/kbuild/kconfig-language.txt.
+#
+
+config 64BIT
+   def_bool y
+
+config GENERIC_CALIBRATE_DELAY
+   def_bool y
+
+config FIX_EARLYCON_MEM
+   def_bool y
+
+config MMU
+   def_bool y
+
+config KALLSYMS_BASE_RELATIVE
+   def_bool n
+
+config GENERIC_CSUM
+   def_bool y
+
+config RWSEM_GENERIC_SPINLOCK
+   def_bool y
+
+config GENERIC_HWEIGHT
+   def_bool y
+
+config ARCH_MMAP_RND_BITS_MAX
+   default 24
+
+config ARCH_MMAP_RND_BITS_MIN
+   default 18
+
+config STACKTRACE_SUPPORT
+   def_bool y
+
+config LOCKDEP_SUPPORT
+   def_bool y
+
+config GENERIC_BUG
+   def_bool y
+   depends on BUG
+
+config KVX_4K_PAGES
+   def_bool y
+
+config KVX
+   def_bool y
+   select ARCH_CLOCKSOURCE_DATA
+   select ARCH_DMA_ADDR_T_64BIT
+   select ARCH_HAS_DEVMEM_IS_ALLOWED
+   select ARCH_HAS_DMA_PREP_COHERENT
+   select ARCH_HAS_ELF_RANDOMIZE
+   select ARCH_HAS_PTE_SPECIAL
+   select ARCH_HAS_SETUP_DMA_OPS if IOMMU_SUPPORT
+   select ARCH_HAS_SYNC_DMA_FOR_DEVICE
+   select ARCH_HAS_SYNC_DMA_FOR_CPU
+   select ARCH_HAS_TEARDOWN_DMA_OPS if IOMMU_SUPPORT
+   select ARCH_OPTIONAL_KERNEL_RWX_DEFAULT
+   select ARCH_USE_QUEUED_SPINLOCKS
+   select ARCH_USE_QUEUED_RWLOCKS
+   select ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT
+   select ARCH_WANT_FRAME_POINTERS
+   select CLKSRC_OF
+   select COMMON_CLK
+   select DMA_DIRECT_REMAP
+   select GENERIC_ALLOCATOR
+   select GENERIC_CLOCKEVENTS
+   select GENERIC_CLOCKEVENTS
+   select GENERIC_CPU_DEVICES
+   select GENERIC_IOMAP
+   select GENERIC_IOREMAP
+   select GENERIC_IRQ_CHIP
+   select GENERIC_IRQ_PROBE
+   select GENERIC_IRQ_SHOW
+   select GENERIC_SCHED_CLOCK
+   select HAVE_ARCH_AUDITSYSCALL
+   select HAVE_ARCH_BITREVERSE
+   select HAVE_ARCH_MMAP_RND_BITS
+   select HAVE_ASM_MODVERSIONS
+   select HAVE_DEBUG_KMEMLEAK
+   select HAVE_EFFICIENT_UNALIGNED_ACCESS
+   select HAVE_FUTEX_CMPXCHG if FUTEX
+   select HAVE_IOREMAP_PROT
+   select HAVE_MEMBLOCK_NODE_MAP
+   select HAVE_PCI
+   select HAVE_STACKPROTECTOR
+   select HAVE_SYSCALL_TRACEPOINTS
+   select IOMMU_DMA if IOMMU_SUPPORT
+   select KVX_APIC_GIC
+   select KVX_APIC_MAILBOX
+   select KVX_CORE_INTC
+   select KVX_ITGEN
+   select KVX_WATCHDOG
+   select MODULES_USE_ELF_RELA
+   select OF
+   select OF_EARLY_FLATTREE
+   select OF_RESERVED_MEM
+   select PCI_DOMAINS_GENERIC if PCI
+   select SPARSE_IRQ
+   select SYSCTL_EXCEPTION_TRACE
+   select THREAD_INFO_IN_TASK
+   select TIMER_OF
+   select TRACE_IRQFLAGS_SUPPORT
+   select WATCHDOG
+   select ZONE_DMA32
+
+config PGTABLE_LEVELS
+   default 3
+
+config 

[RFC PATCH v2 18/31] irqchip: Add kvx-core-intc core interupt controller driver

2023-01-20 Thread Yann Sionneau
From: Jules Maselbas 

Each kvx core includes a hardware interrupt controller (core INTC)
with the following features:
 - 32 independent interrupt sources
 - 4-bit priotity level
 - Individual interrupt enable bit
 - Interrupt status bit displaying the pending interrupts
 - Priority management between the 32 interrupts

Among those 32 interrupt sources, the first are hard-wired to hardware
sources. The remaining interrupt sources can be triggered via software
by directly writing to the ILR SFR.

The hard-wired interrupt sources are the following:
  0: Timer 0
  1: Timer 1
  2: Watchdog
  3: Performance Monitors
  4: APIC GIC line 0
  5: APIC GIC line 1
  6: APIC GIC line 2
  7: APIC GIC line 3
 12: SECC error from memory system
 13: Arithmetic exception (carry and IEEE 754 flags)
 16: Data Asynchronous Memory Error (DAME), raised for DECC/DSYS errors
 17: CLI (Cache Line Invalidation) for L1D or L1I following
 DECC/DSYS/Parity errors

The APIC GIC lines will be used to route interrupts coming from SoC
peripherals from outside the Cluster to the kvx core. Those peripherals
include USB host controller, eMMC/SD host controller, i2c, spi, PCIe,
IOMMUs etc...

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Co-developed-by: Vincent Chardon 
Signed-off-by: Vincent Chardon 
Co-developed-by: Jules Maselbas 
Signed-off-by: Jules Maselbas 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: new patch
 - removed print on probe success

 drivers/irqchip/Kconfig |  5 ++
 drivers/irqchip/Makefile|  1 +
 drivers/irqchip/irq-kvx-core-intc.c | 80 +
 3 files changed, 86 insertions(+)
 create mode 100644 drivers/irqchip/irq-kvx-core-intc.c

diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
index 806adbc7b2a4..d242e02771e3 100644
--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -334,6 +334,11 @@ config MIPS_GIC
select IRQ_DOMAIN_HIERARCHY
select MIPS_CM
 
+config KVX_CORE_INTC
+   bool
+   depends on KVX
+   select IRQ_DOMAIN
+
 config KVX_APIC_GIC
bool
depends on KVX
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index 7eaea87ca9ab..d931f2eb38b6 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -69,6 +69,7 @@ obj-$(CONFIG_BCM7120_L2_IRQ)  += irq-bcm7120-l2.o
 obj-$(CONFIG_BRCMSTB_L2_IRQ)   += irq-brcmstb-l2.o
 obj-$(CONFIG_KEYSTONE_IRQ) += irq-keystone.o
 obj-$(CONFIG_MIPS_GIC) += irq-mips-gic.o
+obj-$(CONFIG_KVX_CORE_INTC)+= irq-kvx-core-intc.o
 obj-$(CONFIG_KVX_APIC_GIC) += irq-kvx-apic-gic.o
 obj-$(CONFIG_KVX_ITGEN)+= irq-kvx-itgen.o
 obj-$(CONFIG_KVX_APIC_MAILBOX) += irq-kvx-apic-mailbox.o
diff --git a/drivers/irqchip/irq-kvx-core-intc.c 
b/drivers/irqchip/irq-kvx-core-intc.c
new file mode 100644
index ..145f1248925b
--- /dev/null
+++ b/drivers/irqchip/irq-kvx-core-intc.c
@@ -0,0 +1,80 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#define pr_fmt(fmt)"kvx_core_intc: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define KVX_CORE_INTC_IRQ  32
+
+
+static void kvx_irq_mask(struct irq_data *data)
+{
+   kvx_sfr_clear_bit(ILE, data->hwirq);
+}
+
+static void kvx_irq_unmask(struct irq_data *data)
+{
+   kvx_sfr_set_bit(ILE, data->hwirq);
+}
+
+static struct irq_chip kvx_irq_chip = {
+   .name   = "kvx core Intc",
+   .irq_mask   = kvx_irq_mask,
+   .irq_unmask = kvx_irq_unmask,
+};
+
+static int kvx_irq_map(struct irq_domain *d, unsigned int irq,
+irq_hw_number_t hw)
+{
+   /* All interrupts for core are per cpu */
+   irq_set_percpu_devid(irq);
+   irq_set_chip_and_handler(irq, &kvx_irq_chip, handle_percpu_irq);
+
+   return 0;
+}
+
+static const struct irq_domain_ops kvx_irq_ops = {
+   .xlate = irq_domain_xlate_onecell,
+   .map = kvx_irq_map,
+};
+
+static int __init
+kvx_init_core_intc(struct device_node *intc, struct device_node *parent)
+{
+   struct irq_domain *root_domain;
+   uint32_t core_nr_irqs;
+
+   if (parent)
+   panic("DeviceTree core intc not a root irq controller\n");
+
+   if (of_property_read_u32(intc, "kalray,intc-nr-irqs", &core_nr_irqs))
+   core_nr_irqs = KVX_CORE_INTC_IRQ;
+
+   /* We only have up to 32 interrupts, according to IRQ-domain.txt,
+* linear is likely to be the best choice
+*/
+   root_domain = irq_domain_add_linear(intc, core_nr_irqs,
+   &kvx_irq_ops, NULL);
+   if (!root_domain)
+   panic("root irq domain not avail\n");
+
+   /*
+* Needed for primary domain lookup to succeed
+* T

[RFC PATCH v2 28/31] kvx: Add debugging related support

2023-01-20 Thread Yann Sionneau
Add kvx support for debugging

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Guillaume Thouvenin 
Signed-off-by: Guillaume Thouvenin 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Co-developed-by: Marius Gligor 
Signed-off-by: Marius Gligor 
Co-developed-by: Yann Sionneau 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: no changes

 arch/kvx/include/asm/debug.h  |  35 ++
 arch/kvx/include/asm/insns.h  |  16 +++
 arch/kvx/include/asm/insns_defs.h | 197 ++
 arch/kvx/kernel/break_hook.c  |  76 
 arch/kvx/kernel/debug.c   |  64 ++
 arch/kvx/kernel/insns.c   | 144 ++
 6 files changed, 532 insertions(+)
 create mode 100644 arch/kvx/include/asm/debug.h
 create mode 100644 arch/kvx/include/asm/insns.h
 create mode 100644 arch/kvx/include/asm/insns_defs.h
 create mode 100644 arch/kvx/kernel/break_hook.c
 create mode 100644 arch/kvx/kernel/debug.c
 create mode 100644 arch/kvx/kernel/insns.c

diff --git a/arch/kvx/include/asm/debug.h b/arch/kvx/include/asm/debug.h
new file mode 100644
index ..f60c632e6697
--- /dev/null
+++ b/arch/kvx/include/asm/debug.h
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#ifndef __ASM_KVX_DEBUG_HOOK_H_
+#define __ASM_KVX_DEBUG_HOOK_H_
+
+/**
+ * enum debug_ret - Break return value
+ * @DEBUG_HOOK_HANDLED: Hook handled successfully
+ * @DEBUG_HOOK_IGNORED: Hook call has been ignored
+ */
+enum debug_ret {
+   DEBUG_HOOK_HANDLED = 0,
+   DEBUG_HOOK_IGNORED = 1,
+};
+
+/**
+ * struct debug_hook - Debug hook description
+ * @node: List node
+ * @handler: handler called on debug entry
+ * @mode: Hook mode (user/kernel)
+ */
+struct debug_hook {
+   struct list_head node;
+   int (*handler)(u64 ea, struct pt_regs *regs);
+   u8 mode;
+};
+
+void debug_hook_register(struct debug_hook *dbg_hook);
+void debug_hook_unregister(struct debug_hook *dbg_hook);
+
+#endif /* __ASM_KVX_DEBUG_HOOK_H_ */
diff --git a/arch/kvx/include/asm/insns.h b/arch/kvx/include/asm/insns.h
new file mode 100644
index ..36a9e8335ce8
--- /dev/null
+++ b/arch/kvx/include/asm/insns.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#ifndef _ASM_KVX_INSNS_H
+#define _ASM_KVX_INSNS_H
+
+int kvx_insns_write_nostop(u32 *insns, u8 insns_len, u32 *insn_addr);
+
+int kvx_insns_write(u32 *insns, unsigned long insns_len, u32 *addr);
+
+int kvx_insns_read(u32 *insns, unsigned long insns_len, u32 *addr);
+
+#endif
diff --git a/arch/kvx/include/asm/insns_defs.h 
b/arch/kvx/include/asm/insns_defs.h
new file mode 100644
index ..ed8d9d6f0817
--- /dev/null
+++ b/arch/kvx/include/asm/insns_defs.h
@@ -0,0 +1,197 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ *Guillaume Thouvenin
+ */
+
+#ifndef __ASM_KVX_INSNS_DEFS_H_
+#define __ASM_KVX_INSNS_DEFS_H_
+
+#include 
+
+#ifndef __ASSEMBLY__
+static inline int check_signed_imm(long long imm, int bits)
+{
+   long long min, max;
+
+   min = -BIT_ULL(bits - 1);
+   max = BIT_ULL(bits - 1) - 1;
+   if (imm < min || imm > max)
+   return 1;
+
+   return 0;
+}
+#endif /* __ASSEMBLY__ */
+
+#define BITMASK(bits)  (BIT_ULL(bits) - 1)
+
+#define KVX_INSN_SYLLABLE_WIDTH 4
+
+#define IS_INSN(__insn, __mnemo) \
+   ((__insn & KVX_INSN_ ## __mnemo ## _MASK_0) == \
+KVX_INSN_ ## __mnemo ## _OPCODE_0)
+
+#define INSN_SIZE(__insn) \
+   (KVX_INSN_ ## __insn ## _SIZE * KVX_INSN_SYLLABLE_WIDTH)
+
+/* Values for general registers */
+#define KVX_REG_R0 0
+#define KVX_REG_R1 1
+#define KVX_REG_R2 2
+#define KVX_REG_R3 3
+#define KVX_REG_R4 4
+#define KVX_REG_R5 5
+#define KVX_REG_R6 6
+#define KVX_REG_R7 7
+#define KVX_REG_R8 8
+#define KVX_REG_R9 9
+#define KVX_REG_R1010
+#define KVX_REG_R1111
+#define KVX_REG_R1212
+#define KVX_REG_SP 12
+#define KVX_REG_R1313
+#define KVX_REG_TP 13
+#define KVX_REG_R1414
+#define KVX_REG_FP 14
+#define KVX_REG_R1515
+#define KVX_REG_R1616
+#define KVX_REG_R1717
+#define KVX_REG_R1818
+#define KVX_REG_R1919
+#define KVX_REG_R2020
+#define KVX_REG_R2121
+#define KVX_REG_R2222
+#define KVX_REG_R2323
+#define KVX_REG_R2424
+#define KVX_REG_R2525
+#define KVX_REG_R2626
+#define KVX_REG_R2727
+#define KVX_REG_R2828
+#define KVX_REG_R2929
+#define KVX_REG_R3030
+#define KVX_REG_R3131
+#define KVX_REG_R3232
+#define KVX_REG_R3333
+#define KVX_REG_R3434
+#define KVX_REG_R3535
+#define KVX_REG_R3636
+#define KVX_REG_R3737
+#define KVX_REG_R3838
+#define KVX_REG_R3939
+#define KVX_REG_R4

[RFC PATCH v2 22/31] kvx: Add signal handling support

2023-01-20 Thread Yann Sionneau
Add sigcontext definition and signal handling support for kvx.

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Jules Maselbas 
Signed-off-by: Jules Maselbas 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Co-developed-by: Yann Sionneau 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2:
 - use read_thread_flags() as suggested by Mark Rutland

 arch/kvx/include/uapi/asm/sigcontext.h |  16 ++
 arch/kvx/kernel/signal.c   | 265 +
 arch/kvx/kernel/vdso.c |  87 
 3 files changed, 368 insertions(+)
 create mode 100644 arch/kvx/include/uapi/asm/sigcontext.h
 create mode 100644 arch/kvx/kernel/signal.c
 create mode 100644 arch/kvx/kernel/vdso.c

diff --git a/arch/kvx/include/uapi/asm/sigcontext.h 
b/arch/kvx/include/uapi/asm/sigcontext.h
new file mode 100644
index ..97ab4f78152a
--- /dev/null
+++ b/arch/kvx/include/uapi/asm/sigcontext.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-only WITH Linux-syscall-note */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#ifndef _UAPI_ASM_KVX_SIGCONTEXT_H
+#define _UAPI_ASM_KVX_SIGCONTEXT_H
+
+#include 
+
+struct sigcontext {
+   struct user_pt_regs sc_regs;
+};
+
+#endif /* _UAPI_ASM_KVX_SIGCONTEXT_H */
diff --git a/arch/kvx/kernel/signal.c b/arch/kvx/kernel/signal.c
new file mode 100644
index ..5bd63d14f43e
--- /dev/null
+++ b/arch/kvx/kernel/signal.c
@@ -0,0 +1,265 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#include 
+#include 
+
+#include 
+#include 
+#include 
+#include 
+
+struct rt_sigframe {
+   struct siginfo info;
+   struct ucontext uc;
+};
+
+int __init setup_syscall_sigreturn_page(void *sigpage_addr)
+{
+   unsigned int frame_size = (uintptr_t) &user_scall_rt_sigreturn_end -
+ (uintptr_t) &user_scall_rt_sigreturn;
+
+   /* Copy the sigreturn scall implementation */
+   memcpy(sigpage_addr, &user_scall_rt_sigreturn, frame_size);
+
+   flush_icache_range((unsigned long) sigpage_addr,
+  (unsigned long) sigpage_addr + frame_size);
+
+   return 0;
+}
+
+static long restore_sigcontext(struct pt_regs *regs,
+  struct sigcontext __user *sc)
+{
+   long err;
+
+   /* sc_regs is structured the same as the start of pt_regs */
+   err = __copy_from_user(regs, &sc->sc_regs, sizeof(sc->sc_regs));
+
+   return err;
+}
+
+long _sys_rt_sigreturn(void)
+{
+   struct pt_regs *regs = current_pt_regs();
+   struct rt_sigframe __user *frame;
+   struct task_struct *task;
+   sigset_t set;
+
+   current->restart_block.fn = do_no_restart_syscall;
+
+   frame = (struct rt_sigframe __user *) user_stack_pointer(regs);
+
+   /*
+* Stack is not aligned but should be !
+* User probably did some malicious things.
+*/
+   if (user_stack_pointer(regs) & STACK_ALIGN_MASK)
+   goto badframe;
+
+   if (!access_ok(frame, sizeof(*frame)))
+   goto badframe;
+
+   /* Restore sigmask */
+   if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
+   goto badframe;
+
+   set_current_blocked(&set);
+
+   if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
+   goto badframe;
+
+   if (restore_altstack(&frame->uc.uc_stack))
+   goto badframe;
+
+   return regs->r0;
+
+badframe:
+   task = current;
+   if (show_unhandled_signals) {
+   pr_info_ratelimited(
+   "%s[%d]: bad frame in %s: frame=%p pc=%p sp=%p\n",
+   task->comm, task_pid_nr(task), __func__,
+   frame, (void *) instruction_pointer(regs),
+   (void *) user_stack_pointer(regs));
+   }
+   force_sig(SIGSEGV);
+   return 0;
+}
+
+
+static long setup_sigcontext(struct rt_sigframe __user *frame,
+struct pt_regs *regs)
+{
+   struct sigcontext __user *sc = &frame->uc.uc_mcontext;
+   long err;
+
+   /* sc_regs is structured the same as the start of pt_regs */
+   err = __copy_to_user(&sc->sc_regs, regs, sizeof(sc->sc_regs));
+
+   return err;
+}
+
+static inline void __user *get_sigframe(struct ksignal *ksig,
+   struct pt_regs *regs, size_t framesize)
+{
+   unsigned long sp;
+   /* Default to using normal stack */
+   sp = regs->sp;
+
+   /*
+* If we are on the alternate signal stack and would overflow it, don't.
+* Return an always-bogus address instead so we will die with SIGSEGV.
+*/
+   if (on_sig_stack(sp) && !likely(on_sig_stack(sp - framesize)))
+   return (void __user __force *)(-1UL);
+
+   /* This is the X/Open sanctioned signal stack switching. */

[RFC PATCH v2 23/31] kvx: Add ELF relocations and module support

2023-01-20 Thread Yann Sionneau
Add ELF-related definition and module relocation code for basic
kvx support.

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Co-developed-by: Marius Gligor 
Signed-off-by: Marius Gligor 
Co-developed-by: Yann Sionneau 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: no changes

 arch/kvx/include/asm/elf.h  | 155 
 arch/kvx/include/asm/vermagic.h |  12 +++
 arch/kvx/kernel/module.c| 148 ++
 3 files changed, 315 insertions(+)
 create mode 100644 arch/kvx/include/asm/elf.h
 create mode 100644 arch/kvx/include/asm/vermagic.h
 create mode 100644 arch/kvx/kernel/module.c

diff --git a/arch/kvx/include/asm/elf.h b/arch/kvx/include/asm/elf.h
new file mode 100644
index ..38978d48221e
--- /dev/null
+++ b/arch/kvx/include/asm/elf.h
@@ -0,0 +1,155 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Yann Sionneau
+ *Clement Leger
+ *Marius Gligor
+ *Guillaume Thouvenin
+ */
+
+#ifndef _ASM_KVX_ELF_H
+#define _ASM_KVX_ELF_H
+
+#include 
+
+#include 
+
+/*
+ * These are used to set parameters in the core dumps.
+ */
+#define ELF_CLASS  ELFCLASS64
+#define ELF_DATA   ELFDATA2LSB
+#define ELF_ARCH   EM_KVX
+
+typedef uint64_t elf_greg_t;
+typedef uint64_t elf_fpregset_t;
+
+#define ELF_NGREG  (sizeof(struct user_pt_regs) / sizeof(elf_greg_t))
+typedef elf_greg_t elf_gregset_t[ELF_NGREG];
+
+/* Copy user_pt_regs from pt_regs into the elf_gregset_t */
+#define ELF_CORE_COPY_REGS(dest, regs) \
+   *(struct user_pt_regs *)&(dest) = (regs)->user_regs;
+
+/*
+ * This is used to ensure we don't load something for the wrong architecture.
+ */
+#define elf_check_arch(x) ((x)->e_machine == EM_KVX)
+
+#define ELF_CORE_EFLAGS 0x1308
+
+#define ELF_EXEC_PAGESIZE  (PAGE_SIZE)
+
+/*
+ * This is the location that an ET_DYN program is loaded if exec'ed.  Typical
+ * use of this is to invoke "./ld.so someprog" to test out a new version of
+ * the loader.  We need to make sure that it is out of the way of the program
+ * that it will "exec", and that there is sufficient room for the brk.
+ */
+#define ELF_ET_DYN_BASE((TASK_SIZE / 3) * 2)
+
+/*
+ * This yields a mask that user programs can use to figure out what
+ * instruction set this CPU supports.  This could be done in user space,
+ * but it's not easy, and we've already done it here.
+ */
+#define ELF_HWCAP  (elf_hwcap)
+extern unsigned long elf_hwcap;
+
+/*
+ * This yields a string that ld.so will use to load implementation
+ * specific libraries for optimization.  This is more specific in
+ * intent than poking at uname or /proc/cpuinfo.
+ */
+#define ELF_PLATFORM   (NULL)
+
+#define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
+struct linux_binprm;
+extern int arch_setup_additional_pages(struct linux_binprm *bprm,
+  int uses_interp);
+
+/* KVX relocs */
+#define R_KVX_NONE   0
+#define R_KVX_16 1
+#define R_KVX_32 2
+#define R_KVX_64 3
+#define R_KVX_S16_PCREL  4
+#define R_KVX_PCREL175
+#define R_KVX_PCREL276
+#define R_KVX_32_PCREL   7
+#define R_KVX_S37_PCREL_LO10 8
+#define R_KVX_S37_PCREL_UP27 9
+#define R_KVX_S43_PCREL_LO1010
+#define R_KVX_S43_PCREL_UP2711
+#define R_KVX_S43_PCREL_EX6 12
+#define R_KVX_S64_PCREL_LO1013
+#define R_KVX_S64_PCREL_UP2714
+#define R_KVX_S64_PCREL_EX2715
+#define R_KVX_64_PCREL  16
+#define R_KVX_S16   17
+#define R_KVX_S32_LO5   18
+#define R_KVX_S32_UP27  19
+#define R_KVX_S37_LO10  20
+#define R_KVX_S37_UP27  21
+#define R_KVX_S37_GOTOFF_LO10   22
+#define R_KVX_S37_GOTOFF_UP27   23
+#define R_KVX_S43_GOTOFF_LO10   24
+#define R_KVX_S43_GOTOFF_UP27   25
+#define R_KVX_S43_GOTOFF_EX626
+#define R_KVX_32_GOTOFF 27
+#define R_KVX_64_GOTOFF 28
+#define R_KVX_32_GOT29
+#define R_KVX_S37_GOT_LO10  30
+#define R_KVX_S37_GOT_UP27  31
+#define R_KVX_S43_GOT_LO10  32
+#define R_KVX_S43_GOT_UP27  33
+#define R_KVX_S43_GOT_EX6   

Re: [RFC PATCH v2 09/31] kvx: Add build infrastructure

2023-01-20 Thread Jules Maselbas
On Fri, Jan 20, 2023 at 03:39:22PM +0100, Arnd Bergmann wrote:
> On Fri, Jan 20, 2023, at 15:09, Yann Sionneau wrote:
> >  - Fix clean target raising an error from gcc (LIBGCC)
> 
> I had not noticed this on v1 but:
> 
> > +# Link with libgcc to get __div* builtins.
> > +LIBGCC := $(shell $(CC) $(DEFAULT_OPTS) --print-libgcc-file-name)
> 
> It's better to copy the bits of libgcc that you actually need
> than to include the whole thing. The kernel is in a weird
It was initialy using KCONFIG_CFLAGS which do not contains valid options
when invoking the clean target.

I am not exactly sure what's needed by gcc for --print-libgcc-file-name,
my guess is that only the -march option matters, I will double check
internally with compiler peoples.

> state that is neither freestanding nor the normal libc based
> environment, so we generally want full control over what is
> used. This is particularly important for 32-bit architectures
> that do not want the 64-bit division, but there are probably
> enough other cases as well.
> 
>  Arnd
> 
> 
> 
> 




--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



[RFC PATCH v2 12/31] kvx: Add other common headers

2023-01-20 Thread Yann Sionneau
Add some other common headers for basic kvx support.

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Co-developed-by: Vincent Chardon 
Signed-off-by: Vincent Chardon 
Co-developed-by: Yann Sionneau 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: no changes

 arch/kvx/include/asm/asm-prototypes.h   | 14 
 arch/kvx/include/asm/clocksource.h  | 17 +
 arch/kvx/include/asm/linkage.h  | 13 +++
 arch/kvx/include/asm/pci.h  | 36 +++
 arch/kvx/include/asm/sections.h | 18 ++
 arch/kvx/include/asm/spinlock.h | 16 +
 arch/kvx/include/asm/spinlock_types.h   | 17 +
 arch/kvx/include/asm/stackprotector.h   | 47 +
 arch/kvx/include/asm/timex.h| 20 +++
 arch/kvx/include/asm/types.h| 12 +++
 arch/kvx/include/uapi/asm/bitsperlong.h | 14 
 arch/kvx/include/uapi/asm/byteorder.h   | 12 +++
 tools/include/uapi/asm/bitsperlong.h|  2 ++
 13 files changed, 238 insertions(+)
 create mode 100644 arch/kvx/include/asm/asm-prototypes.h
 create mode 100644 arch/kvx/include/asm/clocksource.h
 create mode 100644 arch/kvx/include/asm/linkage.h
 create mode 100644 arch/kvx/include/asm/pci.h
 create mode 100644 arch/kvx/include/asm/sections.h
 create mode 100644 arch/kvx/include/asm/spinlock.h
 create mode 100644 arch/kvx/include/asm/spinlock_types.h
 create mode 100644 arch/kvx/include/asm/stackprotector.h
 create mode 100644 arch/kvx/include/asm/timex.h
 create mode 100644 arch/kvx/include/asm/types.h
 create mode 100644 arch/kvx/include/uapi/asm/bitsperlong.h
 create mode 100644 arch/kvx/include/uapi/asm/byteorder.h

diff --git a/arch/kvx/include/asm/asm-prototypes.h 
b/arch/kvx/include/asm/asm-prototypes.h
new file mode 100644
index ..af032508e30c
--- /dev/null
+++ b/arch/kvx/include/asm/asm-prototypes.h
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#ifndef _ASM_KVX_ASM_PROTOTYPES_H
+#define _ASM_KVX_ASM_PROTOTYPES_H
+
+#include 
+
+#include 
+
+#endif /* _ASM_KVX_ASM_PROTOTYPES_H */
diff --git a/arch/kvx/include/asm/clocksource.h 
b/arch/kvx/include/asm/clocksource.h
new file mode 100644
index ..4df7c66ffbb5
--- /dev/null
+++ b/arch/kvx/include/asm/clocksource.h
@@ -0,0 +1,17 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Yann Sionneau
+ *Clement Leger
+ */
+
+#ifndef _ASM_KVX_CLOCKSOURCE_H
+#define _ASM_KVX_CLOCKSOURCE_H
+
+#include 
+
+struct arch_clocksource_data {
+   void __iomem *regs;
+};
+
+#endif /* _ASM_KVX_CLOCKSOURCE_H */
diff --git a/arch/kvx/include/asm/linkage.h b/arch/kvx/include/asm/linkage.h
new file mode 100644
index ..84e1cacf67c2
--- /dev/null
+++ b/arch/kvx/include/asm/linkage.h
@@ -0,0 +1,13 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Yann Sionneau
+ */
+
+#ifndef __ASM_KVX_LINKAGE_H
+#define __ASM_KVX_LINKAGE_H
+
+#define __ALIGN.align 4
+#define __ALIGN_STR".align 4"
+
+#endif
diff --git a/arch/kvx/include/asm/pci.h b/arch/kvx/include/asm/pci.h
new file mode 100644
index ..d5bbaaf041b5
--- /dev/null
+++ b/arch/kvx/include/asm/pci.h
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Vincent Chardon
+ *Clement Leger
+ */
+
+#ifndef __ASM_KVX_PCI_H_
+#define __ASM_KVX_PCI_H_
+
+#include 
+#include 
+#include 
+
+#define ARCH_GENERIC_PCI_MMAP_RESOURCE 1
+#define HAVE_PCI_MMAP  1
+
+extern int isa_dma_bridge_buggy;
+
+/* Can be used to override the logic in pci_scan_bus for skipping
+ * already-configured bus numbers - to be used for buggy BIOSes
+ * or architectures with incomplete PCI setup by the loader.
+ */
+#define pcibios_assign_all_busses()0
+
+#define PCIBIOS_MIN_IO  0UL
+#define PCIBIOS_MIN_MEM 0UL
+
+#ifdef CONFIG_PCI_DOMAINS
+static inline int pci_proc_domain(struct pci_bus *bus)
+{
+   return pci_domain_nr(bus);
+}
+#endif /*  CONFIG_PCI_DOMAINS */
+
+#endif /* _ASM_KVX_PCI_H */
diff --git a/arch/kvx/include/asm/sections.h b/arch/kvx/include/asm/sections.h
new file mode 100644
index ..0777675ef264
--- /dev/null
+++ b/arch/kvx/include/asm/sections.h
@@ -0,0 +1,18 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#ifndef _ASM_KVX_SECTIONS_H
+#define _ASM_KVX_SECTIONS_H
+
+#include 
+
+extern char __rodata_start[], __rodata_end[];
+extern char __initdata_start[], __initdata_end[];
+extern char __inittext_start[], __inittext_end[];
+extern char __exception_start[], __exception_end[];
+extern char __rm_firmware_regs_start[];
+
+#endif
dif

[RFC PATCH v2 11/31] kvx: Add atomic/locking headers

2023-01-20 Thread Yann Sionneau
Add common headers (atomic, bitops, barrier and locking) for basic
kvx support.

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Jules Maselbas 
Signed-off-by: Jules Maselbas 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Co-developed-by: Julien Villette 
Signed-off-by: Julien Villette 
Co-developed-by: Yann Sionneau 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2:
 - use {READ,WRITE}_ONCE for arch_atomic64_{read,set}
 - use asm-generic/bitops/atomic.h instead of __test_and_*_bit
 - removed duplicated includes
 - rewrite xchg and cmpxchg in C using builtins for acswap insn

 arch/kvx/include/asm/atomic.h  | 104 
 arch/kvx/include/asm/barrier.h |  15 +++
 arch/kvx/include/asm/bitops.h  | 115 ++
 arch/kvx/include/asm/bitrev.h  |  32 +++
 arch/kvx/include/asm/cmpxchg.h | 170 +
 5 files changed, 436 insertions(+)
 create mode 100644 arch/kvx/include/asm/atomic.h
 create mode 100644 arch/kvx/include/asm/barrier.h
 create mode 100644 arch/kvx/include/asm/bitops.h
 create mode 100644 arch/kvx/include/asm/bitrev.h
 create mode 100644 arch/kvx/include/asm/cmpxchg.h

diff --git a/arch/kvx/include/asm/atomic.h b/arch/kvx/include/asm/atomic.h
new file mode 100644
index ..bea3d70785b1
--- /dev/null
+++ b/arch/kvx/include/asm/atomic.h
@@ -0,0 +1,104 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#ifndef _ASM_KVX_ATOMIC_H
+#define _ASM_KVX_ATOMIC_H
+
+#include 
+
+#include 
+
+#define ATOMIC64_INIT(i) { (i) }
+
+#define arch_atomic64_cmpxchg(v, old, new) (arch_cmpxchg(&((v)->counter), old, 
new))
+#define arch_atomic64_xchg(v, new) (arch_xchg(&((v)->counter), new))
+
+static inline long arch_atomic64_read(const atomic64_t *v)
+{
+   return READ_ONCE(v->counter);
+}
+
+static inline void arch_atomic64_set(atomic64_t *v, long i)
+{
+   WRITE_ONCE(v->counter, i);
+}
+
+#define ATOMIC64_RETURN_OP(op, c_op)   \
+static inline long arch_atomic64_##op##_return(long i, atomic64_t *v)  \
+{  \
+   long new, old, ret; \
+   \
+   do {\
+   old = v->counter;   \
+   new = old c_op i;   \
+   ret = arch_cmpxchg(&v->counter, old, new);  \
+   } while (ret != old);   \
+   \
+   return new; \
+}
+
+#define ATOMIC64_OP(op, c_op)  \
+static inline void arch_atomic64_##op(long i, atomic64_t *v)   \
+{  \
+   long new, old, ret; \
+   \
+   do {\
+   old = v->counter;   \
+   new = old c_op i;   \
+   ret = arch_cmpxchg(&v->counter, old, new);  \
+   } while (ret != old);   \
+}
+
+#define ATOMIC64_FETCH_OP(op, c_op)\
+static inline long arch_atomic64_fetch_##op(long i, atomic64_t *v) \
+{  \
+   long new, old, ret; \
+   \
+   do {\
+   old = v->counter;   \
+   new = old c_op i;   \
+   ret = arch_cmpxchg(&v->counter, old, new);  \
+   } while (ret != old);   \
+   \
+   return old; \
+}
+
+#define ATOMIC64_OPS(op, c_op) \
+   ATOMIC64_OP(op, c_op)   \
+   ATOMIC64_RETURN_OP(op, c_op)\
+   ATOMIC64_FETCH_OP(op, c_op)
+
+ATOMIC64_OPS(and, &)
+ATOMIC64_OPS(or, |)
+ATOMIC64_OPS(xor, ^)
+ATOMIC64_OPS(add, +)
+ATOMIC64_OPS(sub, -)
+
+#undef ATOMIC64_OPS
+#undef ATOMIC64_FETCH_OP
+#undef ATOMIC64

Re: [RFC PATCH v2 12/31] kvx: Add other common headers

2023-01-20 Thread Jason A. Donenfeld
Hi Yann,

On Fri, Jan 20, 2023 at 03:09:43PM +0100, Yann Sionneau wrote:
> +#include 
> +#include 
> +
> +extern unsigned long __stack_chk_guard;
> +
> +/*
> + * Initialize the stackprotector canary value.
> + *
> + * NOTE: this must only be called from functions that never return,
> + * and it must always be inlined.
> + */
> +static __always_inline void boot_init_stack_canary(void)
> +{
> + unsigned long canary;
> +
> + /* Try to get a semi random initial value. */
> + get_random_bytes(&canary, sizeof(canary));
> + canary ^= LINUX_VERSION_CODE;
> + canary &= CANARY_MASK;
> +
> + current->stack_canary = canary;
> + __stack_chk_guard = current->stack_canary;
> +}


You should rewrite this as:

current->stack_canary = get_random_canary();
__stack_chk_guard = current->stack_canary;

which is what the other archs all now do. (They didn't used to, and this
looks like it's simply based on older code.)

> +#define get_cycles get_cycles
> +
> +#include 
> +#include 
> +
> +static inline cycles_t get_cycles(void)
> +{
> + return kvx_sfr_get(PM0);
> +}

Glad to see this CPU has a cycle counter. Out of curiosity, what is
its resolution?

Also, related, does this CPU happen to have a "RDRAND"-like instruction?
(I don't know anything about kvx or even what it is.)

Jason

--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



[RFC PATCH v2 24/31] kvx: Add misc common routines

2023-01-20 Thread Yann Sionneau
Add some misc common routines for kvx, including: asm-offsets routines,
futex functions, i/o memory access functions.

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Guillaume Thouvenin 
Signed-off-by: Guillaume Thouvenin 
Co-developed-by: Jonathan Borne 
Signed-off-by: Jonathan Borne 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Co-developed-by: Julien Villette 
Signed-off-by: Julien Villette 
Co-developed-by: Yann Sionneau 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: no changes

 arch/kvx/include/asm/futex.h  | 141 ++
 arch/kvx/include/asm/io.h |  34 
 arch/kvx/kernel/asm-offsets.c | 157 ++
 arch/kvx/kernel/io.c  |  96 +
 4 files changed, 428 insertions(+)
 create mode 100644 arch/kvx/include/asm/futex.h
 create mode 100644 arch/kvx/include/asm/io.h
 create mode 100644 arch/kvx/kernel/asm-offsets.c
 create mode 100644 arch/kvx/kernel/io.c

diff --git a/arch/kvx/include/asm/futex.h b/arch/kvx/include/asm/futex.h
new file mode 100644
index ..b71b52339729
--- /dev/null
+++ b/arch/kvx/include/asm/futex.h
@@ -0,0 +1,141 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2018-2023 Kalray Inc.
+ * Authors:
+ *  Clement Leger 
+ *  Yann Sionneau 
+ *  Jonathan Borne 
+ *
+ * Part of code is taken from RiscV port
+ */
+
+#ifndef _ASM_KVX_FUTEX_H
+#define _ASM_KVX_FUTEX_H
+
+#ifdef __KERNEL__
+
+#include 
+#include 
+
+#define __futex_atomic_op(insn, ret, oldval, uaddr, oparg) \
+{ \
+   __enable_user_access(); \
+   __asm__ __volatile__ (  \
+   "   fence   \n" \
+   "   ;;\n  " \
+   "1: lwz $r63 = 0[%[u]]  \n" \
+   "   ;;\n  " \
+   "   " insn "\n" \
+   "   ;;\n  " \
+   "   acswapw 0[%[u]], $r62r63\n" \
+   "   ;;\n  " \
+   "   cb.deqz $r62? 1b\n" \
+   "   ;;\n  " \
+   "   copyd %[ov] = $r63  \n" \
+   "   ;;\n  " \
+   "2: \n" \
+   "   .section .fixup,\"ax\"  \n" \
+   "3: make %[r] = 2b  \n" \
+   "   ;;\n  " \
+   "   make %[r] = %[e]\n" \
+   "   igoto %[r]  \n" \
+   "   ;;\n  " \
+   "   .previous   \n" \
+   "   .section __ex_table,\"a\"   \n" \
+   "   .align 8\n" \
+   "   .dword 1b,3b\n" \
+   "   .dword 2b,3b\n" \
+   "   .previous   \n" \
+   : [r] "+r" (ret), [ov] "+r" (oldval)   \
+   : [u] "r" (uaddr),  \
+ [op] "r" (oparg), [e] "i" (-EFAULT)   \
+   : "r62", "r63", "memory");  \
+   __disable_user_access();\
+}
+
+
+static inline int
+arch_futex_atomic_op_inuser(int op, u32 oparg, int *oval, u32 __user *uaddr)
+{
+   int oldval = 0, ret = 0;
+
+   if (!access_ok(uaddr, sizeof(u32)))
+   return -EFAULT;
+   switch (op) {
+   case FUTEX_OP_SET: /* *(int *)UADDR = OPARG; */
+   __futex_atomic_op("copyd $r62 = %[op]",
+ ret, oldval, uaddr, oparg);
+   break;
+   case FUTEX_OP_ADD: /* *(int *)UADDR += OPARG; */
+   __futex_atomic_op("addw $r62 = $r63, %[op]",
+ ret, oldval, uaddr, oparg);
+   break;
+   case FUTEX_OP_OR: /* *(int *)UADDR |= OPARG; */
+   __futex_atomic_op("orw $r62 = $r63, %[op]",
+ ret, oldval, uaddr, oparg);
+   break;
+   case FUTEX_OP_ANDN: /* *(int *)UADDR &= ~OPARG; */
+   __futex_atomic_op("andnw $r62 = %[op], $r63",
+ ret, oldval, uaddr, oparg);
+   break;
+   case FUTEX_OP_XOR:
+   __futex_atomic_op("xorw $r62 = $r63, %[op]",
+ ret, oldval, uaddr, oparg);
+   break;
+   default:
+   ret = -ENOSYS;
+   }
+
+

[RFC PATCH v2 00/31] Upstream kvx Linux port

2023-01-20 Thread Yann Sionneau
This patch series adds support for the kv3-1 CPU architecture of the kvx family
found in the Coolidge (aka MPPA3-80) SoC of Kalray.

This is an RFC, since kvx support is not yet upstreamed into gcc/binutils,
therefore this patch series cannot be merged into Linux for now.

The goal is to have preliminary reviews and to fix problems early.

The Kalray VLIW processor family (kvx) has the following features:
* 32/64 bits execution mode
* 6-issue VLIW architecture
* 64 x 64bits general purpose registers
* SIMD instructions
* little-endian
* deep learning co-processor

Kalray kv3-1 core which is the third of the kvx family is embedded in Kalray
Coolidge SoC currently used on K200 and K200-LP boards.

The Coolidge SoC contains 5 clusters each of which is made of:
* 4MiB of on-chip memory (SMEM)
* 1 dedicated safety/security core (kv3-1 core).
* 16 PEs (Processing Elements) (kv3-1 cores).
* 16 Co-processors (one per PE)
* 2 Crypto accelerators

The Coolidge SoC contains the following features:
* 5 Clusters
* 2 100G Ethernet controllers
* 8 PCIe GEN4 controllers (Root Complex and Endpoint capable)
* 2 USB 2.0 controllers
* 1 Octal SPI-NOR flash controller
* 1 eMMC controller
* 3 Quad SPI controllers
* 6 UART
* 5 I2C controllers (3 of which are SMBus capable)
* 4 CAN controllers
* 1 OTP memory

A kvx toolchain can be built using:
# install dependencies: texinfo bison flex libgmp-dev libmpc-dev libmpfr-dev
$ git clone https://github.com/kalray/build-scripts
$ cd build-scripts
$ source last.refs
$ ./build-kvx-xgcc.sh output

The kvx toolchain will be installed in the "output" directory.

You can also find prebuilt toolchains at: 
https://github.com/kalray/build-scripts/releases/tag/v4.11.1
They are built for Ubuntu 18.04, 20.04 and 22.04 (named 'latest').

A buildroot image (kernel+rootfs) and toolchain can be built using:
$ git clone -b coolidge-for-upstream-v2 https://github.com/kalray/buildroot
$ cd buildroot
$ make O=build_kvx kvx_defconfig
$ make O=build_kvx

The vmlinux image can be found in buildroot/build_kvx/images/vmlinux.

If you are just interested in building the Linux kernel with no rootfs you can
just do this with the kvx-elf- toolchain:
$ make ARCH=kvx O=build_kvx CROSS_COMPILE=kvx-elf- defconfig
$ make ARCH=kvx O=build_kvx CROSS_COMPILE=kvx-elf- -j$(($(nproc) + 1))

The vmlinux ELF can be run with qemu by doing:
# install dependencies: ninja pkg-config libglib-2.0-dev cmake libfdt-dev 
libpixman-1-dev zlib1g-dev
$ git clone https://github.com/kalray/qemu-builder
$ cd qemu-builder
$ git submodule update --init
$ make -j$(($(nproc) + 1))
$ ./qemu-system-kvx -m 1024 -nographic -kernel 

V1 -> V2:
 - Rebase on 6.1.6
 - Removed features that are non-necessary for basic port to boot: kgdb, l2 
cache driver, jump label, ftrace, hw breakpoints, gdb python helpers and perf 
monitors
 - Split dt bindings in separate patches
 - Split irqchip drivers: 1 driver == 1 patch
 - Fixed typos in arch/kvx/Kconfig
 - Rewrote ASM atomic helpers in C using builtins
 - Documentation has been rewritten in RST format and included in documentation 
build system
 - Renamed default_defconfig to defconfig
 - Removed arch-specific __access_ok to use generic code
 - Fixed make clean issue caused by LIBGCC definition in arch/kvx/Makefile

Note that all remarks on V1 patchset are not addressed yet. We are still 
working on some fixes like removing legacy syscalls,
using generic entry, rework smp.c and publication of kv3-1 ABI specification.

Jules Maselbas (11):
  Documentation: Add binding for kalray,kv3-1-core-intc
  Documentation: Add binding for kalray,kv3-1-apic-gic
  Documentation: Add binding for kalray,kv3-1-apic-mailbox
  Documentation: Add binding for kalray,coolidge-itgen
  Documentation: Add binding for kalray,kv3-1-ipi-ctrl
  Documentation: Add binding for kalray,kv3-1-pwr-ctrl
  irqchip: Add irq-kvx-itgen driver
  irqchip: Add irq-kvx-apic-mailbox driver
  irqchip: Add kvx-core-intc core interupt controller driver
  kvx: Add power controller driver
  kvx: Add IPI driver

Yann Sionneau (20):
  Documentation: kvx: Add basic documentation
  kvx: Add ELF-related definitions
  kvx: Add build infrastructure
  kvx: Add CPU definition headers
  kvx: Add atomic/locking headers
  kvx: Add other common headers
  kvx: Add boot and setup routines
  kvx: Add exception/interrupt handling
  irqchip: Add irq-kvx-apic-gic driver
  kvx: Add process management
  kvx: Add memory management
  kvx: Add system call support
  kvx: Add signal handling support
  kvx: Add ELF relocations and module support
  kvx: Add misc common routines
  kvx: Add some library functions
  kvx: Add multi-processor (SMP) support
  kvx: Add kvx default config file
  kvx: Add debugging related support
  kvx: Add support for cpuinfo

 Documentation/arch.rst|1 +
 .../kalray,coolidge-itgen.yaml|   48 +
 .../kalray,kv3-1-apic-gic.yaml|   66 +
 .../kalray,kv3-1-apic-mailbox.yaml|   75 +
 .../kalray,kv

[RFC PATCH v2 30/31] kvx: Add power controller driver

2023-01-20 Thread Yann Sionneau
From: Jules Maselbas 

The Power Controller (pwr-ctrl) control cores reset and wake-up
procedure.

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Co-developed-by: Louis Morhet 
Signed-off-by: Louis Morhet 
Co-developed-by: Marius Gligor 
Signed-off-by: Marius Gligor 
Signed-off-by: Jules Maselbas 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: new patch

 arch/kvx/include/asm/pwr_ctrl.h | 45 
 arch/kvx/platform/Makefile  |  6 +++
 arch/kvx/platform/pwr_ctrl.c| 91 +
 3 files changed, 142 insertions(+)
 create mode 100644 arch/kvx/include/asm/pwr_ctrl.h
 create mode 100644 arch/kvx/platform/Makefile
 create mode 100644 arch/kvx/platform/pwr_ctrl.c

diff --git a/arch/kvx/include/asm/pwr_ctrl.h b/arch/kvx/include/asm/pwr_ctrl.h
new file mode 100644
index ..25f403ba935a
--- /dev/null
+++ b/arch/kvx/include/asm/pwr_ctrl.h
@@ -0,0 +1,45 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ *Marius Gligor
+ */
+
+#ifndef _ASM_KVX_PWR_CTRL_H
+#define _ASM_KVX_PWR_CTRL_H
+
+#ifndef __ASSEMBLY__
+
+int kvx_pwr_ctrl_probe(void);
+
+void kvx_pwr_ctrl_cpu_poweron(unsigned int cpu);
+
+#endif
+
+/* Power controller vector register definitions */
+#define KVX_PWR_CTRL_VEC_OFFSET 0x1000
+#define KVX_PWR_CTRL_VEC_WUP_SET_OFFSET 0x10
+#define KVX_PWR_CTRL_VEC_WUP_CLEAR_OFFSET 0x20
+
+/* Power controller PE reset PC register definitions */
+#define KVX_PWR_CTRL_RESET_PC_OFFSET   0x2000
+
+/* Power controller global register definitions */
+#define KVX_PWR_CTRL_GLOBAL_OFFSET 0x4040
+
+#define KVX_PWR_CTRL_GLOBAL_SET_OFFSET 0x10
+#define KVX_PWR_CTRL_GLOBAL_SET_PE_EN_SHIFT   0x1
+
+#define PWR_CTRL_WUP_SET_OFFSET  \
+   (KVX_PWR_CTRL_VEC_OFFSET + \
+KVX_PWR_CTRL_VEC_WUP_SET_OFFSET)
+
+#define PWR_CTRL_WUP_CLEAR_OFFSET  \
+   (KVX_PWR_CTRL_VEC_OFFSET + \
+KVX_PWR_CTRL_VEC_WUP_CLEAR_OFFSET)
+
+#define PWR_CTRL_GLOBAL_CONFIG_OFFSET \
+   (KVX_PWR_CTRL_GLOBAL_OFFSET + \
+KVX_PWR_CTRL_GLOBAL_SET_OFFSET)
+
+#endif /* _ASM_KVX_PWR_CTRL_H */
diff --git a/arch/kvx/platform/Makefile b/arch/kvx/platform/Makefile
new file mode 100644
index ..c7d0abb15c27
--- /dev/null
+++ b/arch/kvx/platform/Makefile
@@ -0,0 +1,6 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# Copyright (C) 2018-2023 Kalray Inc.
+#
+
+obj-$(CONFIG_SMP) += pwr_ctrl.o
diff --git a/arch/kvx/platform/pwr_ctrl.c b/arch/kvx/platform/pwr_ctrl.c
new file mode 100644
index ..ee35d04845ae
--- /dev/null
+++ b/arch/kvx/platform/pwr_ctrl.c
@@ -0,0 +1,91 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+struct kvx_pwr_ctrl {
+   void __iomem *regs;
+};
+
+static struct kvx_pwr_ctrl kvx_pwr_controller;
+
+/**
+ * kvx_pwr_ctrl_cpu_poweron() - Wakeup a cpu
+ * @cpu: cpu to wakeup
+ */
+void kvx_pwr_ctrl_cpu_poweron(unsigned int cpu)
+{
+   /* Set PE boot address */
+   writeq((unsigned long long)kvx_start,
+   kvx_pwr_controller.regs + KVX_PWR_CTRL_RESET_PC_OFFSET);
+   /* Wake up processor ! */
+   writeq(1ULL << cpu,
+  kvx_pwr_controller.regs + PWR_CTRL_WUP_SET_OFFSET);
+   /* Then clear wakeup to allow processor to sleep */
+   writeq(1ULL << cpu,
+  kvx_pwr_controller.regs + PWR_CTRL_WUP_CLEAR_OFFSET);
+}
+
+static struct device_node * __init get_pwr_ctrl_node(void)
+{
+   const phandle *ph;
+   struct device_node *cpu;
+   struct device_node *node;
+
+   cpu = of_get_cpu_node(raw_smp_processor_id(), NULL);
+   if (!cpu) {
+   pr_err("Failed to get CPU node\n");
+   return NULL;
+   }
+
+   ph = of_get_property(cpu, "power-controller", NULL);
+   if (!ph) {
+   pr_err("Failed to get power-controller phandle\n");
+   return NULL;
+   }
+
+   node = of_find_node_by_phandle(be32_to_cpup(ph));
+   if (!node) {
+   pr_err("Failed to get power-controller node\n");
+   return NULL;
+   }
+
+   return node;
+}
+
+int __init kvx_pwr_ctrl_probe(void)
+{
+   struct device_node *ctrl;
+
+   ctrl = get_pwr_ctrl_node();
+   if (!ctrl) {
+   pr_err("Failed to get power controller node\n");
+   return -EINVAL;
+   }
+
+   if (!of_device_is_compatible(ctrl, "kalray,kvx-pwr-ctrl")) {
+   pr_err("Failed to get power controller node\n");
+   return -EINVAL;
+   }
+
+   kvx_pwr_controller.regs = of_iomap(ctrl, 0);
+   if (!kvx_pwr_controller.regs) {
+   

[RFC PATCH v2 06/31] Documentation: Add binding for kalray,kv3-1-ipi-ctrl

2023-01-20 Thread Yann Sionneau
From: Jules Maselbas 

Add documentation for `kalray,kv3-1-ipi-ctrl` binding.

Co-developed-by: Jules Maselbas 
Signed-off-by: Jules Maselbas 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: new patch

 .../kalray/kalray,kv3-1-ipi-ctrl.yaml | 44 +++
 1 file changed, 44 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/kalray/kalray,kv3-1-ipi-ctrl.yaml

diff --git 
a/Documentation/devicetree/bindings/kalray/kalray,kv3-1-ipi-ctrl.yaml 
b/Documentation/devicetree/bindings/kalray/kalray,kv3-1-ipi-ctrl.yaml
new file mode 100644
index ..dc8026b12905
--- /dev/null
+++ b/Documentation/devicetree/bindings/kalray/kalray,kv3-1-ipi-ctrl.yaml
@@ -0,0 +1,44 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/kalray/kalray,kv3-1-ipi-ctrl#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Kalray kv3-1 Inter-Processor Interrupt Controller (IPI)
+
+description: |
+  The Inter-Processor Interrupt Controller (IPI) provides a fast 
synchronization
+  mechanism to the software. It exposes eight independent set of registers that
+  can be use to notify each processor in the cluster.
+  A set of registers contains two 32-bit registers:
+- 17-bit interrupt control, one bit per core, raise an interrupt on write
+- 17-bit mask, one per core, to enable interrupts
+
+  Bit at offsets 0 to 15 selects cores in the cluster, respectively PE0 to 
PE15,
+  while bit at offset 16 is for the cluster Resource Manager (RM) core.
+
+  The eight output interrupts are connected to each processor core interrupt
+  controller (intc).
+
+properties:
+  compatible:
+const: kalray,kv3-1-ipi-ctrl
+  reg:
+maxItems: 1
+
+required:
+  - compatible
+  - reg
+  - interrupt-parent
+  - interrupts
+
+examples:
+  - |
+ipi: inter-processor-interrupt@ad {
+compatible = "kalray,kv3-1-ipi-ctrl";
+reg = <0x00 0xad 0x00 0x1000>;
+interrupt-parent = <&intc>;
+interrupts = <24>;
+};
+
+...
-- 
2.37.2





--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



[RFC PATCH v2 19/31] kvx: Add process management

2023-01-20 Thread Yann Sionneau
Add process management support for kvx, including: thread info
definition, context switch and process tracing.

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Guillaume Thouvenin 
Signed-off-by: Guillaume Thouvenin 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Co-developed-by: Marius Gligor 
Signed-off-by: Marius Gligor 
Co-developed-by: Vincent Chardon 
Signed-off-by: Vincent Chardon 
Co-developed-by: Yann Sionneau 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: no change

 arch/kvx/include/asm/current.h |  22 +++
 arch/kvx/include/asm/ptrace.h  | 217 +++
 arch/kvx/include/asm/switch_to.h   |  21 +++
 arch/kvx/include/asm/thread_info.h |  78 
 arch/kvx/include/uapi/asm/ptrace.h | 114 
 arch/kvx/kernel/process.c  | 203 +
 arch/kvx/kernel/ptrace.c   | 276 +
 arch/kvx/kernel/stacktrace.c   | 173 ++
 8 files changed, 1104 insertions(+)
 create mode 100644 arch/kvx/include/asm/current.h
 create mode 100644 arch/kvx/include/asm/ptrace.h
 create mode 100644 arch/kvx/include/asm/switch_to.h
 create mode 100644 arch/kvx/include/asm/thread_info.h
 create mode 100644 arch/kvx/include/uapi/asm/ptrace.h
 create mode 100644 arch/kvx/kernel/process.c
 create mode 100644 arch/kvx/kernel/ptrace.c
 create mode 100644 arch/kvx/kernel/stacktrace.c

diff --git a/arch/kvx/include/asm/current.h b/arch/kvx/include/asm/current.h
new file mode 100644
index ..b5fd0f076ec9
--- /dev/null
+++ b/arch/kvx/include/asm/current.h
@@ -0,0 +1,22 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#ifndef _ASM_KVX_CURRENT_H
+#define _ASM_KVX_CURRENT_H
+
+#include 
+#include 
+
+struct task_struct;
+
+static __always_inline struct task_struct *get_current(void)
+{
+   return (struct task_struct *) kvx_sfr_get(SR);
+}
+
+#define current get_current()
+
+#endif /* _ASM_KVX_CURRENT_H */
diff --git a/arch/kvx/include/asm/ptrace.h b/arch/kvx/include/asm/ptrace.h
new file mode 100644
index ..d1b1e0975d9e
--- /dev/null
+++ b/arch/kvx/include/asm/ptrace.h
@@ -0,0 +1,217 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ *Marius Gligor
+ *Yann Sionneau
+ */
+
+#ifndef _ASM_KVX_PTRACE_H
+#define _ASM_KVX_PTRACE_H
+
+#include 
+#include 
+#include 
+
+#define GPR_COUNT  64
+#define SFR_COUNT  9
+#define VIRT_COUNT 1
+
+#define ES_SYSCALL 0x3
+
+#define KVX_HW_BREAKPOINT_COUNT2
+#define KVX_HW_WATCHPOINT_COUNT1
+
+#define REG_SIZE   sizeof(u64)
+
+/**
+ * When updating pt_regs structure, this size must be updated.
+ * This is the expected size of the pt_regs struct.
+ * It ensures the structure layout from gcc is the same as the one we
+ * expect in order to do packed load (load/store octuple) in assembly.
+ * Conclusion: never put sizeof(pt_regs) in here or we lose this check
+ * (build time check done in asm-offsets.c via BUILD_BUG_ON)
+ */
+#define PT_REGS_STRUCT_EXPECTED_SIZE \
+   ((GPR_COUNT + SFR_COUNT + VIRT_COUNT) * REG_SIZE + \
+   2 * REG_SIZE) /* Padding for stack alignment */
+
+/**
+ * Saved register structure. Note that we should save only the necessary
+ * registers.
+ * When you modify it, please read carefully the comment above.
+ * Moreover, you will need to modify user_pt_regs to match the beginning
+ * of this struct 1:1
+ */
+struct pt_regs {
+   union {
+   struct user_pt_regs user_regs;
+   struct {
+   /* GPR */
+   uint64_t r0;
+   uint64_t r1;
+   uint64_t r2;
+   uint64_t r3;
+   uint64_t r4;
+   uint64_t r5;
+   uint64_t r6;
+   uint64_t r7;
+   uint64_t r8;
+   uint64_t r9;
+   uint64_t r10;
+   uint64_t r11;
+   union {
+   uint64_t r12;
+   uint64_t sp;
+   };
+   union {
+   uint64_t r13;
+   uint64_t tp;
+   };
+   union {
+   uint64_t r14;
+   uint64_t fp;
+   };
+   uint64_t r15;
+   uint64_t r16;
+   uint64_t r17;
+   uint64_t r18;
+   uint64_t r19;
+   uint64_t r20;
+   uint64_t r21;
+   uint64_t r22;
+

Re: [RFC PATCH v2 09/31] kvx: Add build infrastructure

2023-01-20 Thread Arnd Bergmann
On Fri, Jan 20, 2023, at 15:09, Yann Sionneau wrote:
>  - Fix clean target raising an error from gcc (LIBGCC)

I had not noticed this on v1 but:

> +# Link with libgcc to get __div* builtins.
> +LIBGCC   := $(shell $(CC) $(DEFAULT_OPTS) --print-libgcc-file-name)

It's better to copy the bits of libgcc that you actually need
than to include the whole thing. The kernel is in a weird
state that is neither freestanding nor the normal libc based
environment, so we generally want full control over what is
used. This is particularly important for 32-bit architectures
that do not want the 64-bit division, but there are probably
enough other cases as well.

 Arnd

--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



Re: [RFC PATCH v2 09/31] kvx: Add build infrastructure

2023-01-20 Thread Jules Maselbas
On Fri, Jan 20, 2023 at 04:01:11PM +0100, Arnd Bergmann wrote:
> On Fri, Jan 20, 2023, at 15:53, Jules Maselbas wrote:
> > On Fri, Jan 20, 2023 at 03:39:22PM +0100, Arnd Bergmann wrote:
> >> On Fri, Jan 20, 2023, at 15:09, Yann Sionneau wrote:
> >> >  - Fix clean target raising an error from gcc (LIBGCC)
> >> 
> >> I had not noticed this on v1 but:
> >> 
> >> > +# Link with libgcc to get __div* builtins.
> >> > +LIBGCC  := $(shell $(CC) $(DEFAULT_OPTS) --print-libgcc-file-name)
> >> 
> >> It's better to copy the bits of libgcc that you actually need
> >> than to include the whole thing. The kernel is in a weird
> > It was initialy using KCONFIG_CFLAGS which do not contains valid options
> > when invoking the clean target.
> >
> > I am not exactly sure what's needed by gcc for --print-libgcc-file-name,
> > my guess is that only the -march option matters, I will double check
> > internally with compiler peoples.
> >
> >> state that is neither freestanding nor the normal libc based
> >> environment, so we generally want full control over what is
> >> used. This is particularly important for 32-bit architectures
> >> that do not want the 64-bit division, but there are probably
> >> enough other cases as well.
> 
> To clarify: I meant you should not include libgcc.a at all but
> add the minimum set of required files as arch/kvx/lib/*.S.
Thanks for clarifying :)


-- Jules




--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



[RFC PATCH v2 31/31] kvx: Add IPI driver

2023-01-20 Thread Yann Sionneau
From: Jules Maselbas 

The Inter-Processor Interrupt Controller (IPI) provides a fast
synchronization mechanism to the software. It exposes eight independent
set of registers that can be use to notify each processor in the cluster.
test

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Guillaume Thouvenin 
Signed-off-by: Guillaume Thouvenin 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Co-developed-by: Luc Michel 
Signed-off-by: Luc Michel 
Signed-off-by: Jules Maselbas 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: new patch

 arch/kvx/include/asm/ipi.h |  16 ++
 arch/kvx/platform/Makefile |   1 +
 arch/kvx/platform/ipi.c| 108 +
 3 files changed, 125 insertions(+)
 create mode 100644 arch/kvx/include/asm/ipi.h
 create mode 100644 arch/kvx/platform/ipi.c

diff --git a/arch/kvx/include/asm/ipi.h b/arch/kvx/include/asm/ipi.h
new file mode 100644
index ..137407a075e6
--- /dev/null
+++ b/arch/kvx/include/asm/ipi.h
@@ -0,0 +1,16 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#ifndef _ASM_KVX_IPI_H
+#define _ASM_KVX_IPI_H
+
+#include 
+
+int kvx_ipi_ctrl_probe(irqreturn_t (*ipi_irq_handler)(int, void *));
+
+void kvx_ipi_send(const struct cpumask *mask);
+
+#endif /* _ASM_KVX_IPI_H */
diff --git a/arch/kvx/platform/Makefile b/arch/kvx/platform/Makefile
index c7d0abb15c27..27f0914e0de5 100644
--- a/arch/kvx/platform/Makefile
+++ b/arch/kvx/platform/Makefile
@@ -4,3 +4,4 @@
 #
 
 obj-$(CONFIG_SMP) += pwr_ctrl.o
+obj-$(CONFIG_SMP) += ipi.o
diff --git a/arch/kvx/platform/ipi.c b/arch/kvx/platform/ipi.c
new file mode 100644
index ..a471039b1643
--- /dev/null
+++ b/arch/kvx/platform/ipi.c
@@ -0,0 +1,108 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ *Luc Michel
+ */
+
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define IPI_INTERRUPT_OFFSET   0x0
+#define IPI_MASK_OFFSET0x20
+
+/*
+ * IPI controller can signal RM and PE0 -> 15
+ * In order to restrict that to the PE, write the corresponding mask
+ */
+#define KVX_IPI_CPU_MASK   (~0x)
+
+struct kvx_ipi_ctrl {
+   void __iomem *regs;
+   unsigned int ipi_irq;
+};
+
+static struct kvx_ipi_ctrl kvx_ipi_controller;
+
+/**
+ * @kvx_pwr_ctrl_cpu_poweron Wakeup a cpu
+ *
+ * cpu: cpu to wakeup
+ */
+void kvx_ipi_send(const struct cpumask *mask)
+{
+   const unsigned long *maskb = cpumask_bits(mask);
+
+   WARN_ON(*maskb & KVX_IPI_CPU_MASK);
+   writel(*maskb, kvx_ipi_controller.regs + IPI_INTERRUPT_OFFSET);
+}
+
+static int kvx_ipi_starting_cpu(unsigned int cpu)
+{
+   enable_percpu_irq(kvx_ipi_controller.ipi_irq, IRQ_TYPE_NONE);
+
+   return 0;
+}
+
+static int kvx_ipi_dying_cpu(unsigned int cpu)
+{
+   disable_percpu_irq(kvx_ipi_controller.ipi_irq);
+
+   return 0;
+}
+
+int __init kvx_ipi_ctrl_probe(irqreturn_t (*ipi_irq_handler)(int, void *))
+{
+   struct device_node *np;
+   int ret;
+   unsigned int ipi_irq;
+   void __iomem *ipi_base;
+
+   np = of_find_compatible_node(NULL, NULL, "kalray,kvx-ipi-ctrl");
+   BUG_ON(!np);
+
+   ipi_base = of_iomap(np, 0);
+   BUG_ON(!ipi_base);
+
+   kvx_ipi_controller.regs = ipi_base;
+
+   /* Init mask for interrupts to PE0 -> PE15 */
+   writel(KVX_IPI_CPU_MASK, kvx_ipi_controller.regs + IPI_MASK_OFFSET);
+
+   ipi_irq = irq_of_parse_and_map(np, 0);
+   of_node_put(np);
+   if (!ipi_irq) {
+   pr_err("Failed to parse irq: %d\n", ipi_irq);
+   return -EINVAL;
+   }
+
+   ret = request_percpu_irq(ipi_irq, ipi_irq_handler,
+   "kvx_ipi", &kvx_ipi_controller);
+   if (ret) {
+   pr_err("can't register interrupt %d (%d)\n",
+   ipi_irq, ret);
+   return ret;
+   }
+   kvx_ipi_controller.ipi_irq = ipi_irq;
+
+   ret = cpuhp_setup_state(CPUHP_AP_IRQ_KVX_STARTING,
+   "kvx/ipi:online",
+   kvx_ipi_starting_cpu,
+   kvx_ipi_dying_cpu);
+   if (ret < 0) {
+   pr_err("Failed to setup hotplug state");
+   return ret;
+   }
+
+   return 0;
+}
-- 
2.37.2





--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



[RFC PATCH v2 26/31] kvx: Add multi-processor (SMP) support

2023-01-20 Thread Yann Sionneau
Coolidge v1 SoC has 5 clusters of 17 kvx cores:
 - 16 application cores aka PE
 - 1 privileged core, the Resource Manager, aka RM.

Linux can run in SMP config on the 16 cores of a Cluster.

Memory coherency between all cores is guarenteed by the L2 cache.

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Co-developed-by: Julien Hascoet 
Signed-off-by: Julien Hascoet 
Co-developed-by: Louis Morhet 
Signed-off-by: Louis Morhet 
Co-developed-by: Luc Michel 
Signed-off-by: Luc Michel 
Co-developed-by: Marius Gligor 
Signed-off-by: Marius Gligor 
Co-developed-by: Yann Sionneau 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2:
 - removed L2 cache driver
 - removed ipi and pwr-ctrl driver (splitted in their own patch)

 arch/kvx/include/asm/smp.h |  42 
 arch/kvx/kernel/smp.c  | 110 
 arch/kvx/kernel/smpboot.c  | 127 +
 include/linux/cpuhotplug.h |   2 +
 4 files changed, 281 insertions(+)
 create mode 100644 arch/kvx/include/asm/smp.h
 create mode 100644 arch/kvx/kernel/smp.c
 create mode 100644 arch/kvx/kernel/smpboot.c

diff --git a/arch/kvx/include/asm/smp.h b/arch/kvx/include/asm/smp.h
new file mode 100644
index ..e4fd4d001b2c
--- /dev/null
+++ b/arch/kvx/include/asm/smp.h
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#ifndef _ASM_KVX_SMP_H
+#define _ASM_KVX_SMP_H
+
+#include 
+#include 
+
+#include 
+
+#ifdef CONFIG_SMP
+
+/* Hook for the generic smp_call_function_many() routine. */
+void arch_send_call_function_ipi_mask(struct cpumask *mask);
+
+/* Hook for the generic smp_call_function_single() routine. */
+void arch_send_call_function_single_ipi(int cpu);
+
+void __init setup_processor(void);
+
+void smp_init_cpus(void);
+
+irqreturn_t ipi_call_interrupt(int irq, void *dev_id);
+
+#define raw_smp_processor_id() ((int) \
+   ((kvx_sfr_get(PCR) & KVX_SFR_PCR_PID_MASK) \
+   >> KVX_SFR_PCR_PID_SHIFT))
+
+#define flush_cache_vmap(start, end)   do { } while (0)
+#define flush_cache_vunmap(start, end) do { } while (0)
+
+#else
+
+void smp_init_cpus(void) {}
+
+#endif /* CONFIG_SMP */
+
+#endif
diff --git a/arch/kvx/kernel/smp.c b/arch/kvx/kernel/smp.c
new file mode 100644
index ..ed4c35a8c4bc
--- /dev/null
+++ b/arch/kvx/kernel/smp.c
@@ -0,0 +1,110 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include 
+#include 
+
+enum ipi_message_type {
+   IPI_RESCHEDULE,
+   IPI_CALL_FUNC,
+   IPI_IRQ_WORK,
+   IPI_MAX
+};
+
+/* A collection of single bit ipi messages.  */
+static struct {
+   unsigned long bits cacheline_aligned;
+} ipi_data[NR_CPUS] __cacheline_aligned;
+
+static void send_ipi_message(const struct cpumask *mask,
+enum ipi_message_type operation)
+{
+   unsigned long flags;
+   int cpu;
+
+   /* Set operation that must be done by receiver */
+   for_each_cpu(cpu, mask)
+   set_bit(operation, &ipi_data[cpu].bits);
+
+   /* Commit the write before sending IPI */
+   smp_wmb();
+
+   local_irq_save(flags);
+
+   kvx_ipi_send(mask);
+
+   local_irq_restore(flags);
+}
+
+void arch_send_call_function_ipi_mask(struct cpumask *mask)
+{
+   send_ipi_message(mask, IPI_CALL_FUNC);
+}
+
+void arch_send_call_function_single_ipi(int cpu)
+{
+   send_ipi_message(cpumask_of(cpu), IPI_CALL_FUNC);
+}
+
+#ifdef CONFIG_IRQ_WORK
+void arch_irq_work_raise(void)
+{
+   send_ipi_message(cpumask_of(smp_processor_id()), IPI_IRQ_WORK);
+}
+#endif
+
+static void ipi_stop(void *unused)
+{
+   local_cpu_stop();
+}
+
+void smp_send_stop(void)
+{
+   struct cpumask targets;
+
+   cpumask_copy(&targets, cpu_online_mask);
+   cpumask_clear_cpu(smp_processor_id(), &targets);
+
+   smp_call_function_many(&targets, ipi_stop, NULL, 0);
+}
+
+void smp_send_reschedule(int cpu)
+{
+   send_ipi_message(cpumask_of(cpu), IPI_RESCHEDULE);
+}
+
+irqreturn_t ipi_call_interrupt(int irq, void *dev_id)
+{
+   unsigned long *pending_ipis = &ipi_data[smp_processor_id()].bits;
+
+   while (true) {
+   unsigned long ops = xchg(pending_ipis, 0);
+
+   if (ops == 0)
+   return IRQ_HANDLED;
+
+   if (ops & (1 << IPI_RESCHEDULE))
+   scheduler_ipi();
+
+   if (ops & (1 << IPI_CALL_FUNC))
+   generic_smp_call_function_interrupt();
+
+   if (ops & (1 << IPI_IRQ_WORK))
+   irq_work_run();
+
+   BUG_ON((ops >> IPI_MAX) != 0);
+   }
+
+   return IRQ_HANDLED;
+}
diff

[RFC PATCH v2 08/31] kvx: Add ELF-related definitions

2023-01-20 Thread Yann Sionneau
Add ELF-related definitions for kvx, including: EM_KVX, AUDIT_ARCH_KVX
and NT_KVX_TCA.

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: no changes

 include/uapi/linux/audit.h  | 1 +
 include/uapi/linux/elf-em.h | 1 +
 include/uapi/linux/elf.h| 1 +
 3 files changed, 3 insertions(+)

diff --git a/include/uapi/linux/audit.h b/include/uapi/linux/audit.h
index d676ed2b246e..4db7aa3f84c7 100644
--- a/include/uapi/linux/audit.h
+++ b/include/uapi/linux/audit.h
@@ -402,6 +402,7 @@ enum {
 #define AUDIT_ARCH_HEXAGON (EM_HEXAGON)
 #define AUDIT_ARCH_I386(EM_386|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_IA64
(EM_IA_64|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
+#define AUDIT_ARCH_KVX (EM_KVX|__AUDIT_ARCH_64BIT|__AUDIT_ARCH_LE)
 #define AUDIT_ARCH_M32R(EM_M32R)
 #define AUDIT_ARCH_M68K(EM_68K)
 #define AUDIT_ARCH_MICROBLAZE  (EM_MICROBLAZE)
diff --git a/include/uapi/linux/elf-em.h b/include/uapi/linux/elf-em.h
index ef38c2bc5ab7..9cc348be7f86 100644
--- a/include/uapi/linux/elf-em.h
+++ b/include/uapi/linux/elf-em.h
@@ -51,6 +51,7 @@
 #define EM_RISCV   243 /* RISC-V */
 #define EM_BPF 247 /* Linux BPF - in-kernel virtual machine */
 #define EM_CSKY252 /* C-SKY */
+#define EM_KVX 256 /* Kalray VLIW Architecture */
 #define EM_LOONGARCH   258 /* LoongArch */
 #define EM_FRV 0x5441  /* Fujitsu FR-V */
 
diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
index c7b056af9ef0..49094f3be06c 100644
--- a/include/uapi/linux/elf.h
+++ b/include/uapi/linux/elf.h
@@ -444,6 +444,7 @@ typedef struct elf64_shdr {
 #define NT_LOONGARCH_LSX   0xa02   /* LoongArch Loongson SIMD Extension 
registers */
 #define NT_LOONGARCH_LASX  0xa03   /* LoongArch Loongson Advanced SIMD 
Extension registers */
 #define NT_LOONGARCH_LBT   0xa04   /* LoongArch Loongson Binary 
Translation registers */
+#define NT_KVX_TCA 0x900   /* kvx TCA registers */
 
 /* Note types with note name "GNU" */
 #define NT_GNU_PROPERTY_TYPE_0 5
-- 
2.37.2





--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



[RFC PATCH v2 27/31] kvx: Add kvx default config file

2023-01-20 Thread Yann Sionneau
Add a default config file for kvx based Coolidge SoC.

Co-developed-by: Ashley Lesdalons 
Signed-off-by: Ashley Lesdalons 
Co-developed-by: Benjamin Mugnier 
Signed-off-by: Benjamin Mugnier 
Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Guillaume Thouvenin 
Signed-off-by: Guillaume Thouvenin 
Co-developed-by: Jules Maselbas 
Signed-off-by: Jules Maselbas 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Co-developed-by: Samuel Jones 
Signed-off-by: Samuel Jones 
Co-developed-by: Thomas Costis 
Signed-off-by: Thomas Costis 
Co-developed-by: Vincent Chardon 
Signed-off-by: Vincent Chardon 
Co-developed-by: Yann Sionneau 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: default_defconfig renamed to defconfig

 arch/kvx/configs/defconfig | 127 +
 1 file changed, 127 insertions(+)
 create mode 100644 arch/kvx/configs/defconfig

diff --git a/arch/kvx/configs/defconfig b/arch/kvx/configs/defconfig
new file mode 100644
index ..960784da0b1b
--- /dev/null
+++ b/arch/kvx/configs/defconfig
@@ -0,0 +1,127 @@
+CONFIG_DEFAULT_HOSTNAME="KVXlinux"
+CONFIG_SERIAL_KVX_SCALL_COMM=y
+CONFIG_CONFIGFS_FS=y
+CONFIG_DEBUG_KERNEL=y
+CONFIG_DEBUG_INFO=y
+CONFIG_DEBUG_INFO_DWARF4=y
+CONFIG_PRINTK_TIME=y
+CONFIG_CONSOLE_LOGLEVEL_DEFAULT=15
+CONFIG_MESSAGE_LOGLEVEL_DEFAULT=7
+CONFIG_PANIC_TIMEOUT=-1
+CONFIG_BLK_DEV_INITRD=y
+CONFIG_GDB_SCRIPTS=y
+CONFIG_FRAME_POINTER=y
+CONFIG_HZ_100=y
+CONFIG_SERIAL_EARLYCON=y
+CONFIG_HOTPLUG_PCI_PCIE=y
+CONFIG_PCIEAER=y
+CONFIG_PCIE_DPC=y
+CONFIG_HOTPLUG_PCI=y
+CONFIG_SERIAL_8250=y
+CONFIG_SERIAL_8250_CONSOLE=y
+CONFIG_SERIAL_8250_DW=y
+CONFIG_SERIAL_8250_NR_UARTS=8
+CONFIG_SERIAL_8250_RUNTIME_UARTS=8
+CONFIG_PINCTRL=y
+CONFIG_PINCTRL_SINGLE=y
+CONFIG_POWER_RESET_KVX_SCALL_POWEROFF=y
+CONFIG_PCI=y
+CONFIG_PCI_MSI=y
+CONFIG_PCIE_KVX_NWL=y
+CONFIG_PCIEPORTBUS=y
+# CONFIG_PCIEASPM is not set
+CONFIG_PCIEAER_INJECT=y
+CONFIG_TMPFS=y
+CONFIG_DMADEVICES=y
+CONFIG_KVX_DMA_NOC=m
+CONFIG_KVX_IOMMU=y
+CONFIG_KVX_OTP_NV=y
+CONFIG_PACKET=y
+CONFIG_NET=y
+# CONFIG_WLAN is not set
+CONFIG_INET=y
+CONFIG_IPV6=y
+CONFIG_NETDEVICES=y
+CONFIG_NET_CORE=y
+CONFIG_E1000E=y
+CONFIG_BLK_DEV_NVME=y
+CONFIG_VFAT_FS=y
+CONFIG_NLS_DEFAULT="iso8859-1"
+CONFIG_NLS_CODEPAGE_437=y
+CONFIG_NLS_ISO8859_1=y
+CONFIG_WATCHDOG=y
+CONFIG_KVX_WATCHDOG=y
+CONFIG_HUGETLBFS=y
+CONFIG_MAILBOX=y
+CONFIG_KVX_MBOX=y
+CONFIG_REMOTEPROC=y
+CONFIG_KVX_REMOTEPROC=y
+CONFIG_VIRTIO_NET=y
+CONFIG_VIRTIO_MMIO=y
+CONFIG_RPMSG_VIRTIO=y
+CONFIG_RPMSG_CHAR=y
+CONFIG_MODULES=y
+CONFIG_MODULE_UNLOAD=y
+CONFIG_MODVERSIONS=y
+CONFIG_MODULE_SRCVERSION_ALL=y
+CONFIG_BLK_DEV=y
+CONFIG_BLK_DEV_LOOP=m
+CONFIG_BLK_DEV_LOOP_MIN_COUNT=8
+CONFIG_EXT4_FS=m
+CONFIG_EXT4_USE_FOR_EXT2=y
+CONFIG_SYSVIPC=y
+CONFIG_UNIX=y
+CONFIG_NET_VENDOR_KALRAY=y
+CONFIG_NET_KVX_SOC=m
+CONFIG_STACKPROTECTOR=y
+CONFIG_GPIO_DWAPB=y
+CONFIG_I2C=y
+CONFIG_I2C_SLAVE=y
+CONFIG_I2C_CHARDEV=y
+CONFIG_I2C_DESIGNWARE_PLATFORM=y
+CONFIG_I2C_DESIGNWARE_CORE=y
+CONFIG_I2C_DESIGNWARE_SLAVE=y
+CONFIG_I2C_SLAVE_USPACE=y
+CONFIG_POWER_RESET=y
+CONFIG_POWER_RESET_SYSCON=y
+CONFIG_SPI=y
+CONFIG_SPI_DESIGNWARE=y
+CONFIG_SPI_DW_MMIO=y
+CONFIG_SPI_DW_KVX=y
+CONFIG_MTD=y
+CONFIG_MTD_SPI_NOR=y
+# CONFIG_MTD_SPI_NOR_USE_4K_SECTORS is not set
+CONFIG_SQUASHFS=m
+CONFIG_USB=y
+CONFIG_USB_CONFIGFS=m
+CONFIG_USB_CONFIGFS_ACM=y
+CONFIG_USB_CONFIGFS_ECM=y
+CONFIG_USB_DWC2=y
+CONFIG_USB_DWC2_DUAL_ROLE=y
+CONFIG_USB_GADGET=y
+CONFIG_U_SERIAL_CONSOLE=y
+CONFIG_USB_USBNET=m
+CONFIG_USB_NET_SMSC95XX=m
+# CONFIG_NOP_USB_XCEIV is not set
+CONFIG_USB_PHY=y
+CONFIG_GENERIC_PHY=y
+CONFIG_GENERIC_PHY_USB=y
+CONFIG_MMC=y
+CONFIG_MMC_SDHCI=y
+CONFIG_MMC_SDHCI_PLTFM=y
+CONFIG_MMC_SDHCI_OF_DWCMSHC=y
+CONFIG_MDIO_BITBANG=m
+CONFIG_MDIO_GPIO=m
+CONFIG_MARVELL_PHY=m
+CONFIG_GPIO_PCA953X=y
+CONFIG_NETFILTER=y
+CONFIG_NF_CONNTRACK=m
+CONFIG_NF_NAT=m
+CONFIG_IP_NF_IPTABLES=m
+CONFIG_IP_NF_NAT=m
+CONFIG_LEDS_GPIO=y
+CONFIG_LEDS_CLASS=y
+CONFIG_LEDS_TRIGGERS=y
+CONFIG_LEDS_TRIGGER_NETDEV=y
+CONFIG_LEDS_TRIGGER_PATTERN=y
+CONFIG_DCB=y
-- 
2.37.2





--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



[RFC PATCH v2 02/31] Documentation: Add binding for kalray,kv3-1-core-intc

2023-01-20 Thread Yann Sionneau
From: Jules Maselbas 

Add documentation for `kalray,kv3-1-core-intc` binding.

Co-developed-by: Jules Maselbas 
Signed-off-by: Jules Maselbas 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: new patch

 .../kalray,kv3-1-core-intc.yaml   | 46 +++
 1 file changed, 46 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-core-intc.yaml

diff --git 
a/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-core-intc.yaml
 
b/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-core-intc.yaml
new file mode 100644
index ..1e3d0593173a
--- /dev/null
+++ 
b/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-core-intc.yaml
@@ -0,0 +1,46 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/interrupt-controller/kalray,kv3-1-core-intc#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Kalray kv3-1 Core Interrupt Controller
+
+description: |
+  The Kalray Core Interrupt Controller is tightly integrated in each kv3 core
+  present in the Coolidge SoC.
+
+  It provides the following features:
+  - 32 independent interrupt sources
+  - 2-bit configurable priority level
+  - 2-bit configurable ownership level
+
+allOf:
+  - $ref: /schemas/interrupt-controller.yaml#
+
+properties:
+  compatible:
+const: kalray,kv3-1-core-intc
+  "#interrupt-cells":
+const: 1
+description:
+  The IRQ number.
+  reg:
+maxItems: 0
+  "kalray,intc-nr-irqs":
+description: Number of irqs handled by the controller.
+
+required:
+  - compatible
+  - "#interrupt-cells"
+  - interrupt-controller
+
+examples:
+  - |
+intc: interrupt-controller {
+compatible = "kalray,kv3-1-core-intc";
+#interrupt-cells = <1>;
+interrupt-controller;
+};
+
+...
-- 
2.37.2





--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



Re: [RFC PATCH v2 04/31] Documentation: Add binding for kalray,kv3-1-apic-mailbox

2023-01-20 Thread Rob Herring


On Fri, 20 Jan 2023 15:09:35 +0100, Yann Sionneau wrote:
> From: Jules Maselbas 
> 
> Add documentation for `kalray,kv3-1-core-intc` binding.
> 
> Co-developed-by: Jules Maselbas 
> Signed-off-by: Jules Maselbas 
> Signed-off-by: Yann Sionneau 
> ---
> 
> Notes:
> V1 -> V2: new patch
> 
>  .../kalray,kv3-1-apic-mailbox.yaml| 75 +++
>  1 file changed, 75 insertions(+)
>  create mode 100644 
> Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-apic-mailbox.yaml
> 

My bot found errors running 'make DT_CHECKER_FLAGS=-m dt_binding_check'
on your patch (DT_CHECKER_FLAGS is new in v5.13):

yamllint warnings/errors:

dtschema/dtc warnings/errors:
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-apic-mailbox.yaml:
 $id: 
'http://devicetree.org/schemas/interrupt-controller/kalray,kv3-1-apic-mailbox#' 
does not match 'http://devicetree.org/schemas/.*\\.yaml#'
from schema $id: http://devicetree.org/meta-schemas/base.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-apic-mailbox.yaml:
 'maintainers' is a required property
hint: Metaschema for devicetree binding documentation
from schema $id: http://devicetree.org/meta-schemas/base.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-apic-mailbox.yaml:
 'oneOf' conditional failed, one must be fixed:
'unevaluatedProperties' is a required property
'additionalProperties' is a required property
hint: Either unevaluatedProperties or additionalProperties must be 
present
from schema $id: http://devicetree.org/meta-schemas/core.yaml#
/builds/robherring/dt-review-ci/linux/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-apic-mailbox.yaml:
 properties:interrupt-parent: False schema does not allow True
from schema $id: http://devicetree.org/meta-schemas/interrupts.yaml#
./Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-apic-mailbox.yaml:
 $id: relative path/filename doesn't match actual path or filename
expected: 
http://devicetree.org/schemas/interrupt-controller/kalray,kv3-1-apic-mailbox.yaml#
Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-apic-mailbox.example.dtb:
 /example-0/interrupt-controller@a0: failed to match any schema with 
compatible: ['kalray,kv3-1-apic-gic']

doc reference errors (make refcheckdocs):

See 
https://patchwork.ozlabs.org/project/devicetree-bindings/patch/20230120141002.2442-5-ysionn...@kalray.eu

The base for the series is generally the latest rc1. A different dependency
should be noted in *this* patch.

If you already ran 'make dt_binding_check' and didn't see the above
error(s), then make sure 'yamllint' is installed and dt-schema is up to
date:

pip3 install dtschema --upgrade

Please check and re-submit after running the above command yourself. Note
that DT_SCHEMA_FILES can be set to your schema file to speed up checking
your schema. However, it must be unset to test all examples with your schema.

--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



Re: [RFC PATCH v2 09/31] kvx: Add build infrastructure

2023-01-20 Thread Arnd Bergmann
On Fri, Jan 20, 2023, at 15:53, Jules Maselbas wrote:
> On Fri, Jan 20, 2023 at 03:39:22PM +0100, Arnd Bergmann wrote:
>> On Fri, Jan 20, 2023, at 15:09, Yann Sionneau wrote:
>> >  - Fix clean target raising an error from gcc (LIBGCC)
>> 
>> I had not noticed this on v1 but:
>> 
>> > +# Link with libgcc to get __div* builtins.
>> > +LIBGCC:= $(shell $(CC) $(DEFAULT_OPTS) --print-libgcc-file-name)
>> 
>> It's better to copy the bits of libgcc that you actually need
>> than to include the whole thing. The kernel is in a weird
> It was initialy using KCONFIG_CFLAGS which do not contains valid options
> when invoking the clean target.
>
> I am not exactly sure what's needed by gcc for --print-libgcc-file-name,
> my guess is that only the -march option matters, I will double check
> internally with compiler peoples.
>
>> state that is neither freestanding nor the normal libc based
>> environment, so we generally want full control over what is
>> used. This is particularly important for 32-bit architectures
>> that do not want the 64-bit division, but there are probably
>> enough other cases as well.

To clarify: I meant you should not include libgcc.a at all but
add the minimum set of required files as arch/kvx/lib/*.S.

 Arnd

--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



[RFC PATCH v2 17/31] irqchip: Add irq-kvx-apic-mailbox driver

2023-01-20 Thread Yann Sionneau
From: Jules Maselbas 

The APIC includes a mailbox controller, containing 128 mailboxes.
Each mailbox is a word of 8 bytes in the controller internal memory.
Each mailbox can be independently configured with a trigger condition
and an input function.

After a write to a mailbox if the mailbox's trigger condition is met
then an interrupt will be generated.

Since this hardware block generates IRQs based on writes at some memory
locations, it is both an interrupt controller and an MSI controller.

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Jules Maselbas 
Signed-off-by: Jules Maselbas 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Co-developed-by: Luc Michel 
Signed-off-by: Luc Michel 
Co-developed-by: Yann Sionneau 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: new patch
 - removed print on probe success

 drivers/irqchip/Kconfig|   8 +
 drivers/irqchip/Makefile   |   1 +
 drivers/irqchip/irq-kvx-apic-mailbox.c | 480 +
 3 files changed, 489 insertions(+)
 create mode 100644 drivers/irqchip/irq-kvx-apic-mailbox.c

diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
index 546bc611f3f3..806adbc7b2a4 100644
--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -348,6 +348,14 @@ config KVX_ITGEN
select IRQ_DOMAIN
select IRQ_DOMAIN_HIERARCHY
 
+config KVX_APIC_MAILBOX
+   bool
+   depends on KVX
+   select GENERIC_IRQ_IPI if SMP
+   select GENERIC_MSI_IRQ_DOMAIN
+   select IRQ_DOMAIN
+   select IRQ_DOMAIN_HIERARCHY
+
 config INGENIC_IRQ
bool
depends on MACH_INGENIC
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index 6b8f459d8a21..7eaea87ca9ab 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -71,6 +71,7 @@ obj-$(CONFIG_KEYSTONE_IRQ)+= irq-keystone.o
 obj-$(CONFIG_MIPS_GIC) += irq-mips-gic.o
 obj-$(CONFIG_KVX_APIC_GIC) += irq-kvx-apic-gic.o
 obj-$(CONFIG_KVX_ITGEN)+= irq-kvx-itgen.o
+obj-$(CONFIG_KVX_APIC_MAILBOX) += irq-kvx-apic-mailbox.o
 obj-$(CONFIG_ARCH_MEDIATEK)+= irq-mtk-sysirq.o irq-mtk-cirq.o
 obj-$(CONFIG_ARCH_DIGICOLOR)   += irq-digicolor.o
 obj-$(CONFIG_ARCH_SA1100)  += irq-sa11x0.o
diff --git a/drivers/irqchip/irq-kvx-apic-mailbox.c 
b/drivers/irqchip/irq-kvx-apic-mailbox.c
new file mode 100644
index ..33249df047b6
--- /dev/null
+++ b/drivers/irqchip/irq-kvx-apic-mailbox.c
@@ -0,0 +1,480 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ *Jules Maselbas
+ */
+
+#define pr_fmt(fmt)"kvx_apic_mailbox: " fmt
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#define KVX_MAILBOX_MODE_WRITE  0x0
+#define KVX_MAILBOX_MODE_OR  0x1
+#define KVX_MAILBOX_MODE_ADD  0x2
+
+#define KVX_MAILBOX_TRIG_NO_TRIG 0x0
+#define KVX_MAILBOX_TRIG_DOORBELL 0x1
+#define KVX_MAILBOX_TRIG_MATCH 0x2
+#define KVX_MAILBOX_TRIG_BARRIER 0x3
+#define KVX_MAILBOX_TRIG_THRESHOLD 0x4
+
+#define KVX_MAILBOX_OFFSET 0x0
+#define KVX_MAILBOX_ELEM_SIZE 0x200
+#define KVX_MAILBOX_MASK_OFFSET 0x10
+#define KVX_MAILBOX_FUNCT_OFFSET 0x18
+#define KVX_MAILBOX_LAC_OFFSET 0x8
+#define KVX_MAILBOX_VALUE_OFFSET 0x0
+#define KVX_MAILBOX_FUNCT_MODE_SHIFT  0x0
+#define KVX_MAILBOX_FUNCT_TRIG_SHIFT 0x8
+
+#define MAILBOXES_MAX_COUNT 128
+
+/* Mailboxes are 64 bits wide */
+#define MAILBOXES_BIT_SIZE 64
+
+/* Maximum number of mailboxes available */
+#define MAILBOXES_MAX_BIT_COUNT (MAILBOXES_MAX_COUNT * MAILBOXES_BIT_SIZE)
+
+/* Mailboxes are grouped by 8 in a single page */
+#define MAILBOXES_BITS_PER_PAGE (8 * MAILBOXES_BIT_SIZE)
+
+/**
+ * struct mb_data - per mailbox data
+ * @cpu: CPU on which the mailbox is routed
+ * @parent_irq: Parent IRQ on the GIC
+ */
+struct mb_data {
+   unsigned int cpu;
+   unsigned int parent_irq;
+};
+
+/**
+ * struct kvx_apic_mailbox - kvx apic mailbox
+ * @base: base address of the controller
+ * @device_domain: IRQ device domain for mailboxes
+ * @msi_domain: platform MSI domain for MSI interface
+ * @domain_info: Domain information needed for the MSI domain
+ * @mb_count: Count of mailboxes we are handling
+ * @available: bitmap of availables bits in mailboxes
+ * @mailboxes_lock: lock for irq migration
+ * @mask_lock: lock for irq masking
+ * @mb_data: data associated to each mailbox
+ */
+struct kvx_apic_mailbox {
+   void __iomem *base;
+   phys_addr_t phys_base;
+   struct irq_domain *device_domain;
+   struct irq_domain *msi_domain;
+   struct msi_domain_info domain_info;
+   /* Start and count of device mailboxes */
+   unsigned int mb_count;
+   /* Bitmap of allocated bits in mailboxes */
+   DECLARE_BITMAP(available, MAILBOXES_MAX_BIT_COUNT);
+  

[RFC PATCH v2 29/31] kvx: Add support for cpuinfo

2023-01-20 Thread Yann Sionneau
Add support for cpuinfo on kvx arch.

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Guillaume Thouvenin 
Signed-off-by: Guillaume Thouvenin 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Signed-off-by: Jules Maselbas 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: no changes

 arch/kvx/kernel/cpuinfo.c | 96 +++
 1 file changed, 96 insertions(+)
 create mode 100644 arch/kvx/kernel/cpuinfo.c

diff --git a/arch/kvx/kernel/cpuinfo.c b/arch/kvx/kernel/cpuinfo.c
new file mode 100644
index ..f44c46c1e4ba
--- /dev/null
+++ b/arch/kvx/kernel/cpuinfo.c
@@ -0,0 +1,96 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (C) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ *Guillaume Thouvenin
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+
+unsigned long elf_hwcap __read_mostly;
+
+static int show_cpuinfo(struct seq_file *m, void *v)
+{
+   int cpu_num = *(unsigned int *)v;
+   struct cpuinfo_kvx *n = per_cpu_ptr(&cpu_info, cpu_num);
+
+   seq_printf(m, "processor\t: %d\nvendor_id\t: Kalray\n", cpu_num);
+
+   seq_printf(m,
+  "copro enabled\t: %s\n"
+  "arch revision\t: %d\n"
+  "uarch revision\t: %d\n",
+  n->copro_enable ? "yes" : "no",
+  n->arch_rev,
+  n->uarch_rev);
+
+   seq_printf(m,
+  "bogomips\t: %lu.%02lu\n"
+  "cpu MHz\t\t: %llu.%03llu\n\n",
+  (loops_per_jiffy * HZ) / 50,
+  ((loops_per_jiffy * HZ) / 5000) % 100,
+  n->freq / 100, (n->freq / 1) % 100);
+
+   return 0;
+}
+
+static void *c_start(struct seq_file *m, loff_t *pos)
+{
+   if (*pos == 0)
+   *pos = cpumask_first(cpu_online_mask);
+   if (*pos >= num_online_cpus())
+   return NULL;
+
+   return pos;
+}
+
+static void *c_next(struct seq_file *m, void *v, loff_t *pos)
+{
+   *pos = cpumask_next(*pos, cpu_online_mask);
+
+   return c_start(m, pos);
+}
+
+static void c_stop(struct seq_file *m, void *v)
+{
+}
+
+const struct seq_operations cpuinfo_op = {
+   .start = c_start,
+   .next = c_next,
+   .stop = c_stop,
+   .show = show_cpuinfo,
+};
+
+static int __init setup_cpuinfo(void)
+{
+   int cpu;
+   struct clk *clk;
+   unsigned long cpu_freq = 10;
+   struct device_node *node = of_get_cpu_node(0, NULL);
+
+   clk = of_clk_get(node, 0);
+   if (IS_ERR(clk)) {
+   printk(KERN_WARNING
+  "Device tree missing CPU 'clock' parameter. Assuming 
frequency is 1GHZ");
+   goto setup_cpu_freq;
+   }
+
+   cpu_freq = clk_get_rate(clk);
+
+   clk_put(clk);
+
+setup_cpu_freq:
+   of_node_put(node);
+
+   for_each_possible_cpu(cpu)
+   per_cpu_ptr(&cpu_info, cpu)->freq = cpu_freq;
+
+   return 0;
+}
+
+late_initcall(setup_cpuinfo);
-- 
2.37.2





--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



[RFC PATCH v2 04/31] Documentation: Add binding for kalray,kv3-1-apic-mailbox

2023-01-20 Thread Yann Sionneau
From: Jules Maselbas 

Add documentation for `kalray,kv3-1-core-intc` binding.

Co-developed-by: Jules Maselbas 
Signed-off-by: Jules Maselbas 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: new patch

 .../kalray,kv3-1-apic-mailbox.yaml| 75 +++
 1 file changed, 75 insertions(+)
 create mode 100644 
Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-apic-mailbox.yaml

diff --git 
a/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-apic-mailbox.yaml
 
b/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-apic-mailbox.yaml
new file mode 100644
index ..e1eb1c9fda0d
--- /dev/null
+++ 
b/Documentation/devicetree/bindings/interrupt-controller/kalray,kv3-1-apic-mailbox.yaml
@@ -0,0 +1,75 @@
+# SPDX-License-Identifier: GPL-2.0
+%YAML 1.2
+---
+$id: 
http://devicetree.org/schemas/interrupt-controller/kalray,kv3-1-apic-mailbox#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: Kalray kv3-1 APIC-Mailbox
+
+description: |
+  Each cluster in the Coolidge SoC includes an Advanced Programmable Interrupt
+  Controller (APIC) which is split in two part:
+- a Generic Interrupt Controller (referred as APIC-GIC)
+- a Mailbox Controller   (referred as APIC-Mailbox)
+  The APIC-Mailbox contains 128 mailboxes of 8 bytes (size of a word),
+  this hardware block is basically a 1 KB of smart memory space.
+  Each mailbox can be independently configured with a trigger condition
+  and an input mode function.
+
+  Input mode are:
+   - write
+   - bitwise OR
+   - add
+
+  Interrupts are generated on a write when the mailbox content value
+  match the configured trigger condition.
+  Available conditions are:
+   - doorbell: always raise interruption on write
+   - match: when the mailbox's value equal the configured trigger value
+   - barrier: same as match but the mailbox's value is cleared on trigger
+   - threshold: when the mailbox's value is greater than, or equal to, the
+ configured trigger value
+
+  Since this hardware block generates IRQs based on writes to some memory
+  locations, it is both an interrupt controller and an MSI controller.
+
+allOf:
+  - $ref: /schemas/interrupt-controller.yaml#
+
+properties:
+  compatible:
+const: kalray,kv3-1-apic-mailbox
+  "#interrupt-cells":
+const: 1
+description:
+  The IRQ number.
+  interrupt-controller: true
+  interrupt-parent: true
+  interrupts:
+maxItems: 128
+description: |
+ Specifies the interrupt line(s) in the interrupt-parent controller node;
+ valid values depend on the type of parent interrupt controller
+  msi-controller: true
+
+required:
+  - compatible
+  - reg
+  - "#interrupt-cells"
+  - interrupt-controller
+  - interrupt-parent
+  - interrupts
+  - msi-controller
+
+examples:
+  - |
+apic_mailbox: interrupt-controller@a0 {
+compatible = "kalray,kv3-1-apic-gic";
+reg = <0 0xa0 0 0x0f200>;
+#interrupt-cells = <1>;
+interrupt-controller;
+interrupt-parent = <&apic_gic>;
+interrups = <0 1 2 3 4 5 6 7 8 9>;
+};
+
+...
-- 
2.37.2





--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



[RFC PATCH v2 16/31] irqchip: Add irq-kvx-itgen driver

2023-01-20 Thread Yann Sionneau
From: Jules Maselbas 

The Kalray Core Interrupt Controller is tightly integrated in each kv3
core present in the Coolidge SoC.

It provides the following features:
 - 32 independent interrupt sources
 - 2-bit configurable priority level
 - 2-bit configurable ownership level

Co-developed-by: Clement Leger 
Signed-off-by: Clement Leger 
Co-developed-by: Julian Vetter 
Signed-off-by: Julian Vetter 
Co-developed-by: Vincent Chardon 
Signed-off-by: Vincent Chardon 
Signed-off-by: Jules Maselbas 
Signed-off-by: Yann Sionneau 
---

Notes:
V1 -> V2: new patch
 - removed header include/linux/irqchip/irq-kvx-apic-gic.h
 - header moved to drivers/irqchip/ but in another patch
 - removed print on probe success

 drivers/irqchip/Kconfig |   8 ++
 drivers/irqchip/Makefile|   1 +
 drivers/irqchip/irq-kvx-itgen.c | 236 
 3 files changed, 245 insertions(+)
 create mode 100644 drivers/irqchip/irq-kvx-itgen.c

diff --git a/drivers/irqchip/Kconfig b/drivers/irqchip/Kconfig
index 2433e4ba0759..546bc611f3f3 100644
--- a/drivers/irqchip/Kconfig
+++ b/drivers/irqchip/Kconfig
@@ -340,6 +340,14 @@ config KVX_APIC_GIC
select IRQ_DOMAIN
select IRQ_DOMAIN_HIERARCHY
 
+config KVX_ITGEN
+   bool
+   depends on KVX
+   select GENERIC_IRQ_IPI if SMP
+   select GENERIC_MSI_IRQ_DOMAIN
+   select IRQ_DOMAIN
+   select IRQ_DOMAIN_HIERARCHY
+
 config INGENIC_IRQ
bool
depends on MACH_INGENIC
diff --git a/drivers/irqchip/Makefile b/drivers/irqchip/Makefile
index 8ac1dd880420..6b8f459d8a21 100644
--- a/drivers/irqchip/Makefile
+++ b/drivers/irqchip/Makefile
@@ -70,6 +70,7 @@ obj-$(CONFIG_BRCMSTB_L2_IRQ)  += irq-brcmstb-l2.o
 obj-$(CONFIG_KEYSTONE_IRQ) += irq-keystone.o
 obj-$(CONFIG_MIPS_GIC) += irq-mips-gic.o
 obj-$(CONFIG_KVX_APIC_GIC) += irq-kvx-apic-gic.o
+obj-$(CONFIG_KVX_ITGEN)+= irq-kvx-itgen.o
 obj-$(CONFIG_ARCH_MEDIATEK)+= irq-mtk-sysirq.o irq-mtk-cirq.o
 obj-$(CONFIG_ARCH_DIGICOLOR)   += irq-digicolor.o
 obj-$(CONFIG_ARCH_SA1100)  += irq-sa11x0.o
diff --git a/drivers/irqchip/irq-kvx-itgen.c b/drivers/irqchip/irq-kvx-itgen.c
new file mode 100644
index ..f6af023a689e
--- /dev/null
+++ b/drivers/irqchip/irq-kvx-itgen.c
@@ -0,0 +1,236 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * Copyright (c) 2017-2023 Kalray Inc.
+ * Author(s): Clement Leger
+ *Julian Vetter
+ *Vincent Chardon
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+/* Parameters */
+#define KVX_ITGEN_PARAM_OFFSET 0x1100
+#define KVX_ITGEN_PARAM_IT_NUM_OFFSET  0x0
+
+/* Target configuration */
+#define KVX_ITGEN_CFG_ENABLE_OFFSET0x8
+#define KVX_ITGEN_CFG_ELEM_SIZE0x10
+#define KVX_ITGEN_CFG_TARGET_OFFSET0x0
+#define KVX_ITGEN_CFG_TARGET_MAILBOX_SHIFT 0x0
+#define KVX_ITGEN_CFG_TARGET_MAILBOX_MASK  0x7FUL
+#define KVX_ITGEN_CFG_TARGET_CLUSTER_SHIFT 0x8
+#define KVX_ITGEN_CFG_TARGET_CLUSTER_MASK  0x700UL
+#define KVX_ITGEN_CFG_TARGET_SELECT_BIT_SHIFT  0x18
+#define KVX_ITGEN_CFG_TARGET_SELECT_BIT_MASK   0x3F00UL
+
+#define MB_ADDR_CLUSTER_SHIFT  24
+#define MB_ADDR_MAILBOX_SHIFT  9
+
+/**
+ * struct kvx_itgen - kvx interrupt generator (MSI client)
+ * @base: base address of the itgen controller
+ * @domain: IRQ domain of the controller
+ * @pdev: Platform device associated to the controller
+ */
+struct kvx_itgen {
+   void __iomem *base;
+   struct irq_domain *domain;
+   struct platform_device *pdev;
+};
+
+static void __iomem *get_itgen_cfg_offset(struct kvx_itgen *itgen,
+   irq_hw_number_t hwirq)
+{
+   return itgen->base + KVX_ITGEN_CFG_TARGET_OFFSET +
+   hwirq * KVX_ITGEN_CFG_ELEM_SIZE;
+}
+
+void __iomem *get_itgen_param_offset(struct kvx_itgen *itgen)
+{
+   return itgen->base + KVX_ITGEN_PARAM_OFFSET;
+}
+
+static void kvx_itgen_enable(struct irq_data *data, u32 value)
+{
+   struct kvx_itgen *itgen = irq_data_get_irq_chip_data(data);
+   void __iomem *enable_reg =
+   get_itgen_cfg_offset(itgen, irqd_to_hwirq(data)) +
+   KVX_ITGEN_CFG_ENABLE_OFFSET;
+
+   dev_dbg(&itgen->pdev->dev, "%sabling hwirq %d, addr %p\n",
+value ? "En" : "Dis",
+(int) irqd_to_hwirq(data),
+enable_reg);
+   writel(value, enable_reg);
+}
+
+static void kvx_itgen_mask(struct irq_data *data)
+{
+   kvx_itgen_enable(data, 0x0);
+   irq_chip_mask_parent(data);
+}
+
+static void kvx_itgen_unmask(struct irq_data *data)
+{
+   kvx_itgen_enable(data, 0x1);
+   irq_chip_unmask_parent(data);
+}
+
+#ifdef CONFIG_SMP
+static int kvx_itgen_irq_set_affinity(struct irq_data *data,
+

Re: [PATCH v6 3/3] fanotify,audit: Allow audit to use the full permission event response

2023-01-20 Thread Paul Moore
On Tue, Jan 17, 2023 at 4:14 PM Richard Guy Briggs  wrote:
>
> This patch passes the full response so that the audit function can use all
> of it. The audit function was updated to log the additional information in
> the AUDIT_FANOTIFY record.
>
> Currently the only type of fanotify info that is defined is an audit
> rule number, but convert it to hex encoding to future-proof the field.
> Hex encoding suggested by Paul Moore .
>
> The {subj,obj}_trust values are {0,1,2}, corresponding to no, yes, unknown.
>
> Sample records:
>   type=FANOTIFY msg=audit(1600385147.372:590): resp=2 fan_type=1 
> fan_info=3137 subj_trust=3 obj_trust=5
>   type=FANOTIFY msg=audit(1659730979.839:284): resp=1 fan_type=0 fan_info=3F 
> subj_trust=2 obj_trust=2
>
> Suggested-by: Steve Grubb 
> Link: https://lore.kernel.org/r/3075502.aeNJFYEL58@x2
> Signed-off-by: Richard Guy Briggs 
> ---
>  fs/notify/fanotify/fanotify.c |  3 ++-
>  include/linux/audit.h |  9 +
>  kernel/auditsc.c  | 16 +---
>  3 files changed, 20 insertions(+), 8 deletions(-)

...

> diff --git a/kernel/auditsc.c b/kernel/auditsc.c
> index d1fb821de104..3133c4175c15 100644
> --- a/kernel/auditsc.c
> +++ b/kernel/auditsc.c
> @@ -2877,10 +2878,19 @@ void __audit_log_kern_module(char *name)
> context->type = AUDIT_KERN_MODULE;
>  }
>
> -void __audit_fanotify(u32 response)
> +void __audit_fanotify(u32 response, struct fanotify_response_info_audit_rule 
> *friar)
>  {
> -   audit_log(audit_context(), GFP_KERNEL,
> -   AUDIT_FANOTIFY, "resp=%u", response);
> +   /* {subj,obj}_trust values are {0,1,2}: no,yes,unknown */
> +   if (friar->hdr.type == FAN_RESPONSE_INFO_NONE) {
> +   audit_log(audit_context(), GFP_KERNEL, AUDIT_FANOTIFY,
> + "resp=%u fan_type=%u fan_info=3F subj_trust=2 
> obj_trust=2",
> + response, FAN_RESPONSE_INFO_NONE);
> +   return;
> +   }
> +   audit_log(audit_context(), GFP_KERNEL, AUDIT_FANOTIFY,
> + "resp=%u fan_type=%u fan_info=%X subj_trust=%u 
> obj_trust=%u",
> + response, friar->hdr.type, friar->rule_number,
> + friar->subj_trust, friar->obj_trust);
>  }

The only thing that comes to mind might be to convert the if-return
into a switch statement to make it a bit cleaner and easier to patch
in the future, but that is s far removed from any real concern
that I debated even mentioning it.  I only bring it up in case the
"3F" discussion results in a respin, and even then I'm not going to
hold my ACK over something as silly as a if-return vs switch.

For clarity, this is what I was thinking:

void __audit_fanontify(...)
{
  switch (type) {
  case FAN_RESPONSE_INFO_NONE:
audit_log(...);
break;
  default:
audit_log(...);
  }
}

-- 
paul-moore.com

--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit



Re: [PATCH v6 3/3] fanotify,audit: Allow audit to use the full permission event response

2023-01-20 Thread Paul Moore
On Wed, Jan 18, 2023 at 1:34 PM Steve Grubb  wrote:
>
> Hello Richard,
>
> I built a new kernel and tested this with old and new user space. It is
> working as advertised. The only thing I'm wondering about is why we have 3F
> as the default value when no additional info was sent? Would it be better to
> just make it 0?

...

> On Tuesday, January 17, 2023 4:14:07 PM EST Richard Guy Briggs wrote:
> > diff --git a/kernel/auditsc.c b/kernel/auditsc.c
> > index d1fb821de104..3133c4175c15 100644
> > --- a/kernel/auditsc.c
> > +++ b/kernel/auditsc.c
> > @@ -2877,10 +2878,19 @@ void __audit_log_kern_module(char *name)
> >   context->type = AUDIT_KERN_MODULE;
> >  }
> >
> > -void __audit_fanotify(u32 response)
> > +void __audit_fanotify(u32 response, struct
> > fanotify_response_info_audit_rule *friar) {
> > - audit_log(audit_context(), GFP_KERNEL,
> > - AUDIT_FANOTIFY, "resp=%u", response);
> > + /* {subj,obj}_trust values are {0,1,2}: no,yes,unknown */
> > + if (friar->hdr.type == FAN_RESPONSE_INFO_NONE) {
> > + audit_log(audit_context(), GFP_KERNEL, AUDIT_FANOTIFY,
> > +   "resp=%u fan_type=%u fan_info=3F subj_trust=2
> obj_trust=2",
> > +   response, FAN_RESPONSE_INFO_NONE);
> > + return;
> > + }

(I'm working under the assumption that the "fan_info=3F" in the record
above is what Steve was referring to in his comment.)

I vaguely recall Richard commenting on this in the past, although
maybe not ... my thought is that the "3F" is simply the hex encoded
"?" character in ASCII ('man 7 ascii' is your friend).  I suppose the
question is what to do in the FAN_RESPONSE_INFO_NONE case.

Historically when we had a missing field we would follow the "field=?"
pattern, but I don't recall doing that for a field which was
potentially hex encoded, is there an existing case where we use "?"
for a field that is hex encoded?  If so, we can swap out the "3F" for
a more obvious "?".

However, another option might be to simply output the current
AUDIT_FANOTIFY record format in the FAN_RESPONSE_INFO_NONE case, e.g.
only "resp=%u".  This is a little against the usual guidance of
"fields should not disappear from a record", but considering that
userspace will always need to support the original resp-only format
for compatibility reasons this may be an option.

--
paul-moore.com

--
Linux-audit mailing list
Linux-audit@redhat.com
https://listman.redhat.com/mailman/listinfo/linux-audit