Hi Pedro and Laszlo,

Part of the code in this patch is indeed quoted from the Linux kernel, and do you think it is inapproparate? If so, we need to refactor this module, what are you suggests with the refactoring? Just remove the unused logic from the Kernel code and keep the logic good or refactor from scratch?


Thanks,
Chao
On 2024/2/1 01:46, Pedro Falcato wrote:
On Wed, Jan 31, 2024 at 1:41 PM Laszlo Ersek <lersek@redhat.com> wrote:
Hi Pedro,

On 1/31/24 11:33, Pedro Falcato wrote:
On Fri, Jan 26, 2024 at 6:29 AM Chao Li <lichao@loongson.cn> wrote:
Add a new library named CpuMmuLib and add a LoongArch64 instance with in
the library.
It provides two-stage MMU libraryinstances, PEI and DXE.

BZ: https://bugzilla.tianocore.org/show_bug.cgi?id=4584
[...]
diff --git a/UefiCpuPkg/Library/CpuMmuLib/LoongArch64/CommonMmuLib.c b/UefiCpuPkg/Library/CpuMmuLib/LoongArch64/CommonMmuLib.c
new file mode 100644
index 0000000000..2e852c3371
--- /dev/null
+++ b/UefiCpuPkg/Library/CpuMmuLib/LoongArch64/CommonMmuLib.c
@@ -0,0 +1,988 @@
+/** @file
+
+  CPU Memory Map Unit Handler Library common functions.
+
+  Copyright (c) 2024 Loongson Technology Corporation Limited. All rights reserved.<BR>
+
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+  @par Glossary:
+    - Pgd or Pgd or PGD    - Page Global Directory
+    - Pud or Pud or PUD    - Page Upper Directory
+    - Pmd or Pmd or PMD    - Page Middle Directory
+    - Pte or pte or PTE    - Page Table Entry
+    - Val or VAL or val    - Value
+    - Dir    - Directory
+**/
You took essentially Linux code [...] and EDK2-ify'd it. Congrats,
this is cursed.
are you saying this patch is effectively a port of GPL'd Linux code
(potentially *old* code, but still), with the GPL simply replaced with
BSD-2-Clause-Patent?
Yes. With a bit of patience, you can get a good idea of the
similarities by kernel-ifying identifiers and searching them on
https://elixir.bootlin.com/linux/latest/source.
The smoking gun being the types and strategy used for the MMU code
(PGD, P4D, PUD, PMD, PTE and VAL/PTEVAL being a very unique linux
strategy that is not emulated elsewhere AFAIK) and SWAP_PAGE_DIR (->
swapper_pg_dir, the kernel's pgd; swap has no meaning whatsoever in
UEFI land).

That sounds... shocking. If such a patch were merged into edk2, it would
violate both the GPL (the GPL cannot just be "relaxed") and the edk2
rules (edk2 does not want GPL code).

The only exception would be if Loongson Technology Corporation Limited
were the Copyright holder of the Linux code, and this patch were a
relicensing. But then that too would have to be documented, IMO.
FWIW, I wasn't objecting to the patch on legal grounds, but mainly
technical ones, since I was assuming Loongson had written most of this
code.
However (arch/loongarch/include/asm/pgtable.h):
/* SPDX-License-Identifier: GPL-2.0 */
/*
 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
 *
 * Derived from MIPS:
 * Copyright (C) 1994, 95, 96, 97, 98, 99, 2000, 2003 Ralf Baechle
 * Copyright (C) 1999, 2000, 2001 Silicon Graphics, Inc.
 */

and after a closer look, other functions such as P*AllocGet()
mirroring p4d_alloc, pud_alloc and pmd_alloc (from include/linux/mm.h,
definitely not loongson's copyright) very closely, it seems like this
patch is a walking copyright violation.
Not that implementing something similar to Linux's is impossible in a
clean-room instance, but the code used and the patterns used imitate
Linux's down to a t.

_._,_._,_

Groups.io Links:

You receive all messages sent to this group.

View/Reply Online (#114928) | | Mute This Topic | New Topic
Your Subscription | Contact Group Owner | Unsubscribe [rebecca@openfw.io]

_._,_._,_