linux-riscv.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [RFC patch 0/4] riscv: introduce alternative mechanism to apply errata patches
@ 2021-03-08  3:58 Vincent Chen
  2021-03-08  3:58 ` [RFC patch 1/4] riscv: Add 3 SBI wrapper functions to get cpu manufacturer information Vincent Chen
                   ` (4 more replies)
  0 siblings, 5 replies; 28+ messages in thread
From: Vincent Chen @ 2021-03-08  3:58 UTC (permalink / raw)
  To: linux-riscv, palmer
  Cc: Frank.Zhao, atish.patra, anup.patel, guoren, alankao,
	paul.walmsley, Vincent Chen

With the emergence of more and more RISC-V CPUs, the request for how to
upstream the vendor errata patch may gradually appear. In order to resolve
this issue, this patch introduces the alternative mechanism from ARM64 and
x86 to enable the kernel to patch code at runtime according to the
manufacturer information of the running CPU. The main purpose of this patch
set is to propose a framework to apply vendor's errata solutions. Based on
this framework, it can be ensured that the errata only applies to the
specified CPU cores. Other CPU cores do not be affected. Therefore, some
complicated scenarios are unsupported in this patch set, such as patching
code to the kernel module, doing relocation in patching code, and
heterogeneous CPU topology.

In the "alternative" scheme, Users could use the macro ALTERNATIVE to apply
an errata to the existing code flow. In the macro ALTERNATIVE, users need
to specify the manufacturer information (vendor id, arch id, and implement
id) for this errata. Therefore, kernel will know this errata is suitable
for which CPU core. During the booting procedure, kernel will select the
errata required by the CPU core and then patch it. It means that the kernel
only applies the errata to the specified CPU core. In this case, the
vendor's errata does not affect each other at runtime. The above patching
procedure only occurs during the booting phase, so we only take the
overhead of the "alternative" mechanism once.

This "alternative" mechanism is enabled by default to ensure that all
required errata will be applied. However, users can disable this feature by
the Kconfig "CONFIG_RISCV_ERRATA_ALTERNATIVE".

The last patch is to apply the SiFive CIP-453 errata by this "alternative"
scheme. Therefore, It can be regarded as an example. According to the
results of running this image on the QEMU virt platform, kernel does not
apply this errata at run-time because the CPU manufacturer information
does not match the specified SiFive CPU core. Therefore, this errata does
not affect any CPU core except for the specified SiFive cores.

Vincent Chen (4):
  riscv: Add 3 SBI wrapper functions to get cpu manufacturer information
  riscv: Get CPU manufacturer information
  riscv: Introduce alternative mechanism to apply errata solution
  riscv: sifive: apply errata "cip-453" patch

 arch/riscv/Kconfig                          |   1 +
 arch/riscv/Kconfig.erratas                  |  32 ++++++++
 arch/riscv/Kconfig.socs                     |   1 +
 arch/riscv/Makefile                         |   1 +
 arch/riscv/errata/Makefile                  |   2 +
 arch/riscv/errata/alternative.c             |  69 +++++++++++++++++
 arch/riscv/errata/sifive/Makefile           |   2 +
 arch/riscv/errata/sifive/errata.c           |  56 ++++++++++++++
 arch/riscv/errata/sifive/errata_cip_453.S   |  34 +++++++++
 arch/riscv/include/asm/alternative-macros.h | 110 ++++++++++++++++++++++++++++
 arch/riscv/include/asm/alternative.h        |  44 +++++++++++
 arch/riscv/include/asm/asm.h                |   1 +
 arch/riscv/include/asm/csr.h                |   3 +
 arch/riscv/include/asm/errata_list.h        |   9 +++
 arch/riscv/include/asm/hwcap.h              |   6 ++
 arch/riscv/include/asm/processor.h          |   2 +
 arch/riscv/include/asm/sbi.h                |   3 +
 arch/riscv/include/asm/sections.h           |   2 +
 arch/riscv/include/asm/soc.h                |   1 +
 arch/riscv/include/asm/vendorid_list.h      |   6 ++
 arch/riscv/kernel/cpufeature.c              |  17 +++++
 arch/riscv/kernel/entry.S                   |  12 ++-
 arch/riscv/kernel/sbi.c                     |  15 ++++
 arch/riscv/kernel/setup.c                   |   2 +
 arch/riscv/kernel/smpboot.c                 |   4 +
 arch/riscv/kernel/soc.c                     |   1 +
 arch/riscv/kernel/vmlinux.lds.S             |  14 ++++
 27 files changed, 448 insertions(+), 2 deletions(-)
 create mode 100644 arch/riscv/Kconfig.erratas
 create mode 100644 arch/riscv/errata/Makefile
 create mode 100644 arch/riscv/errata/alternative.c
 create mode 100644 arch/riscv/errata/sifive/Makefile
 create mode 100644 arch/riscv/errata/sifive/errata.c
 create mode 100644 arch/riscv/errata/sifive/errata_cip_453.S
 create mode 100644 arch/riscv/include/asm/alternative-macros.h
 create mode 100644 arch/riscv/include/asm/alternative.h
 create mode 100644 arch/riscv/include/asm/errata_list.h
 create mode 100644 arch/riscv/include/asm/vendorid_list.h

-- 
2.7.4


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 28+ messages in thread
* Re: [RFC patch 0/4] riscv: introduce alternative mechanism to apply errata patches
@ 2021-03-11  3:47 Ruinland ChuanTzu Tsai
  2021-03-11 15:29 ` Vincent Chen
  0 siblings, 1 reply; 28+ messages in thread
From: Ruinland ChuanTzu Tsai @ 2021-03-11  3:47 UTC (permalink / raw)
  To: linux-riscv; +Cc: alankao, ruinland


> With the emergence of more and more RISC-V CPUs, the request for how to
> upstream the vendor errata patch may gradually appear. In order to resolve
> this issue, this patch introduces the alternative mechanism from ARM64 and
> x86 to enable the kernel to patch code at runtime according to the
> manufacturer information of the running CPU. The main purpose of this patch
> set is to propose a framework to apply vendor's errata solutions. Based on
> this framework, it can be ensured that the errata only applies to the
> specified CPU cores. Other CPU cores do not be affected. Therefore, some
> complicated scenarios are unsupported in this patch set, such as patching
> code to the kernel module, doing relocation in patching code, and
> heterogeneous CPU topology.
> 
> In the "alternative" scheme, Users could use the macro ALTERNATIVE to apply
> an errata to the existing code flow. In the macro ALTERNATIVE, users need

In general I love the idea of fixing errata dynamically, yet in the past,
vendors sometimes bump into the dilemma on the necessity of using alternative
framework or just plainly "ifdefine"-ing the CONFIG_ERRATUM_XXX to toggle their
fixups.

Quoting from the Qualcomm Falkor E1041 dicssusion threads [1][2] :

"Just do it with an #ifdef"

"There's really no need for this to be an alternative. It makes the kernel
larger and more complex due to all the altinstr data and probing code."

I wonder if there will be similar disputes end up here. And having a conclusion
on what should be resolved by alternative and what shouldn't might be more
complicated since we're having a more diversed group of vendors (or "users" who
can access the errata as you mentioned).

Cordially yours,
Ruinland

[1] https://lore.kernel.org/kvmarm/20171201112457.GE18083@arm.com/
[2] https://patchwork.kernel.org/project/linux-arm-kernel/patch/1512957823-18064-2-git-send-email-shankerd@codeaurora.org/#21249629

> to specify the manufacturer information (vendor id, arch id, and implement
> id) for this errata. Therefore, kernel will know this errata is suitable
> for which CPU core. During the booting procedure, kernel will select the
> errata required by the CPU core and then patch it. It means that the kernel
> only applies the errata to the specified CPU core. In this case, the
> vendor's errata does not affect each other at runtime. The above patching
> procedure only occurs during the booting phase, so we only take the
> overhead of the "alternative" mechanism once.
> 
> This "alternative" mechanism is enabled by default to ensure that all
> required errata will be applied. However, users can disable this feature by
> the Kconfig "CONFIG_RISCV_ERRATA_ALTERNATIVE".
> 
> The last patch is to apply the SiFive CIP-453 errata by this "alternative"
> scheme. Therefore, It can be regarded as an example. According to the
> results of running this image on the QEMU virt platform, kernel does not
> apply this errata at run-time because the CPU manufacturer information
> does not match the specified SiFive CPU core. Therefore, this errata does
> not affect any CPU core except for the specified SiFive cores.


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2021-03-15  8:29 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-08  3:58 [RFC patch 0/4] riscv: introduce alternative mechanism to apply errata patches Vincent Chen
2021-03-08  3:58 ` [RFC patch 1/4] riscv: Add 3 SBI wrapper functions to get cpu manufacturer information Vincent Chen
2021-03-10  4:39   ` Palmer Dabbelt
2021-03-11  5:21     ` Vincent Chen
2021-03-08  3:58 ` [RFC patch 2/4] riscv: Get CPU " Vincent Chen
2021-03-08 23:30   ` Damien Le Moal
2021-03-09  1:23     ` Sean Anderson
2021-03-09  1:24     ` Vincent Chen
2021-03-09  1:59       ` Damien Le Moal
2021-03-09  1:28   ` Guo Ren
2021-03-09  1:46     ` Vincent Chen
2021-03-09  5:11     ` Anup Patel
2021-03-10  2:50       ` Guo Ren
2021-03-10  3:40       ` Palmer Dabbelt
2021-03-10  3:56         ` Guo Ren
2021-03-10  4:39   ` Palmer Dabbelt
2021-03-08  3:58 ` [RFC patch 3/4] riscv: Introduce alternative mechanism to apply errata solution Vincent Chen
2021-03-10  4:39   ` Palmer Dabbelt
2021-03-12  3:40     ` Vincent Chen
2021-03-08  3:58 ` [RFC patch 4/4] riscv: sifive: apply errata "cip-453" patch Vincent Chen
2021-03-10  4:39   ` Palmer Dabbelt
2021-03-12  3:50     ` Vincent Chen
2021-03-10  4:39 ` [RFC patch 0/4] riscv: introduce alternative mechanism to apply errata patches Palmer Dabbelt
2021-03-11  7:09   ` Vincent Chen
2021-03-11  3:47 Ruinland ChuanTzu Tsai
2021-03-11 15:29 ` Vincent Chen
2021-03-15  4:42   ` Ruinland ChuanTzu Tsai
2021-03-15  8:29     ` Vincent Chen

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).