From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id BD853940FD9 for ; Thu, 1 Feb 2024 03:05:27 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=9r+yUOCUbqMH0pyzS+IvmZZ8u6S1Zype9OSRlB7S22c=; c=relaxed/simple; d=groups.io; h=Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References:From:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Type; s=20140610; t=1706756726; v=1; b=DWxuQreGIakA7p05qBpuTZBW4tjlybF78MPTQiSaJqlGGGjm6EStmwrPZrkkmabHLxRbGsz+ qpDdSv3UrCAeCLrLSjGVIlt50iynxAP72lt8JauXv8AuOwjarM6lPVc5NsOdFAksZtjAnGX28lu Hf6wj3sPD9OomShEyd+AIJA0= X-Received: by 127.0.0.2 with SMTP id T8vwYY7687511xf7OTNOuCEP; Wed, 31 Jan 2024 19:05:26 -0800 X-Received: from mail.loongson.cn (mail.loongson.cn [114.242.206.163]) by mx.groups.io with SMTP id smtpd.web11.7240.1706756724316432343 for ; Wed, 31 Jan 2024 19:05:24 -0800 X-Received: from loongson.cn (unknown [10.40.24.149]) by gateway (Coremail) with SMTP id _____8AxOOhsCrtlp1IJAA--.8084S3; Thu, 01 Feb 2024 11:05:16 +0800 (CST) X-Received: from [10.40.24.149] (unknown [10.40.24.149]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxRMxoCrtl0T4rAA--.26867S3; Thu, 01 Feb 2024 11:05:12 +0800 (CST) Message-ID: Date: Thu, 1 Feb 2024 11:05:12 +0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [edk2-devel] [PATCH v8 14/37] UefiCpuPkg: Add CpuMmuLib to UefiCpuPkg To: devel@edk2.groups.io, pedro.falcato@gmail.com, Laszlo Ersek Cc: Eric Dong , Ray Ni , Rahul Kumar , Gerd Hoffmann , Baoqi Zhang , Dongyan Qian , Xianglai Li , Bibo Mao References: <20240126062715.3099433-1-lichao@loongson.cn> <20240126062919.3101691-1-lichao@loongson.cn> <3fe0fda8-d32e-679e-2f71-6cc35e7772b8@redhat.com> From: "Chao Li" In-Reply-To: X-CM-TRANSID: AQAAf8AxRMxoCrtl0T4rAA--.26867S3 X-CM-SenderInfo: xolfxt3r6o00pqjv00gofq/1tbiAQAOCGW6BOEGkQABsr X-Coremail-Antispam: 1Uk129KBj93XoWxuF4fJFWUAr4rZF13Gw13Jrc_yoW5Kr1UpF Z5Cw4vkFnrJr18Xrn3Zr4xZr129ws3urZrJFZ5KrW8Cw1qg340kr42v34agF1UArsakay8 XrWYgryqgFn8A3gCm3ZEXasCq-sJn29KB7ZKAUJUUUU5529EdanIXcx71UUUUU7KY7ZEXa sCq-sGcSsGvfJ3UbIjqfuFe4nvWSU5nxnvy29KBjDU0xBIdaVrnRJUUUkCb4IE77IF4wAF F20E14v26r1j6r4UM7CY07I20VC2zVCF04k26cxKx2IYs7xG6rWj6s0DM7CIcVAFz4kK6r 1j6r18M28lY4IEw2IIxxk0rwA2F7IY1VAKz4vEj48ve4kI8wA2z4x0Y4vE2Ix0cI8IcVAF wI0_JFI_Gr1l84ACjcxK6xIIjxv20xvEc7CjxVAFwI0_Jr0_Gr1l84ACjcxK6I8E87Iv67 AKxVWxJVW8Jr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4j6r4UJwAS0I0E0xvYzxvE52x0 82IY62kv0487Mc804VCY07AIYIkI8VC2zVCFFI0UMcIj6xIIjxv20xvE14v26r106r15Mc Ij6I8E87Iv67AKxVWUJVW8JwAm72CE4IkC6x0Yz7v_Jr0_Gr1lF7xvr2IY64vIr41l7480 Y4vEI4kI2Ix0rVAqx4xJMxkF7I0En4kS14v26r126r1DMxAIw28IcxkI7VAKI48JMxC20s 026xCaFVCjc4AY6r1j6r4UMI8I3I0E5I8CrVAFwI0_JrI_JrWlx2IqxVCjr7xvwVAFwI0_ JrI_JrWlx4CE17CEb7AF67AKxVWUtVW8ZwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14 v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4v20xva j40_Jr0_JF4lIxAIcVC2z280aVAFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVWUJV W8JbIYCTnIWIevJa73UjIFyTuYvjxUo2-eUUUUU Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,lichao@loongson.cn List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: 2UZy2JMZG8aKucqWEWarILC6x7686176AA= Content-Type: multipart/alternative; boundary="------------kZdbGbwLhzhse2S5u62E6T0I" X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=DWxuQreG; dmarc=none; spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io --------------kZdbGbwLhzhse2S5u62E6T0I Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit 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 wrote: >> Hi Pedro, >> >> On 1/31/24 11:33, Pedro Falcato wrote: >>> On Fri, Jan 26, 2024 at 6:29 AM Chao Li 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.
>>>> + >>>> + 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): https://edk2.groups.io/g/devel/message/114928 Mute This Topic: https://groups.io/mt/103971653/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=- --------------kZdbGbwLhzhse2S5u62E6T0I Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

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]

_._,_._,_
--------------kZdbGbwLhzhse2S5u62E6T0I--