Re: [PATCH] drm/radeon: add late_register for connector
Le 06/10/2024 à 18:56, Christian Zigotzky a écrit : On 03 October 2024 at 08:06 am, Wu Hoi Pok wrote: This is a fix patch not tested yet, for a bug I introduce in previous rework of radeon driver. The bug is a null dereference in 'aux.dev', which is the 'device' not registered, resulting in kernel panic. By having 'late_register', the connector should be registered after 'drm_dev_register' automatically. Please help testing thank you. Hello Wu Hoi Pok, Thanks a lot for your patch. Unfortunately there is a new issue after patching the RC1. Could you please fix the following issue? Thanks, Christian --- Linux fienix 6.12.0-rc1-2-powerpc64-smp #1 SMP Fri Oct 4 08:55:45 CEST 2024 ppc64 GNU/Linux [ 29.167145] systemd[1]: Sent message type=signal sender=n/a destination=n/a path=/org/freedesktop/systemd1/unit/NetworkManager_2eservice interface=org.freedesktop.DBus.Properties member=PropertiesChanged cookie=103 reply_cookie=0 signature=sa{sv}as error-name=n/a error-message=n/a [ 29.542140] systemd-journald[1301]: Successfully sent stream file descriptor to service manager. [ 29.561863] BUG: Kernel NULL pointer dereference on read at 0x [ 29.567156] Faulting instruction address: 0xc0c973c0 [ 29.571574] cpu 0x1: Vector: 300 (Data Access) at [c6f97640] [ 29.576637] pc: c0c973c0: .drm_gem_object_free+0x20/0x70 [ 29.581708] lr: c0d28dd8: .radeon_bo_unref+0x58/0x90 [ 29.586428] sp: c6f978e0 [ 29.588695] msr: 90009032 [ 29.590962] dar: 0 [ 29.591925] dsisr: 4000 [ 29.593496] current = 0xc85b1f00 [ 29.596286] paca = 0xc0003680 irqmask: 0x03 irq_happened: 0x01 [ 29.602119] pid = 1524, comm = Xorg.wrap [ 29.605257] Linux version 6.12.0-rc1-2-powerpc64-smp (geeko@buildhost) (powerpc64-suse-linux-gcc (SUSE Linux) 7.5.0, GNU ld (GNU Binutils; devel:gcc / SLE-15) 2.43.1.20240828-150300.536) #1 SMP Fri Oct 4 08:55:45 CEST 2024 [ 29.623892] enter ? for help [ 29.625487] [c6f97960] c0d28dd8 .radeon_bo_unref+0x58/0x90 [ 29.631083] [c6f979e0] c0e287b0 .radeon_vm_fini+0x260/0x330 [ 29.636765] [c6f97aa0] c0d07c94 .radeon_driver_postclose_kms+0x1a4/0x1f0 [ 29.643579] [c6f97b30] c0c9374c .drm_file_free+0x28c/0x300 [ 29.649174] [c6f97be0] c0c93900 .drm_release+0x90/0x170 [ 29.654508] [c6f97c70] c0304790 .__fput+0x120/0x3b0 [ 29.659495] [c6f97d10] c02fe0fc .__se_sys_close+0x4c/0xc0 [ 29.665004] [c6f97d90] c0025bac .system_call_exception+0x22c/0x260 [ 29.671295] [c6f97e10] c000b554 system_call_common+0xf4/0x258 [ 29.677164] --- Exception: c00 (System Call) at 006b2b48 [ 29.681876] SP (fff4b3d0) is in userspace [ 29.684577] 1:mon> [ 31.666727] Oops: Kernel access of bad area, sig: 11 [#1] [ 31.670829] BE PAGE_SIZE=4K MMU=Hash SMP NR_CPUS=2 A-EON Amigaone X1000 [ 31.676144] Modules linked in: snd_hda_codec_idt snd_hda_codec_generic snd_hda_codec_hdmi snd_hda_intel snd_intel_dspcfg snd_hda_codec snd_hda_core dm_mod [ 31.688703] CPU: 1 UID: 0 PID: 1524 Comm: Xorg.wrap Not tainted 6.12.0-rc1-2-powerpc64-smp #1 [ 31.695932] Hardware name: pasemi,nemo PA6T 0x900102 A-EON Amigaone X1000 [ 31.701417] NIP: c0c973c0 LR: c0d28dd8 CTR: c0d07af0 [ 31.707250] REGS: c6f97640 TRAP: 0300 Not tainted (6.12.0-rc1-2-powerpc64-smp) [ 31.714128] MSR: 90009032 CR: 2800 XER: 2000 [ 31.720773] DAR: DSISR: 4000 IRQMASK: 0 GPR00: c0d28dd8 c6f978e0 c207a800 c85f5468 GPR04: 0b9b 0b9a 000179779000 c86a4b00 GPR08: 0001 GPR12: 48002202 c0003680 GPR16: 006e3318 0001 006e289c 0063 GPR20: c04064a0 007f0088 fff4c734 007d165c GPR24: 007d1668 c00024b6a220 c3588000 c00024b6a200 GPR28: c3b3cc00 c00024b6a248 c2d48820 c85f5468 [ 31.778903] NIP [c0c973c0] .drm_gem_object_free+0x20/0x70 [ 31.783701] LR [c0d28dd8] .radeon_bo_unref+0x58/0x90 [ 31.788062] Call Trace: [ 31.789199] [c6f978e0] [c6f97990] 0xc6f97990 (unreliable) [ 31.795388] [c6f97960] [c0d28dd8] .radeon_bo_unref+0x58/0x90 [ 31.801142] [c6f979e0] [c0e287b0] .radeon_vm_fini+0x260/0x330 [ 31.806982] [c6f97aa0] [c0d07c94] .radeon_driver_postclose_kms+0x1a4/0x1f0 [ 31.813954] [c6f97b30] [c0c9374c] .drm_file_free+0x28c
[PATCH] powerpc/8xx: Fix kernel DTLB miss on dcbz
Following OOPS is encountered while loading test_bpf module on powerpc 8xx: [ 218.835567] BUG: Unable to handle kernel data access on write at 0xcb00 [ 218.842473] Faulting instruction address: 0xc0017a80 [ 218.847451] Oops: Kernel access of bad area, sig: 11 [#1] [ 218.852854] BE PAGE_SIZE=16K PREEMPT CMPC885 [ 218.857207] SAF3000 DIE NOTIFICATION [ 218.860713] Modules linked in: test_bpf(+) test_module [ 218.865867] CPU: 0 UID: 0 PID: 527 Comm: insmod Not tainted 6.11.0-s3k-dev-09856-g3de3d71ae2e6-dirty #1280 [ 218.875546] Hardware name: MIAE 8xx 0x50 CMPC885 [ 218.880521] NIP: c0017a80 LR: beab859c CTR: 000101d4 [ 218.885584] REGS: cac2bc90 TRAP: 0300 Not tainted (6.11.0-s3k-dev-09856-g3de3d71ae2e6-dirty) [ 218.894308] MSR: 9032 CR: 5500 XER: a0007100 [ 218.901290] DAR: cb00 DSISR: c200 [ 218.901290] GPR00: 000185d1 cac2bd50 c21b9580 caf7c030 c3883fcc 0008 cafc [ 218.901290] GPR08: 0004 1830 2000 0004 9900 100d815e ca669d08 0369 [ 218.901290] GPR16: ca73 ca2c004c 035d 0311 0369 [ 218.901290] GPR24: ca732240 0001 00030ba3 c380 00185d48 caf7c000 ca2c004c [ 218.941087] NIP [c0017a80] memcpy+0x88/0xec [ 218.945277] LR [beab859c] test_bpf_init+0x22c/0x3c90 [test_bpf] [ 218.951476] Call Trace: [ 218.953916] [cac2bd50] [beab8570] test_bpf_init+0x200/0x3c90 [test_bpf] (unreliable) [ 218.962034] [cac2bde0] [c0004c04] do_one_initcall+0x4c/0x1fc [ 218.967706] [cac2be40] [c00a2ec4] do_init_module+0x68/0x360 [ 218.973292] [cac2be60] [c00a5194] init_module_from_file+0x8c/0xc0 [ 218.979401] [cac2bed0] [c00a5568] sys_finit_module+0x250/0x3f0 [ 218.985248] [cac2bf20] [c000e390] system_call_exception+0x8c/0x15c [ 218.991444] [cac2bf30] [c00120a8] ret_from_syscall+0x0/0x28 This happens in the main loop of memcpy() ==> c0017a80: 7c 0b 37 ec dcbzr11,r6 c0017a84: 80 e4 00 04 lwz r7,4(r4) c0017a88: 81 04 00 08 lwz r8,8(r4) c0017a8c: 81 24 00 0c lwz r9,12(r4) c0017a90: 85 44 00 10 lwzur10,16(r4) c0017a94: 90 e6 00 04 stw r7,4(r6) c0017a98: 91 06 00 08 stw r8,8(r6) c0017a9c: 91 26 00 0c stw r9,12(r6) c0017aa0: 95 46 00 10 stwur10,16(r6) c0017aa4: 42 00 ff dc bdnzc0017a80 Commit ac9f97ff8b32 ("powerpc/8xx: Inconditionally use task PGDIR in DTLB misses") relies on re-reading DAR register to know if an error is due to a missing copy of a PMD entry in task's PGDIR, allthough DAR was already read in the exception prolog and copied into thread struct. This is because is it done very early in the exception and there are not enough registers available to keep a pointer to thread struct. However, dcbz instruction is buggy and doesn't update DAR register on fault. That is detected and generates a call to FixupDAR workaround which updates DAR copy in thread struct but doesn't fix DAR register. Let's fix DAR in addition to the update of DAR copy in thread struct. Fixes: ac9f97ff8b32 ("powerpc/8xx: Inconditionally use task PGDIR in DTLB misses") Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/head_8xx.S | 1 + 1 file changed, 1 insertion(+) diff --git a/arch/powerpc/kernel/head_8xx.S b/arch/powerpc/kernel/head_8xx.S index 8120273c7249..78942fd6b4b9 100644 --- a/arch/powerpc/kernel/head_8xx.S +++ b/arch/powerpc/kernel/head_8xx.S @@ -495,6 +495,7 @@ FixupDAR:/* Entry point for dcbx workaround. */ bctr/* jump into table */ 152: mfdar r11 + mtdar r10 mtctr r11 /* restore ctr reg from DAR */ mfspr r11, SPRN_SPRG_THREAD stw r10, DAR(r11) -- 2.44.0
Re: [PATCH v2 1/2] powerpc/pseries: Do not pass an error pointer to of_node_put() in pSeries_reconfig_add_node()
Le 03/10/2024 à 19:05, Markus Elfring a écrit : Date: Tue, 21 Mar 2023 10:30:23 +0100 It can be determined in the implementation of the function “pSeries_reconfig_add_node” that an error code would occasionally be provided by a call of a function like pseries_of_derive_parent(). This error indication was passed to an of_node_put() call according to an attempt for exception handling so far. … I was notified also about the following adjustment. … * linuxppc-dev: [resent,v2,1/2] powerpc/pseries: Do not pass an error pointer to of_node_put() in pSeries_reconfig_add_node() - https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpatchwork.ozlabs.org%2Fproject%2Flinuxppc-dev%2Fpatch%2Ff5ac19db-c7d5-9a94-aa37-9bb448fe665f%40web.de%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7Cab19d1c85de343f5474908dce3cd8c02%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638635719164841772%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=8b7APXbglDf13PvZ4nVh5Z92bEft2RBqU3LfKsUETOI%3D&reserved=0 - for: Linux PPC development was: New now: Changes Requested … It seems that I can not see so far why this status update happened for any reasons. Will further clarifications become helpful here? Sorry I forgot to send the email. It is the same kind of problem as the other series: Message IDs and/or In-Reply-To headers are messed up and b4 ends up applying an unrelated patch instead of applying the series as you can see below: $ b4 shazam f5ac19db-c7d5-9a94-aa37-9bb448fe6...@web.de Grabbing thread from lore.kernel.org/all/f5ac19db-c7d5-9a94-aa37-9bb448fe6...@web.de/t.mbox.gz Checking for newer revisions Grabbing search results from lore.kernel.org Analyzing 128 messages in the thread WARNING: duplicate messages found at index 1 Subject 1: powerpc/pseries: Do not pass an error pointer to of_node_put() in pSeries_reconfig_add_node() Subject 2: powerpc/pseries: Do not pass an error pointer to of_node_put() in pSeries_reconfig_add_node() 2 is not a reply... assume additional patch WARNING: duplicate messages found at index 2 Subject 1: powerpc/pseries: Fix exception handling in pSeries_reconfig_add_node() Subject 2: powerpc/pseries: Do not pass an error pointer to of_node_put() in pSeries_reconfig_add_node() 2 is not a reply... assume additional patch Assuming new revision: v3 ([PATCH] ipvs: Fix exception handling in two functions) Assuming new revision: v4 ([PATCH] selftests: cgroup: Fix exception handling in test_memcg_oom_group_score_events()) Assuming new revision: v5 ([Nouveau] [PATCH] drm/nouveau: Add a jump label in nouveau_gem_ioctl_pushbuf()) Assuming new revision: v6 ([PATCH] mm/mempolicy: Fix exception handling in shared_policy_replace()) Assuming new revision: v7 ([PATCH] firmware: ti_sci: Fix exception handling in ti_sci_probe()) Assuming new revision: v8 ([PATCH] remoteproc: imx_dsp_rproc: Improve exception handling in imx_dsp_rproc_mbox_alloc()) Assuming new revision: v9 ([PATCH] spi: atmel: Improve exception handling in atmel_spi_configure_dma()) Assuming new revision: v10 ([cocci] [PATCH] btrfs: Fix exception handling in relocating_repair_kthread()) Assuming new revision: v11 ([cocci] [PATCH] ufs: Fix exception handling in ufs_fill_super()) Assuming new revision: v12 ([cocci] [PATCH] perf cputopo: Improve exception handling in build_cpu_topology()) Assuming new revision: v13 ([cocci] [PATCH] perf pmu: Improve exception handling in pmu_lookup()) Assuming new revision: v14 ([cocci] [PATCH] selftests/bpf: Improve exception handling in rbtree_add_and_remove()) Assuming new revision: v15 ([cocci] [PATCH resent] btrfs: Fix exception handling in relocating_repair_kthread()) Assuming new revision: v16 ([cocci] [PATCH resent] ufs: Fix exception handling in ufs_fill_super()) Assuming new revision: v17 ([cocci] [PATCH resent] perf cputopo: Improve exception handling in build_cpu_topology()) WARNING: duplicate messages found at index 1 Subject 1: scsi: message: fusion: Return directly after input data validation failed in four functions Subject 2: powerpc/pseries: Fix exception handling in pSeries_reconfig_add_node() 2 is a reply... replacing existing: powerpc/pseries: Fix exception handling in pSeries_reconfig_add_node() WARNING: duplicate messages found at index 1 Subject 1: md/raid1: Fix exception handling in setup_conf() Subject 2: scsi: message: fusion: Return directly after input data validation failed in four functions 2 is not a reply... assume additional patch WARNING: duplicate messages found at index 2 Subject 1: md/raid10: Fix exception handling in setup_conf() Subject 2: scsi: message: fusion: Return directly after input data validation failed in four functions 2 is not a reply... assume additional patch WARNING: duplicate messages found at index 1 Subject 1: irqchip/gic-v4: Fix exception handling in its_alloc_vcpu_irqs() Subject 2:
Re: [PATCH v2 1/4] powerpc/4xx: Fix exception handling in ppc4xx_pciex_port_setup_hose()
Le 03/10/2024 à 17:47, Markus Elfring a écrit : … Looks like you have messed up your patches, There were special communication settings involved which hindered desirable data processing for known information systems. Don't know what you mean. there is no much we can do it seems: $ b4 shazam e68a714b-32f2-de9f-066e-99a3f51a2...@web.de Please take another look also at published information according to further mailing list archive interfaces. Another look to what ? It seems like several patches were posted with the same Message-Id and/or with an unrelated In-Reply-To: b4 is lost and cannot apply your series, it applies the patch at https://lore.kernel.org/all/82aebf6c-47ac-9d17-2d11-6245f5823...@web.de/ You may consider fixing and resending the series as an independant series. Christophe
Re: [PATCH v1] ps3: Correct some typos in comments
Le 30/09/2024 à 04:32, Shen Lichuan a écrit : [Vous ne recevez pas souvent de courriers de shenlich...@vivo.com. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ] Fixed some confusing typos that were currently identified with codespell, the details are as follows: What is confusing in those typos ? Sure they are typos but I can't see any confusing meaning behind. There is no ambiguity. I would agree if for instance you had "live" instead of "leave", but here I can't see any alternative meaning. -in the code comments: drivers/ps3/ps3-lpm.c:94: rigths ==> rights drivers/ps3/ps3-sys-manager.c:365: acnowledge ==> acknowledge drivers/ps3/ps3-vuart.c:470: remaning ==> remaining drivers/ps3/ps3-vuart.c:471: transmision ==> transmission drivers/ps3/sys-manager-core.c:15: Staticly ==> Statically Signed-off-by: Shen Lichuan --- drivers/ps3/ps3-lpm.c | 2 +- drivers/ps3/ps3-sys-manager.c | 2 +- drivers/ps3/ps3-vuart.c| 4 ++-- drivers/ps3/sys-manager-core.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/ps3/ps3-lpm.c b/drivers/ps3/ps3-lpm.c index 200ad8751860..188ae2572674 100644 --- a/drivers/ps3/ps3-lpm.c +++ b/drivers/ps3/ps3-lpm.c @@ -91,7 +91,7 @@ struct ps3_lpm_shadow_regs { * struct ps3_lpm_priv - Private lpm device data. * * @open: An atomic variable indicating the lpm driver has been opened. - * @rights: The lpm rigths granted by the system policy module. A logical + * @rights: The lpm rights granted by the system policy module. A logical * OR of enum ps3_lpm_rights. * @node_id: The node id of a BE processor whose performance monitor this * lpar has the right to use. diff --git a/drivers/ps3/ps3-sys-manager.c b/drivers/ps3/ps3-sys-manager.c index ad8ef59dea34..ab798b52910e 100644 --- a/drivers/ps3/ps3-sys-manager.c +++ b/drivers/ps3/ps3-sys-manager.c @@ -362,7 +362,7 @@ static int ps3_sys_manager_send_request_shutdown( * ps3_sys_manager_send_response - Send a 'response' to the system manager. * @status: zero = success, others fail. * - * The guest sends this message to the system manager to acnowledge success or + * The guest sends this message to the system manager to acknowledge success or * failure of a command sent by the system manager. */ diff --git a/drivers/ps3/ps3-vuart.c b/drivers/ps3/ps3-vuart.c index 6328abd51ffa..5cb92535a4a1 100644 --- a/drivers/ps3/ps3-vuart.c +++ b/drivers/ps3/ps3-vuart.c @@ -467,8 +467,8 @@ struct list_buffer { * * If the port is idle on entry as much of the incoming data is written to * the port as the port will accept. Otherwise a list buffer is created - * and any remaning incoming data is copied to that buffer. The buffer is - * then enqueued for transmision via the transmit interrupt. + * and any remaining incoming data is copied to that buffer. The buffer is + * then enqueued for transmission via the transmit interrupt. */ int ps3_vuart_write(struct ps3_system_bus_device *dev, const void *buf, diff --git a/drivers/ps3/sys-manager-core.c b/drivers/ps3/sys-manager-core.c index e061b7d0632b..f50032ad9702 100644 --- a/drivers/ps3/sys-manager-core.c +++ b/drivers/ps3/sys-manager-core.c @@ -12,7 +12,7 @@ #include /** - * Staticly linked routines that allow late binding of a loaded sys-manager + * Statically linked routines that allow late binding of a loaded sys-manager * module. */ -- 2.17.1
Re: [PATCH v2 1/4] powerpc/4xx: Fix exception handling in ppc4xx_pciex_port_setup_hose()
Le 25/03/2023 à 16:36, Markus Elfring a écrit : Date: Thu, 16 Mar 2023 19:00:57 +0100 The label “fail” was used to jump to another pointer check despite of the detail in the implementation of the function “ppc4xx_pciex_port_setup_hose” that it was determined already that the corresponding variable contained a null pointer (because of a failed function call in three cases). 1. Thus return directly after a call of the function “pcibios_alloc_controller” failed. 2. Use more appropriate labels instead. 3. Reorder jump targets at the end. 4. Delete two questionable checks. This issue was detected by using the Coccinelle software. Fixes: a2d2e1ec07a80946cbe812dc8c73291cad8214b2 ("[POWERPC] 4xx: PLB to PCI Express support") Fixes: 80daac3f86d4f5aafc9d3e79addb90fa118244e2 ("[POWERPC] 4xx: Add endpoint support to 4xx PCIe driver") Signed-off-by: Markus Elfring Looks like you have messed up your patches, there is no much we can do it seems: $ b4 shazam e68a714b-32f2-de9f-066e-99a3f51a2...@web.de $ LANG= b4 --no-stdin shazam e68a714b-32f2-de9f-066e-99a3f51a2...@web.de Grabbing thread from lore.kernel.org/all/e68a714b-32f2-de9f-066e-99a3f51a2...@web.de/t.mbox.gz Checking for newer revisions Grabbing search results from lore.kernel.org Analyzing 123 messages in the thread WARNING: duplicate messages found at index 1 Subject 1: btrfs: Fix exception handling in relocating_repair_kthread() Subject 2: powerpc/4xx: Fix exception handling in ppc4xx_pciex_port_setup_hose() 2 is not a reply... assume additional patch Assuming new revision: v3 ([cocci] [PATCH] ufs: Fix exception handling in ufs_fill_super()) Assuming new revision: v4 ([cocci] [PATCH] perf cputopo: Improve exception handling in build_cpu_topology()) Assuming new revision: v5 ([cocci] [PATCH] perf pmu: Improve exception handling in pmu_lookup()) Assuming new revision: v6 ([cocci] [PATCH] selftests/bpf: Improve exception handling in rbtree_add_and_remove()) Assuming new revision: v7 ([cocci] [PATCH resent] btrfs: Fix exception handling in relocating_repair_kthread()) Assuming new revision: v8 ([cocci] [PATCH resent] ufs: Fix exception handling in ufs_fill_super()) Assuming new revision: v9 ([cocci] [PATCH resent] perf cputopo: Improve exception handling in build_cpu_topology()) WARNING: duplicate messages found at index 1 Subject 1: scsi: message: fusion: Return directly after input data validation failed in four functions Subject 2: btrfs: Fix exception handling in relocating_repair_kthread() 2 is a reply... replacing existing: btrfs: Fix exception handling in relocating_repair_kthread() WARNING: duplicate messages found at index 2 Subject 1: scsi: message: fusion: Delete a redundant pointer check in four functions Subject 2: powerpc/4xx: Fix exception handling in ppc4xx_pciex_port_setup_hose() 2 is not a reply... assume additional patch WARNING: duplicate messages found at index 3 Subject 1: scsi: message: fusion: Delete an unnecessary variable initialisation in four functions Subject 2: powerpc/4xx: Fix exception handling in ppc4xx_pciex_port_setup_hose() 2 is not a reply... assume additional patch WARNING: duplicate messages found at index 1 Subject 1: md/raid1: Fix exception handling in setup_conf() Subject 2: scsi: message: fusion: Return directly after input data validation failed in four functions 2 is not a reply... assume additional patch WARNING: duplicate messages found at index 2 Subject 1: md/raid10: Fix exception handling in setup_conf() Subject 2: scsi: message: fusion: Return directly after input data validation failed in four functions 2 is not a reply... assume additional patch WARNING: duplicate messages found at index 1 Subject 1: irqchip/gic-v4: Fix exception handling in its_alloc_vcpu_irqs() Subject 2: md/raid1: Fix exception handling in setup_conf() 2 is not a reply... assume additional patch WARNING: duplicate messages found at index 2 Subject 1: irqchip/gic-v4: Fix exception handling in its_alloc_vcpu_sgis() Subject 2: md/raid1: Fix exception handling in setup_conf() 2 is not a reply... assume additional patch WARNING: duplicate messages found at index 1 Subject 1: selinux: Improve exception handling in security_get_bools() Subject 2: irqchip/gic-v4: Fix exception handling in its_alloc_vcpu_irqs() 2 is not a reply... assume additional patch WARNING: duplicate messages found at index 1 Subject 1: selinux: Adjust implementation of security_get_bools() Subject 2: powerpc/4xx: Fix exception handling in ppc4xx_pciex_port_setup_hose() 2 is not a reply... assume additional patch WARNING: duplicate messages found at index 1 Subject 1: IB/uverbs: Improve exception handling in create_qp() Subject 2: selinux: Improve exception handling in security_get_bools() 2 is a reply... replacing existing: selinux: Improve exception handling in security_get_bools() WARNING: duplicate messages found at index 2 Subj
Re: [PATCH] powermac: Call of_node_put(bk_node) only once in pmac_has_backlight_type()
Le 02/10/2024 à 22:02, Markus Elfring a écrit : From: Markus Elfring Date: Wed, 2 Oct 2024 21:50:27 +0200 An of_node_put(bk_node) call was immediately used after a pointer check for an of_get_property() call in this function implementation. Thus call such a function only once instead directly before the check. It seems pointless to perform a put immediately after a get. Shouldn't of_find_property() be used instead ? And then of_property_read_string() would probably be better. Maybe you can even use of_property_match_string(). This issue was transformed by using the Coccinelle software. Signed-off-by: Markus Elfring --- arch/powerpc/platforms/powermac/backlight.c | 6 ++ 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/arch/powerpc/platforms/powermac/backlight.c b/arch/powerpc/platforms/powermac/backlight.c index 12bc01353bd3..d3666595a62e 100644 --- a/arch/powerpc/platforms/powermac/backlight.c +++ b/arch/powerpc/platforms/powermac/backlight.c @@ -61,11 +61,9 @@ int pmac_has_backlight_type(const char *type) if (bk_node) { const char *prop = of_get_property(bk_node, "backlight-control", NULL); - if (prop && strncmp(prop, type, strlen(type)) == 0) { - of_node_put(bk_node); - return 1; - } of_node_put(bk_node); + if (prop && strncmp(prop, type, strlen(type)) == 0) + return 1; } return 0; -- 2.46.1
Re: [PATCH 1/2] powerpc/vdso: Add a page for non-time data
Le 02/10/2024 à 10:54, Thomas Weißschuh a écrit : [Vous ne recevez pas souvent de courriers de thomas.weisssc...@linutronix.de. D?couvrez pourquoi ceci est important ? https://aka.ms/LearnAboutSenderIdentification ] Hi Christophe, On Wed, Oct 02, 2024 at 10:39:28AM GMT, Christophe Leroy wrote: The page containing VDSO time data is swapped with the one containing TIME namespace data when a process uses a non-root time namespace. For other data like powerpc specific data and RNG data, it means tracking whether time namespace is the root one or not to know which page to use. Simplify the logic behind by moving time data out of first data page so that the first data page which contains everything else always remains the first page. Time data is in the second or third page depending on selected time namespace. While we are playing with get_datapage macro, directly take into account the data offset inside the macro instead of adding that offset afterwards. FYI I am currently working on a series to unify the storage of the VDSO data for most architectures, including powerpc. This will also include a dedicated rng data page. That generic infrastructure would replace the need for Patch 1. Obviously, if your series gets applied, I can adapt mine for that. If you are about to also modify other architectures in a similar way, we may want to coordinate. I'm not going to do anything on other architectures. Indeed my patch is an outcome of the discussion at https://patchwork.ozlabs.org/project/linuxppc-dev/patch/ffd7fc255e194d1e2b0aa3d9d129e826c53219d4.1725611321.git.christophe.le...@csgroup.eu/ I'm all fine if you are doing something generic for all architectures. For powerpc will it handle the entire non-time data, not only rng ? The purpose being to revert https://github.com/torvalds/linux/commit/c73049389e58c01e2e3bbfae900c8daeee177191 Christophe
[PATCH 2/2] powerpc/vdso: Implement __arch_get_vdso_rng_data()
VDSO time functions do not call any other function, so they don't need to save/restore LR. However, retrieving the address of VDSO data page requires using LR hence saving then restoring it, which can be heavy on some CPUs. On the other hand, VDSO functions on powerpc are not standard functions and require a wrapper function to call C VDSO functions. And that wrapper has to save and restore LR in order to call the C VDSO function, so retrieving VDSO data page address in that wrapper doesn't require additional save/restore of LR. For random VDSO functions it is a bit different. Because the function calls __arch_chacha20_blocks_nostack(), it saves and restores LR. Retrieving VDSO data page address can then be done there without additional save/restore of LR. So lets implement __arch_get_vdso_rng_data() and simplify the wrapper. It starts paving the way for the day powerpc will implement a more standard ABI for VDSO functions. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/vdso/getrandom.h | 15 +-- arch/powerpc/kernel/asm-offsets.c | 1 - arch/powerpc/kernel/vdso/getrandom.S | 1 - arch/powerpc/kernel/vdso/vgetrandom.c | 4 ++-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/arch/powerpc/include/asm/vdso/getrandom.h b/arch/powerpc/include/asm/vdso/getrandom.h index 501d6bb14e8a..4302e7c67aa5 100644 --- a/arch/powerpc/include/asm/vdso/getrandom.h +++ b/arch/powerpc/include/asm/vdso/getrandom.h @@ -7,6 +7,8 @@ #ifndef __ASSEMBLY__ +#include + static __always_inline int do_syscall_3(const unsigned long _r0, const unsigned long _r3, const unsigned long _r4, const unsigned long _r5) { @@ -43,11 +45,20 @@ static __always_inline ssize_t getrandom_syscall(void *buffer, size_t len, unsig static __always_inline struct vdso_rng_data *__arch_get_vdso_rng_data(void) { - return NULL; + struct vdso_arch_data *data; + + asm( + " bcl 20, 31, .+4\n" + "0: mflr%0\n" + " addis %0, %0, (_vdso_datapage - 0b)@ha\n" + " addi%0, %0, (_vdso_datapage - 0b)@l\n" + : "=r" (data) :: "lr"); + + return &data->rng_data; } ssize_t __c_kernel_getrandom(void *buffer, size_t len, unsigned int flags, void *opaque_state, -size_t opaque_len, const struct vdso_rng_data *vd); +size_t opaque_len); #endif /* !__ASSEMBLY__ */ diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c index 131a8cc10dbe..7b3feb6bc210 100644 --- a/arch/powerpc/kernel/asm-offsets.c +++ b/arch/powerpc/kernel/asm-offsets.c @@ -335,7 +335,6 @@ int main(void) /* datapage offsets for use by vdso */ OFFSET(VDSO_DATA_OFFSET, vdso_arch_data, data); - OFFSET(VDSO_RNG_DATA_OFFSET, vdso_arch_data, rng_data); OFFSET(CFG_TB_TICKS_PER_SEC, vdso_arch_data, tb_ticks_per_sec); #ifdef CONFIG_PPC64 OFFSET(CFG_ICACHE_BLOCKSZ, vdso_arch_data, icache_block_size); diff --git a/arch/powerpc/kernel/vdso/getrandom.S b/arch/powerpc/kernel/vdso/getrandom.S index 3deddcf89f99..a80d9fb436f7 100644 --- a/arch/powerpc/kernel/vdso/getrandom.S +++ b/arch/powerpc/kernel/vdso/getrandom.S @@ -31,7 +31,6 @@ PPC_STL r2, PPC_MIN_STKFRM + STK_GOT(r1) .cfi_rel_offset r2, PPC_MIN_STKFRM + STK_GOT #endif - get_datapager8 VDSO_RNG_DATA_OFFSET bl CFUNC(DOTSYM(\funct)) PPC_LL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1) #ifdef __powerpc64__ diff --git a/arch/powerpc/kernel/vdso/vgetrandom.c b/arch/powerpc/kernel/vdso/vgetrandom.c index 5f855d45fb7b..cc79b960a541 100644 --- a/arch/powerpc/kernel/vdso/vgetrandom.c +++ b/arch/powerpc/kernel/vdso/vgetrandom.c @@ -8,7 +8,7 @@ #include ssize_t __c_kernel_getrandom(void *buffer, size_t len, unsigned int flags, void *opaque_state, -size_t opaque_len, const struct vdso_rng_data *vd) +size_t opaque_len) { - return __cvdso_getrandom_data(vd, buffer, len, flags, opaque_state, opaque_len); + return __cvdso_getrandom(buffer, len, flags, opaque_state, opaque_len); } -- 2.44.0
[PATCH 1/2] powerpc/vdso: Add a page for non-time data
The page containing VDSO time data is swapped with the one containing TIME namespace data when a process uses a non-root time namespace. For other data like powerpc specific data and RNG data, it means tracking whether time namespace is the root one or not to know which page to use. Simplify the logic behind by moving time data out of first data page so that the first data page which contains everything else always remains the first page. Time data is in the second or third page depending on selected time namespace. While we are playing with get_datapage macro, directly take into account the data offset inside the macro instead of adding that offset afterwards. Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/vdso_datapage.h | 24 +++- arch/powerpc/kernel/vdso.c | 16 ++-- arch/powerpc/kernel/vdso/cacheflush.S| 2 +- arch/powerpc/kernel/vdso/datapage.S | 4 ++-- arch/powerpc/kernel/vdso/getrandom.S | 3 +-- arch/powerpc/kernel/vdso/gettimeofday.S | 5 ++--- arch/powerpc/kernel/vdso/vdso32.lds.S| 2 +- arch/powerpc/kernel/vdso/vdso64.lds.S| 2 +- 8 files changed, 25 insertions(+), 33 deletions(-) diff --git a/arch/powerpc/include/asm/vdso_datapage.h b/arch/powerpc/include/asm/vdso_datapage.h index 248dee138f7b..33069afccb3c 100644 --- a/arch/powerpc/include/asm/vdso_datapage.h +++ b/arch/powerpc/include/asm/vdso_datapage.h @@ -82,8 +82,9 @@ struct vdso_arch_data { __u32 syscall_map[SYSCALL_MAP_SIZE];/* Map of syscalls */ __u32 compat_syscall_map[SYSCALL_MAP_SIZE]; /* Map of compat syscalls */ - struct vdso_data data[CS_BASES]; struct vdso_rng_data rng_data; + + struct vdso_data data[CS_BASES] __aligned(1 << CONFIG_PAGE_SHIFT); }; #else /* CONFIG_PPC64 */ @@ -95,8 +96,9 @@ struct vdso_arch_data { __u64 tb_ticks_per_sec; /* Timebase tics / sec 0x38 */ __u32 syscall_map[SYSCALL_MAP_SIZE]; /* Map of syscalls */ __u32 compat_syscall_map[0];/* No compat syscalls on PPC32 */ - struct vdso_data data[CS_BASES]; struct vdso_rng_data rng_data; + + struct vdso_data data[CS_BASES] __aligned(1 << CONFIG_PAGE_SHIFT); }; #endif /* CONFIG_PPC64 */ @@ -105,29 +107,17 @@ extern struct vdso_arch_data *vdso_data; #else /* __ASSEMBLY__ */ -.macro get_datapage ptr +.macro get_datapage ptr offset=0 bcl 20, 31, .+4 999: mflr\ptr - addis \ptr, \ptr, (_vdso_datapage - 999b)@ha - addi\ptr, \ptr, (_vdso_datapage - 999b)@l + addis \ptr, \ptr, (_vdso_datapage - 999b + \offset)@ha + addi\ptr, \ptr, (_vdso_datapage - 999b + \offset)@l .endm #include #include -.macro get_realdatapage ptr scratch - get_datapage \ptr -#ifdef CONFIG_TIME_NS - lwz \scratch, VDSO_CLOCKMODE_OFFSET(\ptr) - xoris \scratch, \scratch, VDSO_CLOCKMODE_TIMENS@h - xori\scratch, \scratch, VDSO_CLOCKMODE_TIMENS@l - cntlzw \scratch, \scratch - rlwinm \scratch, \scratch, PAGE_SHIFT - 5, 1 << PAGE_SHIFT - add \ptr, \ptr, \scratch -#endif -.endm - #endif /* __ASSEMBLY__ */ #endif /* __KERNEL__ */ diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c index ee4b9d676cff..6166c1862c06 100644 --- a/arch/powerpc/kernel/vdso.c +++ b/arch/powerpc/kernel/vdso.c @@ -48,12 +48,13 @@ long sys_ni_syscall(void); */ static union { struct vdso_arch_data data; - u8 page[PAGE_SIZE]; + u8 page[2 * PAGE_SIZE]; } vdso_data_store __page_aligned_data; struct vdso_arch_data *vdso_data = &vdso_data_store.data; enum vvar_pages { - VVAR_DATA_PAGE_OFFSET, + VVAR_BASE_PAGE_OFFSET, + VVAR_TIME_PAGE_OFFSET, VVAR_TIMENS_PAGE_OFFSET, VVAR_NR_PAGES, }; @@ -119,7 +120,7 @@ static struct vm_special_mapping vdso64_spec __ro_after_init = { #ifdef CONFIG_TIME_NS struct vdso_data *arch_get_vdso_data(void *vvar_page) { - return ((struct vdso_arch_data *)vvar_page)->data; + return vvar_page; } /* @@ -153,11 +154,14 @@ static vm_fault_t vvar_fault(const struct vm_special_mapping *sm, unsigned long pfn; switch (vmf->pgoff) { - case VVAR_DATA_PAGE_OFFSET: + case VVAR_BASE_PAGE_OFFSET: + pfn = virt_to_pfn(vdso_data); + break; + case VVAR_TIME_PAGE_OFFSET: if (timens_page) pfn = page_to_pfn(timens_page); else - pfn = virt_to_pfn(vdso_data); + pfn = virt_to_pfn(vdso_data->data); break; #ifdef CONFIG_TIME_NS case VVAR_TIMENS_PAGE_OFFSET: @@ -170,7 +174,7 @@ static vm_fault_t vvar_fault(const struct vm_special_mapping *sm, */ if (!timens_page) return VM_FA
Re: [PATCH 1/2] powerpc/sstep: Unexport analyze_instr, emulate_vsx_load, emulate_vsx_store
Le 01/10/2024 à 12:08, Michal Suchanek a écrit : There is no modular user of analyze_instr, and the latter two are only used by sstep itself. analyze_instr() is used in arch/powerpc/kvm/emulate_loadstore.c which can be a module as far as I can see in Makefile: common-objs-y += powerpc.o emulate_loadstore.o kvm-book3s_64-module-objs := \ $(common-objs-y) \ book3s.o \ book3s_rtas.o \ $(kvm-book3s_64-objs-y) kvm-objs-$(CONFIG_KVM_BOOK3S_64) := $(kvm-book3s_64-module-objs) config KVM_BOOK3S_64 tristate "KVM support for PowerPC book3s_64 processors" Signed-off-by: Michal Suchanek --- arch/powerpc/lib/sstep.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/arch/powerpc/lib/sstep.c b/arch/powerpc/lib/sstep.c index e65f3fb68d06..a0557b0d9a24 100644 --- a/arch/powerpc/lib/sstep.c +++ b/arch/powerpc/lib/sstep.c @@ -863,7 +863,6 @@ void emulate_vsx_load(struct instruction_op *op, union vsx_reg *reg, break; } } -EXPORT_SYMBOL_GPL(emulate_vsx_load); NOKPROBE_SYMBOL(emulate_vsx_load); void emulate_vsx_store(struct instruction_op *op, const union vsx_reg *reg, @@ -955,7 +954,6 @@ void emulate_vsx_store(struct instruction_op *op, const union vsx_reg *reg, break; } } -EXPORT_SYMBOL_GPL(emulate_vsx_store); NOKPROBE_SYMBOL(emulate_vsx_store); static nokprobe_inline int do_vsx_load(struct instruction_op *op, @@ -3172,7 +3170,6 @@ int analyse_instr(struct instruction_op *op, const struct pt_regs *regs, op->val = SRR1_PROGTRAP; return 0; } -EXPORT_SYMBOL_GPL(analyse_instr); NOKPROBE_SYMBOL(analyse_instr); /*
Re: Kernel doesn't boot after DRM updates (drm-next-2024-09-19)
Hi All, Le 01/10/2024 à 14:09, Hoi Pok Wu a écrit : [Vous ne recevez pas souvent de courriers de wuhoi...@gmail.com. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ] Hi Thomas, Could you help on this issue? I do not have access to the hardware now. Thank you. The OOPS is from function drm_dp_aux_register(), exactly here below: static inline const char *dev_name(const struct device *dev) { /* Use the init name until the kobject becomes available */ if (dev->init_name) 1ae0: e8 89 00 50 ld r4,80(r9) As you see in registers dump, r9 register is NULL. That's dev which is NULL: GPR00: c05b74f0 c000800daf10 c15a3600 c0008033f7ec GPR04: c1908f18 c00080460c80 c0c0c0c0 GPR08: c00080f74008 0003 c00080f74008 GPR12: 48000828 c0003fffeac0 0003 0100 GPR16: c000804eaeca 0013 3113 GPR20: 0008 c000800db208 000a c14d6868 GPR24: 0001 c000800db29c c000800db250 GPR28: c00080bd8040 0001 c00080f74000 c0008033f4a0 Full dump below: 1a5c : { 1a5c: 3c 4c 00 00 addis r2,r12,0 1a5e: R_PPC64_REL16_HA .TOC.+0x2 1a60: 38 42 00 00 addir2,r2,0 1a62: R_PPC64_REL16_LO .TOC.+0x6 1a64: 7c 08 02 a6 mflrr0 1a68: fb e1 ff f8 std r31,-8(r1) 1a6c: f8 01 00 10 std r0,16(r1) 1a70: 7c 7f 1b 78 mr r31,r3 1a74: f8 21 ff d1 stdur1,-48(r1) WARN_ON_ONCE(!aux->drm_dev); 1a78: e9 23 03 38 ld r9,824(r3) 1a7c: 2f a9 00 00 cmpdi cr7,r9,0 1a80: 41 de 00 90 beq-cr7,1b10 if (!aux->ddc.algo) 1a84: e9 3f 00 18 ld r9,24(r31) 1a88: 2f a9 00 00 cmpdi cr7,r9,0 1a8c: 41 de 00 74 beq-cr7,1b00 strscpy(aux->ddc.name, aux->name ? aux->name : dev_name(aux->dev), 1a90: e8 9f 00 00 ld r4,0(r31) aux->ddc.owner = THIS_MODULE; 1a94: 39 40 00 00 li r10,0 aux->ddc.dev.parent = aux->dev; 1a98: e9 3f 03 30 ld r9,816(r31) strscpy(aux->ddc.name, aux->name ? aux->name : dev_name(aux->dev), 1a9c: 38 7f 02 74 addir3,r31,628 aux->ddc.owner = THIS_MODULE; 1aa0: f9 5f 00 08 std r10,8(r31) strscpy(aux->ddc.name, aux->name ? aux->name : dev_name(aux->dev), 1aa4: 2f a4 00 00 cmpdi cr7,r4,0 aux->ddc.dev.parent = aux->dev; 1aa8: f9 3f 00 b8 std r9,184(r31) strscpy(aux->ddc.name, aux->name ? aux->name : dev_name(aux->dev), 1aac: 41 de 00 34 beq-cr7,1ae0 1ab0: 38 a0 00 30 li r5,48 1ab4: 48 00 00 01 bl 1ab4 1ab4: R_PPC64_REL24 sized_strscpy 1ab8: 60 00 00 00 nop ret = i2c_add_adapter(&aux->ddc); 1abc: 38 7f 00 08 addir3,r31,8 1ac0: 48 00 00 01 bl 1ac0 1ac0: R_PPC64_REL24 i2c_add_adapter 1ac4: 60 00 00 00 nop } 1ac8: 38 21 00 30 addir1,r1,48 1acc: e8 01 00 10 ld r0,16(r1) 1ad0: eb e1 ff f8 ld r31,-8(r1) 1ad4: 7c 08 03 a6 mtlrr0 1ad8: 4e 80 00 20 blr 1adc: 60 00 00 00 nop * Return: The kobject name of the device, or its initial name if unavailable. */ static inline const char *dev_name(const struct device *dev) { /* Use the init name until the kobject becomes available */ if (dev->init_name) 1ae0: e8 89 00 50 ld r4,80(r9) 1ae4: 2f a4 00 00 cmpdi cr7,r4,0 1ae8: 40 fe ff c8 bne+cr7,1ab0 return dev->init_name; return kobject_name(&dev->kobj); 1aec: e8 89 00 00 ld r4,0(r9) 1af0: 4b ff ff c0 b 1ab0 1af4: 60 00 00 00 nop 1af8: 60 00 00 00 nop 1afc: 60 00 00 00 nop drm_dp_aux_init(aux); 1b00: 7f e3 fb 78 mr r3,r31 1b04: 48 00 00 01 bl 1b04 1b04: R_PPC64_REL24 drm_dp_aux_init 1b08: 4b ff ff 88 b 1a90 1b0c: 60 00 00 00 nop WARN_ON_ONCE(!aux->drm_dev); 1b10: 0f e0 00 00 twuir0,0 1b14: 4b ff ff 70 b 1a84 Regards, Wu Hoi Pok On Tue, Oct 1, 2024 at 12:26 PM Christian Zigotzky wrote: On 30 September 2024 3:27pm, Alex Deucher wrote: + Wu Hoi Pok This is likely related to the drm device rework. Alex —- Hi All, I was able t
Re: [PATCH] powerpc/kexec: Fix the return of uninitialized variable
Le 30/09/2024 à 09:56, Zhang Zekun a écrit : [Vous ne recevez pas souvent de courriers de zhangzeku...@huawei.com. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ] The of_property_read_u64() can fail and remain the variable uninitialized, Replace "remain" by "leave". which will then be used. Return error if we failed to read the property. Rewrite to avoid "we". For instance "Return error if reading the property failed" Fixes: 2e6bd221d96f ("powerpc/kexec_file: Enable early kernel OPAL calls") Signed-off-by: Zhang Zekun --- arch/powerpc/kexec/file_load_64.c | 9 +++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/kexec/file_load_64.c b/arch/powerpc/kexec/file_load_64.c index 9738adabeb1f..dc65c1391157 100644 --- a/arch/powerpc/kexec/file_load_64.c +++ b/arch/powerpc/kexec/file_load_64.c @@ -736,13 +736,18 @@ int setup_purgatory_ppc64(struct kimage *image, const void *slave_code, if (dn) { u64 val; - of_property_read_u64(dn, "opal-base-address", &val); + ret = of_property_read_u64(dn, "opal-base-address", &val); + if (ret) + goto out; + ret = kexec_purgatory_get_set_symbol(image, "opal_base", &val, sizeof(val), false); if (ret) goto out; - of_property_read_u64(dn, "opal-entry-address", &val); + ret = of_property_read_u64(dn, "opal-entry-address", &val); + if (ret) + goto out; ret = kexec_purgatory_get_set_symbol(image, "opal_entry", &val, sizeof(val), false); } -- 2.17.1
Re: FSL P5040 board doesn't boot after DRM updates (drm-next-2024-09-19)
Hi Christian, Le 28/09/2024 à 09:40, Christian Zigotzky a écrit : On 28 September 2024 at 09:21am, Christian Zigotzky wrote: > >> On Sun, Sep 22, 2024 at 12:28 AM Christian Zigotzky >> wrote: >>> >>> Hi All, >>> >>> The lastest Git kernel doesn't boot anymore after the latest DRM updates >>> (drm-next-2024-09-19). [1] >>> >>> I tested it with an AMD Radeon HD 6970 (Cayman XT) and with an AMD >>> Radeon HD 5870 (Cypress XT). >>> >>> I reverted the DRM updates and after that the kernel boots without any >>> problems. >>> >>> Please note: Due to a lack of time, I can't do a bisect. >>> >>> Please check the latest DRM updates. >> >> Can you attach your dmesg output? There was a regression in the dma >> subsystem what was fixed by this commit: >> >> commit b348b6d17fd1d5d89b86db602f02be >> a54a754bd8 >> Author: Leon Romanovsky >> Date: Sun Sep 22 21:09:48 2024 +0300 >> >> dma-mapping: report unlimited DMA addressing in IOMMU DMA path >> >> Alex >> Hi Alex, I tested the latest Git kernel on my FSL P5040 board today and it doesn't boot. Our FSL P5020 boards boot without any problems. I connected my FSL P5040 board with a serial cable to my PC for getting error messages. Unfortunately there aren't any error messages after the loading of the uImage. This means, that the dma-mapping patch doesn't solve the boot issue. Please check the latest DRM updates. Can you bisect the problem ? Christophe
Re: [PATCH v5 14/16] modules: Support extended MODVERSIONS info
Le 26/09/2024 à 01:38, Matthew Maurer a écrit : Adds a new format for MODVERSIONS which stores each field in a separate ELF section. This initially adds support for variable length names, but could later be used to add additional fields to MODVERSIONS in a backwards compatible way if needed. Any new fields will be ignored by old user tooling, unlike the current format where user tooling cannot tolerate adjustments to the format (for example making the name field longer). Since PPC munges its version records to strip leading dots, we reproduce the munging for the new format. Other architectures do not appear to have architecture-specific usage of this information. Signed-off-by: Matthew Maurer --- arch/powerpc/kernel/module_64.c | 23 - kernel/module/internal.h| 11 kernel/module/main.c| 92 ++--- kernel/module/version.c | 45 4 files changed, 161 insertions(+), 10 deletions(-) diff --git a/arch/powerpc/kernel/module_64.c b/arch/powerpc/kernel/module_64.c index e9bab599d0c2..4e7b156dd8b2 100644 --- a/arch/powerpc/kernel/module_64.c +++ b/arch/powerpc/kernel/module_64.c @@ -355,6 +355,23 @@ static void dedotify_versions(struct modversion_info *vers, } } +static void dedotify_ext_version_names(char *str_seq, unsigned long size) +{ + unsigned long out = 0; + unsigned long in; + char last = '\0'; + + for (in = 0; in < size; in++) { + /* Skip one leading dot */ + if (last == '\0' && str_seq[in] == '.') + in++; + last = str_seq[in]; + str_seq[out++] = last; + } Why do you need a loop here ? Can't you just do something like: if (str_seq[0] == '.') memmove(str_seq, str_seq + 1, size); + /* Zero the trailing portion of the names table for robustness */ + memset(&str_seq[out], 0, size - out); This seems unneeded. +} + /* * Undefined symbols which refer to .funcname, hack to funcname. Make .TOC. * seem to be defined (value set later). Christophe
Re: [PATCH] powerpc/vdso: allow r30 in vDSO code generation of getrandom
Le 25/09/2024 à 20:38, Jason A. Donenfeld a écrit : On Wed, Sep 25, 2024 at 07:50:22PM +0200, Jason A. Donenfeld wrote: For gettimeofday, -ffixed-r30 was passed to work around a bug in Go code, where the vDSO trampoline forgot to save and restore this register across function calls. But Go requires a different trampoline for every call, and there's no reason that new Go code needs to be broken and add more bugs. So remove -ffixed-r30 for getrandom. Strangely, I am _unable to_ make the Go code not crash with this patch applied. I'm not quite sure what I'm doing wrong yet, or if this points to another issue. Do you mean that without this patch the Go code works and with this patch it crashes ? That's strange taken into account that the chacha function plays up with r30 regardless of this patch. Christophe
Re: [FSL P50x0] [GIT KERNEL] [VDSO] compiling issue
Le 20/09/2024 à 06:30, Michael Ellerman a écrit : Christian Zigotzky writes: Hi All, The compiling of the latest Git kernel doesn’t work anymore for our FSL P5020/P5040 boards [1] since the random-6.12-rc1 updates [2]. Error messages: arch/powerpc/kernel/vdso/vdso32.so.dbg: dynamic relocations are not supported make[2]: *** [arch/powerpc/kernel/vdso/Makefile:75: arch/powerpc/kernel/vdso/vdso32.so.dbg] Reverting of the vdso updates has solved the compiing issue. Could you please check the random-6.12-rc1 updates? [2] Thanks, Christian [1] https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwiki.amiga.org%2Findex.php%3Ftitle%3DX5000&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7Ce6f19b86406f4cd847f508dcd92d0a13%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638624034682015871%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=VyrTeeljcPlZqFqPSu2unkEoxrEB9%2FCCDdOnIr7CvG4%3D&reserved=0 [2] https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git%2Fcommit%2F%3Fid%3D4a39ac5b7d62679c07a3e3d12b0f6982377d8a7d&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7Ce6f19b86406f4cd847f508dcd92d0a13%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638624034682033680%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=EU8R%2BOEIQUWivXDhkcdwvyUfGqR13%2FOAlm3VUntSblk%3D&reserved=0 + Kernel config Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fraw.githubusercontent.com%2Fchzigotzky%2Fkernels%2Frefs%2Fheads%2Fmain%2Fconfigs%2Fx5000_defconfig&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7Ce6f19b86406f4cd847f508dcd92d0a13%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638624034682046602%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=r9CQKH74EJx%2B74Yniufx%2BFgvPSJVlGgFrvMma1K9Uaw%3D&reserved=0 Your config has: # CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE is not set CONFIG_CC_OPTIMIZE_FOR_SIZE=y But all our defconfigs use CONFIG_CC_OPTIMIZE_FOR_PERFORMANCE. Which explains why we didn't catch this in build testing. I've added a build with OPTIMIZE_FOR_SIZE=y so hopefully we'll catch any similar errors in future. And I sent a patch to fix it: https://patchwork.ozlabs.org/project/linuxppc-dev/patch/aded2b257018fe654db759fdfa4ab1a0b5426b1b.1726772140.git.christophe.le...@csgroup.eu/ Christophe
[PATCH] powerpc/vdso32: Fix use of crtsavres for PPC64
crtsavres.S content is encloded by a #ifndef CONFIG_PPC64 To be used on VDSO32 on PPC64 it's content must available on PPC64 as well. Replace #ifndef CONFIG_PPC64 by #ifndef __powerpc64__ as __powerpc64__ is not set when building VDSO32 on PPC64. Reported-by: Christian Zigotzky Closed: https://lore.kernel.org/linuxppc-dev/047b7503-af0c-4bb0-b12a-2f6b1e461...@csgroup.eu/T/ Fixes: b163596a5b6f ("powerpc/vdso32: Add crtsavres") Signed-off-by: Christophe Leroy --- arch/powerpc/lib/crtsavres.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/lib/crtsavres.S b/arch/powerpc/lib/crtsavres.S index 7e5e1c28e56a..8967903c15e9 100644 --- a/arch/powerpc/lib/crtsavres.S +++ b/arch/powerpc/lib/crtsavres.S @@ -46,7 +46,7 @@ .section ".text" -#ifndef CONFIG_PPC64 +#ifndef __powerpc64__ /* Routines for saving integer registers, called by the compiler. */ /* Called with r11 pointing to the stack header word of the caller of the */ -- 2.44.0
Re: [FSL P50x0] [GIT KERNEL] [VDSO] compiling issue
Hi Christian, Le 19/09/2024 à 17:02, Christian Zigotzky a écrit : Hi All, The compiling of the latest Git kernel doesn’t work anymore for our FSL P5020/P5040 boards [1] since the random-6.12-rc1 updates [2]. Error messages: arch/powerpc/kernel/vdso/vdso32.so.dbg: dynamic relocations are not supported make[2]: *** [arch/powerpc/kernel/vdso/Makefile:75: arch/powerpc/kernel/vdso/vdso32.so.dbg] Reverting of the vdso updates has solved the compiing issue. Could you please check the random-6.12-rc1 updates? [2] Thanks, Christian [1] https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwiki.amiga.org%2Findex.php%3Ftitle%3DX5000&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4b327823a8d843f5dc8d08dcd8bc2600%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638623549830455660%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=xtne08CcJdt0jF0eir8q%2F5CeMcCv6JN4Uj4LDKqUiog%3D&reserved=0 [2] https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Ftorvalds%2Flinux.git%2Fcommit%2F%3Fid%3D4a39ac5b7d62679c07a3e3d12b0f6982377d8a7d&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4b327823a8d843f5dc8d08dcd8bc2600%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638623549830472839%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=sVQ9FhoXe9YDrqFrwb4a1rmMlN7Kegg7z1yMQ4uAFvo%3D&reserved=0 + Kernel config Link: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fraw.githubusercontent.com%2Fchzigotzky%2Fkernels%2Frefs%2Fheads%2Fmain%2Fconfigs%2Fx5000_defconfig&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4b327823a8d843f5dc8d08dcd8bc2600%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638623549830486185%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=SQi%2B9R4TM59QB8Msxq3KuKPvvJEBMVUdyOhoY6ndzVU%3D&reserved=0 + Christophe Leroy + Michael Ellerman Can you try with the following change: diff --git a/arch/powerpc/lib/crtsavres.S b/arch/powerpc/lib/crtsavres.S index 7e5e1c28e56a..8967903c15e9 100644 --- a/arch/powerpc/lib/crtsavres.S +++ b/arch/powerpc/lib/crtsavres.S @@ -46,7 +46,7 @@ .section ".text" -#ifndef CONFIG_PPC64 +#ifndef __powerpc64__ /* Routines for saving integer registers, called by the compiler. */ /* Called with r11 pointing to the stack header word of the caller of the */
Re: [RFC v2 03/13] book3s64/hash: Remove kfence support temporarily
Le 19/09/2024 à 04:56, Ritesh Harjani (IBM) a écrit : Kfence on book3s Hash on pseries is anyways broken. It fails to boot due to RMA size limitation. That is because, kfence with Hash uses debug_pagealloc infrastructure. debug_pagealloc allocates linear map for entire dram size instead of just kfence relevant objects. This means for 16TB of DRAM it will require (16TB >> PAGE_SHIFT) which is 256MB which is half of RMA region on P8. crash kernel reserves 256MB and we also need 2048 * 16KB * 3 for emergency stack and some more for paca allocations. That means there is not enough memory for reserving the full linear map in the RMA region, if the DRAM size is too big (>=16TB) (The issue is seen above 8TB with crash kernel 256 MB reservation). Now Kfence does not require linear memory map for entire DRAM. It only needs for kfence objects. So this patch temporarily removes the kfence functionality since debug_pagealloc code needs some refactoring. We will bring in kfence on Hash support in later patches. Signed-off-by: Ritesh Harjani (IBM) --- arch/powerpc/include/asm/kfence.h | 5 + arch/powerpc/mm/book3s64/hash_utils.c | 16 +++- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/include/asm/kfence.h b/arch/powerpc/include/asm/kfence.h index fab124ada1c7..f3a9476a71b3 100644 --- a/arch/powerpc/include/asm/kfence.h +++ b/arch/powerpc/include/asm/kfence.h @@ -10,6 +10,7 @@ #include #include +#include #ifdef CONFIG_PPC64_ELF_ABI_V1 #define ARCH_FUNC_PREFIX "." @@ -25,6 +26,10 @@ static inline void disable_kfence(void) static inline bool arch_kfence_init_pool(void) { +#ifdef CONFIG_PPC64 + if (!radix_enabled()) No need for a #ifdef here, you can just do: if (IS_ENABLED(CONFIG_PPC64) && !radix_enabled()) return false; + return false; +#endif return !kfence_disabled; But why not just set kfence_disabled to true by calling disable_kfence() from one of the powerpc init functions ? } #endif
Re: [RFC v2 02/13] powerpc: mm: Fix kfence page fault reporting
Le 19/09/2024 à 04:56, Ritesh Harjani (IBM) a écrit : copy_from_kernel_nofault() can be called when doing read of /proc/kcore. /proc/kcore can have some unmapped kfence objects which when read via copy_from_kernel_nofault() can cause page faults. Since *_nofault() functions define their own fixup table for handling fault, use that instead of asking kfence to handle such faults. Hence we search the exception tables for the nip which generated the fault. If there is an entry then we let the fixup table handler handle the page fault by returning an error from within ___do_page_fault(). Searching the exception table is a heavy operation and all has been done in the past to minimise the number of times it is called, see for instance commit cbd7e6ca0210 ("powerpc/fault: Avoid heavy search_exception_tables() verification") Also, by trying to hide false positives you also hide real ones. For instance if csum_partial_copy_generic() is using a kfence protected area, it will now go undetected. IIUC, here your problem is limited to copy_from_kernel_nofault(). You should handle the root cause, not its effects. For that, you could perform additional verifications in copy_from_kernel_nofault_allowed(). Christophe
Re: [PATCH 1/2] powerpc/entry: convert to common and generic entry
Hi, Le 14/09/2024 à 04:22, Luming Yu a écrit : On Fri, Sep 13, 2024 at 02:15:40PM +0200, Christophe Leroy wrote: Le 13/09/2024 à 14:02, Luming Yu a écrit : ... nothing happens after that. reproduced with ppc64_defconfig [0.818972][T1] Run /init as init process [5.851684][ T240] request_module: modprobe binfmt-4c46 cannot be processed, kmod busy with 50 threads for more than 5 seconds now [5.851742][ T240] kworker/u33:18 (240) used greatest stack depth: 13584 bytes left [5.860081][ T232] kworker/u33:16 (232) used greatest stack depth: 13072 bytes left [5.863145][ T210] kworker/u35:13 (210) used greatest stack depth: 12928 bytes left [5.865000][T1] Failed to execute /init (error -8) [5.868897][T1] Run /sbin/init as init process [ 10.891673][ T315] request_module: modprobe binfmt-4c46 cannot be processed, kmod busy with 50 threads for more than 5 seconds now [ 10.894036][T1] Starting init: /sbin/init exists but couldn't execute it (error -8) [ 10.901455][T1] Run /etc/init as init process [ 10.903154][T1] Run /bin/init as init process [ 10.904747][T1] Run /bin/sh as init process [ 15.931679][ T367] request_module: modprobe binfmt-4c46 cannot be processed, kmod busy with 50 threads for more than 5 seconds now [ 15.934689][T1] Starting init: /bin/sh exists but couldn't execute it (error -8) That's something different, this is because you built a big-endian kernel and you are trying to run a little-endian userspace. okay Does it work with ppc64le_defconfig ? make ppc64le_defconfig yes, it builds && boots just fine. the host is a p8 powernv system , the qemu command line is as below: qemu-system-ppc64 -m 64g -smp 16,cores=4,threads=4 --enable-kvm -nographic -net nic -net tap,ifname=tap0,script=/etc/qemu-ifup-nat,downscript=/etc/qemu-ifdown-nat Downloads/Fedora-Cloud-Base-38-1.6.ppc64le.qcow2 With that command you don't boot a freshly built kernel, you boot: Linux version 6.2.9-300.fc38.ppc64le (mockbuild@0e2dbea752814aea985bdc5347ce35da) (gcc (GCC) 13.0.1 20230318 (Red Hat 13.0.1-0), GNU ld version 2.39-9.fc38) Are you sure you tried with the ppc64le_defconfig ? On my side the boot fails as follows when using a ppc64le_defconfig vmlinux with the file Fedora-Cloud-Base-38-1.6.ppc64le.qcow2: ... [2.602758][T1] md: autorun ... [2.602808][T1] md: ... autorun DONE. [2.612596][ T189] kworker/u73:0 (189) used greatest stack depth: 29008 bytes left [2.617068][T1] /dev/root: Can't open blockdev [2.618136][T1] VFS: Cannot open root device "" or unknown-block(0,0): error -6 [2.618239][T1] Please append a correct "root=" boot option; here are the available partitions: [2.618611][T1] 0100 65536 ram0 [2.618768][T1] (driver?) [2.619101][T1] 0101 65536 ram1 [2.619120][T1] (driver?) [2.619187][T1] 0102 65536 ram2 [2.619199][T1] (driver?) [2.619251][T1] 0103 65536 ram3 [2.619261][T1] (driver?) [2.619312][T1] 0104 65536 ram4 [2.619322][T1] (driver?) [2.619372][T1] 0105 65536 ram5 [2.619382][T1] (driver?) [2.619436][T1] 0106 65536 ram6 [2.619447][T1] (driver?) [2.619500][T1] 0107 65536 ram7 [2.619519][T1] (driver?) [2.619571][T1] 0108 65536 ram8 [2.619581][T1] (driver?) [2.619631][T1] 0109 65536 ram9 [2.619641][T1] (driver?) [2.619690][T1] 010a 65536 ram10 [2.619700][T1] (driver?) [2.619754][T1] 010b 65536 ram11 [2.619764][T1] (driver?) [2.619818][T1] 010c 65536 ram12 [2.619827][T1] (driver?) [2.619880][T1] 010d 65536 ram13 [2.619889][T1] (driver?) [2.619942][T1] 010e 65536 ram14 [2.619952][T1] (driver?) [2.620023][T1] 010f 65536 ram15 [2.620036][T1] (driver?) [2.620116][T1] 0b00 1048575 sr0 [2.620150][T1] driver: sr [2.620221][T1] 0800 5242880 sda [2.620234][T1] driver: sd [2.620310][T1] 08014096 sda1 709431c7-74bd-4ec4-bbe8-d4f7e7e3194e [2.620369][T1] [2.620449][T1] 0802 1024000 sda2 e0b0a6de-ca8f-4e50-808c-121324c94d04 [2.620463][T1] [2.620531][T1] 0803 102400 sda3 8ed2fbf1-fd2c-4ab0-b66f-d31df1d24e3e [2.620544][T1] [2.620599][T1] 08041024 sda4 46dc7fc8-bf10-4166-9bc8-98daabbec06d [2.620610][T1] [2.620666][T1] 0805 4109312 sda5 8a52b54b-c379-43a5-bf8d-a43fdef4a370 [2.620676][T1] [2.620838][T1] List of all bdev filesystems: [2.620884][T1] ext3 [2.620918][T1] ex
Re: [PATCH net-next v2] page_pool: fix build on powerpc with GCC 14
Le 14/09/2024 à 04:02, Michael Ellerman a écrit : Mina Almasry writes: Building net-next with powerpc with GCC 14 compiler results in this build error: /home/sfr/next/tmp/ccuSzwiR.s: Assembler messages: /home/sfr/next/tmp/ccuSzwiR.s:2579: Error: operand out of domain (39 is not a multiple of 4) make[5]: *** [/home/sfr/next/next/scripts/Makefile.build:229: net/core/page_pool.o] Error 1 Root caused in this thread: https://lore.kernel.org/netdev/913e2fbd-d318-4c9b-aed2-4d333a1d5...@cs-soprasteria.com/ Sorry I'm late to this, the original report wasn't Cc'ed to linuxppc-dev :D I think this is a bug in the arch/powerpc inline asm constraints. Can you try the patch below, it fixes the build error for me. I'll run it through some boot tests and turn it into a proper patch over the weekend. cheers diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h index 5bf6a4d49268..0e41c1da82dd 100644 --- a/arch/powerpc/include/asm/atomic.h +++ b/arch/powerpc/include/asm/atomic.h @@ -23,6 +23,12 @@ #define __atomic_release_fence() \ __asm__ __volatile__(PPC_RELEASE_BARRIER "" : : : "memory") +#ifdef CONFIG_CC_IS_CLANG +#define DS_FORM_CONSTRAINT "Z<>" +#else +#define DS_FORM_CONSTRAINT "YZ<>" +#endif I see we have the same in uaccess.h, added by commit 2d43cc701b96 ("powerpc/uaccess: Fix build errors seen with GCC 13/14") Should that go in a common header, maybe ppc_asm.h ? + static __inline__ int arch_atomic_read(const atomic_t *v) { int t; @@ -197,7 +203,7 @@ static __inline__ s64 arch_atomic64_read(const atomic64_t *v) if (IS_ENABLED(CONFIG_PPC_KERNEL_PREFIXED)) __asm__ __volatile__("ld %0,0(%1)" : "=r"(t) : "b"(&v->counter)); else - __asm__ __volatile__("ld%U1%X1 %0,%1" : "=r"(t) : "m<>"(v->counter)); + __asm__ __volatile__("ld%U1%X1 %0,%1" : "=r"(t) : DS_FORM_CONSTRAINT (v->counter)); return t; } @@ -208,7 +214,7 @@ static __inline__ void arch_atomic64_set(atomic64_t *v, s64 i) if (IS_ENABLED(CONFIG_PPC_KERNEL_PREFIXED)) __asm__ __volatile__("std %1,0(%2)" : "=m"(v->counter) : "r"(i), "b"(&v->counter)); else - __asm__ __volatile__("std%U0%X0 %1,%0" : "=m<>"(v->counter) : "r"(i)); + __asm__ __volatile__("std%U0%X0 %1,%0" : "=" DS_FORM_CONSTRAINT (v->counter) : "r"(i)); } #define ATOMIC64_OP(op, asm_op) \
Re: [PATCH net-next v1] mm: fix build on powerpc with GCC 14
Hi, Le 13/09/2024 à 21:22, Matthew Wilcox a écrit : On Fri, Sep 13, 2024 at 07:20:36PM +, Mina Almasry wrote: +++ b/include/linux/page-flags.h @@ -239,8 +239,8 @@ static inline unsigned long _compound_head(const struct page *page) { unsigned long head = READ_ONCE(page->compound_head); - if (unlikely(head & 1)) - return head - 1; + if (unlikely(head & 1UL)) + return head & ~1UL; return (unsigned long)page_fixed_fake_head(page); NAK, that pessimises compound_head(). Can you please give more details on what the difference is ? I can't see what it pessimises. In both cases, you test if the value is odd, when it is odd you make it even. Christophe
Re: [PATCH] crypto: Removing CRYPTO_AES_GCM_P10.
Le 13/09/2024 à 14:30, Danny Tsen a écrit : [Vous ne recevez pas souvent de courriers de dt...@linux.ibm.com. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ] Removing CRYPTO_AES_GCM_P10 in Kconfig first so that we can apply the subsequent patches to fix data mismatch over ipsec tunnel. To deactivate a driver, all you have to do is to add: depends on BROKEN Christophe Signed-off-by: Danny Tsen --- arch/powerpc/crypto/Kconfig | 32 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/arch/powerpc/crypto/Kconfig b/arch/powerpc/crypto/Kconfig index 09ebcbdfb34f..96ca2c4c8827 100644 --- a/arch/powerpc/crypto/Kconfig +++ b/arch/powerpc/crypto/Kconfig @@ -105,22 +105,22 @@ config CRYPTO_AES_PPC_SPE architecture specific assembler implementations that work on 1KB tables or 256 bytes S-boxes. -config CRYPTO_AES_GCM_P10 - tristate "Stitched AES/GCM acceleration support on P10 or later CPU (PPC)" - depends on PPC64 && CPU_LITTLE_ENDIAN && VSX - select CRYPTO_LIB_AES - select CRYPTO_ALGAPI - select CRYPTO_AEAD - select CRYPTO_SKCIPHER - help - AEAD cipher: AES cipher algorithms (FIPS-197) - GCM (Galois/Counter Mode) authenticated encryption mode (NIST SP800-38D) - Architecture: powerpc64 using: - - little-endian - - Power10 or later features - - Support for cryptographic acceleration instructions on Power10 or - later CPU. This module supports stitched acceleration for AES/GCM. +#config CRYPTO_AES_GCM_P10 +# tristate "Stitched AES/GCM acceleration support on P10 or later CPU (PPC)" +# depends on PPC64 && CPU_LITTLE_ENDIAN && VSX +# select CRYPTO_LIB_AES +# select CRYPTO_ALGAPI +# select CRYPTO_AEAD +# select CRYPTO_SKCIPHER +# help +#AEAD cipher: AES cipher algorithms (FIPS-197) +#GCM (Galois/Counter Mode) authenticated encryption mode (NIST SP800-38D) +#Architecture: powerpc64 using: +# - little-endian +# - Power10 or later features +# +#Support for cryptographic acceleration instructions on Power10 or +#later CPU. This module supports stitched acceleration for AES/GCM. config CRYPTO_CHACHA20_P10 tristate "Ciphers: ChaCha20, XChacha20, XChacha12 (P10 or later)" -- 2.43.0
Re: [PATCH 1/2] powerpc/entry: convert to common and generic entry
Le 13/09/2024 à 14:02, Luming Yu a écrit : ... nothing happens after that. reproduced with ppc64_defconfig [0.818972][T1] Run /init as init process [5.851684][ T240] request_module: modprobe binfmt-4c46 cannot be processed, kmod busy with 50 threads for more than 5 seconds now [5.851742][ T240] kworker/u33:18 (240) used greatest stack depth: 13584 bytes left [5.860081][ T232] kworker/u33:16 (232) used greatest stack depth: 13072 bytes left [5.863145][ T210] kworker/u35:13 (210) used greatest stack depth: 12928 bytes left [5.865000][T1] Failed to execute /init (error -8) [5.868897][T1] Run /sbin/init as init process [ 10.891673][ T315] request_module: modprobe binfmt-4c46 cannot be processed, kmod busy with 50 threads for more than 5 seconds now [ 10.894036][T1] Starting init: /sbin/init exists but couldn't execute it (error -8) [ 10.901455][T1] Run /etc/init as init process [ 10.903154][T1] Run /bin/init as init process [ 10.904747][T1] Run /bin/sh as init process [ 15.931679][ T367] request_module: modprobe binfmt-4c46 cannot be processed, kmod busy with 50 threads for more than 5 seconds now [ 15.934689][T1] Starting init: /bin/sh exists but couldn't execute it (error -8) That's something different, this is because you built a big-endian kernel and you are trying to run a little-endian userspace. Does it work with ppc64le_defconfig ? On my side there is absolutely nothing happening after the last line, the screen remains steady. Christophe
Re: [PATCH 1/2] powerpc/vpa_pmu: Add interface to expose vpa counters via perf
Le 13/09/2024 à 10:35, kajoljain a écrit : On 9/13/24 12:00, Christophe Leroy wrote: Le 28/08/2024 à 12:21, Kajol Jain a écrit : The pseries Shared Processor Logical Partition(SPLPAR) machines can retrieve a log of dispatch and preempt events from the hypervisor using data from Disptach Trace Log(DTL) buffer. With this information, user can retrieve when and why each dispatch & preempt has occurred. Added an interface to expose the Virtual Processor Area(VPA) DTL counters via perf. The following events are available and exposed in sysfs: vpa_dtl/dtl_cede/ - Trace voluntary (OS initiated) virtual processor waits vpa_dtl/dtl_preempt/ - Trace time slice preempts vpa_dtl/dtl_fault/ - Trace virtual partition memory page faults. vpa_dtl/dtl_all/ - Trace all (dtl_cede/dtl_preempt/dtl_fault) Added interface defines supported event list, config fields for the event attributes and their corresponding bit values which are exported via sysfs. User could use the standard perf tool to access perf events exposed via vpa-dtl pmu. The VPA DTL PMU counters do not interrupt on overflow or generate any PMI interrupts. Therefore, the kernel needs to poll the counters, added hrtimer code to do that. The timer interval can be provided by user via sample_period field in nano seconds. Result on power10 SPLPAR system with 656 cpu threads. In the below perf record command with vpa_dtl pmu, -c option is used to provide sample_period whch corresponding to 10ns i.e; 1sec and the workload time is also 1 second, hence we are getting 656 samples: [command] perf record -a -R -e vpa_dtl/dtl_all/ -c 10 sleep 1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.828 MB perf.data (656 samples) ] There is one hrtimer added per vpa-dtl pmu thread. Code added to handle addition of dtl buffer data in the raw sample. Since DTL does not provide IP address for a sample and it just have traces on reason of dispatch/preempt, we directly saving DTL buffer data to perf.data file as raw sample. For each hrtimer restart call, interface will dump all the new dtl entries added to dtl buffer as a raw sample. To ensure there are no other conflicting dtl users (example: debugfs dtl or /proc/powerpc/vcpudispatch_stats), interface added code to use "down_write_trylock" call to take the dtl_access_lock. The dtl_access_lock is defined in dtl.h file. Also added global reference count variable called "dtl_global_refc", to ensure dtl data can be captured per-cpu. Code also added global lock called "dtl_global_lock" to avoid race condition. Signed-off-by: Kajol Jain --- Notes: - Made code changes on top of recent fix sent by Michael Ellerman. Link to the patch: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.ozlabs.org%2Fproject%2Flinuxppc-dev%2Fpatch%2F20240819122401.513203-1-mpe%40ellerman.id.au%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C95cfb2842b2a44907c9108dcd3cf0b12%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638618133431151306%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=IqFjcvT9G0HYGIbuUWhCrnXkFr9yMtSC1mGFFKZ66MI%3D&reserved=0 arch/powerpc/perf/Makefile | 2 +- arch/powerpc/perf/vpa-pmu.c | 469 include/linux/cpuhotplug.h | 1 + 3 files changed, 471 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/perf/vpa-pmu.c Seems like it doesn't build on PPC64: arch/powerpc/perf/vpa-pmu.c#L212 passing argument 1 of 'up_write' from incompatible pointer type [-Wincompatible-pointer-types] arch/powerpc/perf/vpa-pmu.c#L261 passing argument 1 of 'down_write_trylock' from incompatible pointer type [-Wincompatible-pointer-types] arch/powerpc/perf/vpa-pmu.c#L402 passing argument 1 of 'up_write' from incompatible pointer type [-Wincompatible-pointer-types] Hi Christophe, Thanks for checking the patch. These changes are on top of fix patch sent by Michael Ellerman https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.ozlabs.org%2Fproject%2Flinuxppc-dev%2Fpatch%2F20240819122401.513203-1-mpe%40ellerman.id.au%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C95cfb2842b2a44907c9108dcd3cf0b12%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638618133431160525%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=r1vQxb%2F8IXBRffDtFMwiqbKnFZ4iiqer6cLykT00%2Bew%3D&reserved=0 Since he changed the dtl_access_lock to be a rw_semaphore. Are you trying with Michael patch changes? No, I only saw CI test failure here : https://github.com/linuxppc/linux-snowpatch/actions/runs/10594868105 Sorry I didn't see you mentioned it in a note. Christophe
Re: [PATCH 1/2] powerpc/entry: convert to common and generic entry
Le 13/09/2024 à 09:38, Luming Yu a écrit : On Fri, Sep 13, 2024 at 08:54:12AM +0200, Christophe Leroy wrote: Le 13/09/2024 à 03:40, Luming Yu a écrit : On Thu, Sep 12, 2024 at 12:23:29PM +0200, Christophe Leroy wrote: Le 12/09/2024 à 10:24, Luming Yu a écrit : From: Yu Luming convert powerpc entry code in syscall and fault to use syscall_work and irqentry_state as well as common calls from generic entry infrastructure. Signed-off-by: Luming Yu --- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/hw_irq.h | 5 + arch/powerpc/include/asm/processor.h | 6 ++ arch/powerpc/include/asm/syscall.h | 5 + arch/powerpc/include/asm/thread_info.h | 1 + arch/powerpc/kernel/syscall.c | 6 +- arch/powerpc/mm/fault.c| 5 + 7 files changed, 28 insertions(+), 1 deletion(-) There is another build problem: CC kernel/entry/common.o kernel/entry/common.c: In function 'irqentry_exit': kernel/entry/common.c:335:21: error: implicit declaration of function 'regs_irqs_disabled'; did you mean 'raw_irqs_disabled'? [-Werror=implicit-function-declaration] 335 | } else if (!regs_irqs_disabled(regs)) { | ^~ | raw_irqs_disabled You have put regs_irqs_disabled() in a section dedicated to PPC64, so it fails on PPC32. After fixing this problem and providing an empty asm/entry-common.h it is now possible to build the kernel. But that's not enough, the board is stuck after: ... [2.871391] Freeing unused kernel image (initmem) memory: 1228K [2.877990] Run /init as init process Thanks for these questions. :-) I haven't gotten chance to run it in ppc32 qemu. the common syscall trace enter lost this hunk - if (!is_32bit_task()) - audit_syscall_entry(regs->gpr[0], regs->gpr[3], regs->gpr[4], - regs->gpr[5], regs->gpr[6]); - else - audit_syscall_entry(regs->gpr[0], - regs->gpr[3] & 0x, - regs->gpr[4] & 0x, - regs->gpr[5] & 0x, - regs->gpr[6] & 0x); which I don't understand whether we need a arch callbacks for it. I don't thing so. As far as I can see, audit_syscall_entry() is called by syscall_enter_audit() in kernel/entry/common.c And the masking of arguments based on is_32bit_task() is done in syscall_get_arguments() with is called by syscall_enter_audit() just before calling audit_syscall_entry() and which is an arch callback that does the same as the removed hunk. so, syscall_get_arguments is the ppc arch callback. thanks. :-) Before I sent out the RFC patch set, the very limited compile and boot test goes well with a ppc64 qemu VM. Surely, there will be a lot of test, debug and following up patch set update that is necessary to make it a complete convert. Even on ppc64 it doesn't build, at the first place because arch/powerpc/include/asm/entry-common.h is missing in your patch. Did you forget to 'git add' it ? oh, I forget that I was testing this patch on top of the early user notifier patch: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Flinuxppc%2Fissues%2Fissues%2F477&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C35a08ca9a81f4c6ff8ce08dcd3c73555%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638618099770810941%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=yCQWLIAXL%2BNHnzrh0e91WIBvF0c5WfF6pY6ZMHstocA%3D&reserved=0, https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fpatchwork.ozlabs.org%2Fproject%2Flinuxppc-dev%2Fpatch%2F1FD36D52828D2506%2B20231218031309.2063-1-luming.yu%40shingroup.cn%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C35a08ca9a81f4c6ff8ce08dcd3c73555%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638618099770819779%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=0WBSUlpAbL6EMdPEAtJv1HUHkbeUjjUcP98wYf9IxM4%3D&reserved=0 and the entry-common.h is as follows: [root@localhost linux]# cat arch/powerpc/include/asm/entry-common.h /* SPDX-License-Identifier: GPL-2.0 */ #ifndef ARCH_POWERPC_ENTRY_COMMON_H #define ARCH_POWERPC_ENTRY_COMMON_H #include static inline void arch_exit_to_user_mode_prepare(struct pt_regs *regs, unsigned long ti_work) { if (ti_work & _TIF_USER_RETURN_NOTIFY) fire_user_return_notifiers(); } #define arch_exit_to_user_mode_prepare arch_exit_to_user_mode_prepare #endif As you could see , it looks irrelevant. And same as with PPC32, when I build P
Re: [PATCH 1/2] powerpc/entry: convert to common and generic entry
Le 13/09/2024 à 03:40, Luming Yu a écrit : On Thu, Sep 12, 2024 at 12:23:29PM +0200, Christophe Leroy wrote: Le 12/09/2024 à 10:24, Luming Yu a écrit : From: Yu Luming convert powerpc entry code in syscall and fault to use syscall_work and irqentry_state as well as common calls from generic entry infrastructure. Signed-off-by: Luming Yu --- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/hw_irq.h | 5 + arch/powerpc/include/asm/processor.h | 6 ++ arch/powerpc/include/asm/syscall.h | 5 + arch/powerpc/include/asm/thread_info.h | 1 + arch/powerpc/kernel/syscall.c | 6 +- arch/powerpc/mm/fault.c| 5 + 7 files changed, 28 insertions(+), 1 deletion(-) There is another build problem: CC kernel/entry/common.o kernel/entry/common.c: In function 'irqentry_exit': kernel/entry/common.c:335:21: error: implicit declaration of function 'regs_irqs_disabled'; did you mean 'raw_irqs_disabled'? [-Werror=implicit-function-declaration] 335 | } else if (!regs_irqs_disabled(regs)) { | ^~ | raw_irqs_disabled You have put regs_irqs_disabled() in a section dedicated to PPC64, so it fails on PPC32. After fixing this problem and providing an empty asm/entry-common.h it is now possible to build the kernel. But that's not enough, the board is stuck after: ... [2.871391] Freeing unused kernel image (initmem) memory: 1228K [2.877990] Run /init as init process Thanks for these questions. :-) I haven't gotten chance to run it in ppc32 qemu. the common syscall trace enter lost this hunk - if (!is_32bit_task()) - audit_syscall_entry(regs->gpr[0], regs->gpr[3], regs->gpr[4], - regs->gpr[5], regs->gpr[6]); - else - audit_syscall_entry(regs->gpr[0], - regs->gpr[3] & 0x, - regs->gpr[4] & 0x, - regs->gpr[5] & 0x, - regs->gpr[6] & 0x); which I don't understand whether we need a arch callbacks for it. I don't thing so. As far as I can see, audit_syscall_entry() is called by syscall_enter_audit() in kernel/entry/common.c And the masking of arguments based on is_32bit_task() is done in syscall_get_arguments() with is called by syscall_enter_audit() just before calling audit_syscall_entry() and which is an arch callback that does the same as the removed hunk. Before I sent out the RFC patch set, the very limited compile and boot test goes well with a ppc64 qemu VM. Surely, there will be a lot of test, debug and following up patch set update that is necessary to make it a complete convert. Even on ppc64 it doesn't build, at the first place because arch/powerpc/include/asm/entry-common.h is missing in your patch. Did you forget to 'git add' it ? And same as with PPC32, when I build PPC64 with an empty asm/entry-common.h, it doesn't work. So, I guess you had some needed code in that file and you have to send it.
Re: [PATCH 1/2] powerpc/vpa_pmu: Add interface to expose vpa counters via perf
Le 28/08/2024 à 12:21, Kajol Jain a écrit : The pseries Shared Processor Logical Partition(SPLPAR) machines can retrieve a log of dispatch and preempt events from the hypervisor using data from Disptach Trace Log(DTL) buffer. With this information, user can retrieve when and why each dispatch & preempt has occurred. Added an interface to expose the Virtual Processor Area(VPA) DTL counters via perf. The following events are available and exposed in sysfs: vpa_dtl/dtl_cede/ - Trace voluntary (OS initiated) virtual processor waits vpa_dtl/dtl_preempt/ - Trace time slice preempts vpa_dtl/dtl_fault/ - Trace virtual partition memory page faults. vpa_dtl/dtl_all/ - Trace all (dtl_cede/dtl_preempt/dtl_fault) Added interface defines supported event list, config fields for the event attributes and their corresponding bit values which are exported via sysfs. User could use the standard perf tool to access perf events exposed via vpa-dtl pmu. The VPA DTL PMU counters do not interrupt on overflow or generate any PMI interrupts. Therefore, the kernel needs to poll the counters, added hrtimer code to do that. The timer interval can be provided by user via sample_period field in nano seconds. Result on power10 SPLPAR system with 656 cpu threads. In the below perf record command with vpa_dtl pmu, -c option is used to provide sample_period whch corresponding to 10ns i.e; 1sec and the workload time is also 1 second, hence we are getting 656 samples: [command] perf record -a -R -e vpa_dtl/dtl_all/ -c 10 sleep 1 [ perf record: Woken up 1 times to write data ] [ perf record: Captured and wrote 0.828 MB perf.data (656 samples) ] There is one hrtimer added per vpa-dtl pmu thread. Code added to handle addition of dtl buffer data in the raw sample. Since DTL does not provide IP address for a sample and it just have traces on reason of dispatch/preempt, we directly saving DTL buffer data to perf.data file as raw sample. For each hrtimer restart call, interface will dump all the new dtl entries added to dtl buffer as a raw sample. To ensure there are no other conflicting dtl users (example: debugfs dtl or /proc/powerpc/vcpudispatch_stats), interface added code to use "down_write_trylock" call to take the dtl_access_lock. The dtl_access_lock is defined in dtl.h file. Also added global reference count variable called "dtl_global_refc", to ensure dtl data can be captured per-cpu. Code also added global lock called "dtl_global_lock" to avoid race condition. Signed-off-by: Kajol Jain --- Notes: - Made code changes on top of recent fix sent by Michael Ellerman. Link to the patch: https://patchwork.ozlabs.org/project/linuxppc-dev/patch/20240819122401.513203-1-...@ellerman.id.au/ arch/powerpc/perf/Makefile | 2 +- arch/powerpc/perf/vpa-pmu.c | 469 include/linux/cpuhotplug.h | 1 + 3 files changed, 471 insertions(+), 1 deletion(-) create mode 100644 arch/powerpc/perf/vpa-pmu.c Seems like it doesn't build on PPC64: arch/powerpc/perf/vpa-pmu.c#L212 passing argument 1 of 'up_write' from incompatible pointer type [-Wincompatible-pointer-types] arch/powerpc/perf/vpa-pmu.c#L261 passing argument 1 of 'down_write_trylock' from incompatible pointer type [-Wincompatible-pointer-types] arch/powerpc/perf/vpa-pmu.c#L402 passing argument 1 of 'up_write' from incompatible pointer type [-Wincompatible-pointer-types]
[RFC PATCH] powerpc/vdso: Should VDSO64 functions be flagged as functions like VDSO32 ?
On powerpc64 as shown below by readelf, vDSO functions symbols have type NOTYPE. $ powerpc64-linux-gnu-readelf -a arch/powerpc/kernel/vdso/vdso64.so.dbg ELF Header: Magic: 7f 45 4c 46 02 02 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, big endian Version: 1 (current) OS/ABI:UNIX - System V ABI Version: 0 Type: DYN (Shared object file) Machine: PowerPC64 Version: 0x1 ... Symbol table '.dynsym' contains 12 entries: Num:Value Size TypeBind Vis Ndx Name ... 1: 052484 NOTYPE GLOBAL DEFAULT8 __[...]@@LINUX_2.6.15 ... 4: 0 OBJECT GLOBAL DEFAULT ABS LINUX_2.6.15 5: 06c048 NOTYPE GLOBAL DEFAULT8 __[...]@@LINUX_2.6.15 Symbol table '.symtab' contains 56 entries: Num:Value Size TypeBind Vis Ndx Name ... 45: 0 OBJECT GLOBAL DEFAULT ABS LINUX_2.6.15 46: 06c048 NOTYPE GLOBAL DEFAULT8 __kernel_getcpu 47: 052484 NOTYPE GLOBAL DEFAULT8 __kernel_clock_getres To overcome that, commit ba83b3239e65 ("selftests: vDSO: fix vDSO symbols lookup for powerpc64") was proposed to make selftests also look for NOTYPE symbols, but is it the correct fix ? VDSO32 functions are flagged as functions, why not VDSO64 functions ? Is it because VDSO functions are not traditional C functions using the standard API ? But it is exactly the same for VDSO32 functions, allthough they are flagged as functions. So lets flag them as functions and revert the selftest change. What's your opinion on that ? It predates git kernel history and both VDSO32 and VDSO64 were brough by arch/ppc64/ with that difference already. Signed-off-by: Christophe Leroy --- commit ba83b3239e65 is in random git tree at the moment : https://git.kernel.org/pub/scm/linux/kernel/git/crng/random.git/commit/?id=ba83b3239e657469709d15dcea5f9b65bf9dbf34 On the list at : https://lore.kernel.org/lkml/fc1a0862516b1e11b336d409f2cb8aab10a97337.1725020674.git.christophe.le...@csgroup.eu/T/#u --- arch/powerpc/include/asm/vdso.h | 1 + tools/testing/selftests/vDSO/parse_vdso.c | 3 +-- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/include/asm/vdso.h b/arch/powerpc/include/asm/vdso.h index 7650b6ce14c8..8d972bc98b55 100644 --- a/arch/powerpc/include/asm/vdso.h +++ b/arch/powerpc/include/asm/vdso.h @@ -25,6 +25,7 @@ int vdso_getcpu_init(void); #ifdef __VDSO64__ #define V_FUNCTION_BEGIN(name) \ .globl name;\ + .type name,@function; \ name: \ #define V_FUNCTION_END(name) \ diff --git a/tools/testing/selftests/vDSO/parse_vdso.c b/tools/testing/selftests/vDSO/parse_vdso.c index d9ccc5acac18..4ae417372e9e 100644 --- a/tools/testing/selftests/vDSO/parse_vdso.c +++ b/tools/testing/selftests/vDSO/parse_vdso.c @@ -216,8 +216,7 @@ void *vdso_sym(const char *version, const char *name) ELF(Sym) *sym = &vdso_info.symtab[chain]; /* Check for a defined global or weak function w/ right name. */ - if (ELF64_ST_TYPE(sym->st_info) != STT_FUNC && - ELF64_ST_TYPE(sym->st_info) != STT_NOTYPE) + if (ELF64_ST_TYPE(sym->st_info) != STT_FUNC) continue; if (ELF64_ST_BIND(sym->st_info) != STB_GLOBAL && ELF64_ST_BIND(sym->st_info) != STB_WEAK) -- 2.44.0
Re: [PATCH 1/2] powerpc/entry: convert to common and generic entry
Le 12/09/2024 à 10:24, Luming Yu a écrit : From: Yu Luming convert powerpc entry code in syscall and fault to use syscall_work and irqentry_state as well as common calls from generic entry infrastructure. Signed-off-by: Luming Yu --- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/hw_irq.h | 5 + arch/powerpc/include/asm/processor.h | 6 ++ arch/powerpc/include/asm/syscall.h | 5 + arch/powerpc/include/asm/thread_info.h | 1 + arch/powerpc/kernel/syscall.c | 6 +- arch/powerpc/mm/fault.c| 5 + 7 files changed, 28 insertions(+), 1 deletion(-) There is another build problem: CC kernel/entry/common.o kernel/entry/common.c: In function 'irqentry_exit': kernel/entry/common.c:335:21: error: implicit declaration of function 'regs_irqs_disabled'; did you mean 'raw_irqs_disabled'? [-Werror=implicit-function-declaration] 335 | } else if (!regs_irqs_disabled(regs)) { | ^~ | raw_irqs_disabled You have put regs_irqs_disabled() in a section dedicated to PPC64, so it fails on PPC32. After fixing this problem and providing an empty asm/entry-common.h it is now possible to build the kernel. But that's not enough, the board is stuck after: ... [2.871391] Freeing unused kernel image (initmem) memory: 1228K [2.877990] Run /init as init process Christophe
Re: [PATCH 1/2] powerpc/entry: convert to common and generic entry
Le 12/09/2024 à 10:24, Luming Yu a écrit : From: Yu Luming convert powerpc entry code in syscall and fault to use syscall_work and irqentry_state as well as common calls from generic entry infrastructure. Signed-off-by: Luming Yu --- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/hw_irq.h | 5 + arch/powerpc/include/asm/processor.h | 6 ++ arch/powerpc/include/asm/syscall.h | 5 + arch/powerpc/include/asm/thread_info.h | 1 + arch/powerpc/kernel/syscall.c | 6 +- arch/powerpc/mm/fault.c| 5 + 7 files changed, 28 insertions(+), 1 deletion(-) asm/entry-common.h is missing, this patch doesn't build.
Re: [PATCH 1/2] powerpc/entry: convert to common and generic entry
Le 12/09/2024 à 10:24, Luming Yu a écrit : From: Yu Luming convert powerpc entry code in syscall and fault to use syscall_work and irqentry_state as well as common calls from generic entry infrastructure. Could you add more description about the change ? When I look at x86, riscv or s390 commits for the same thing, they tell a lot more: Commit 27d6b4d14f5c ("x86/entry: Use generic syscall entry function") Commit f0bddf50586d ("riscv: entry: Convert to generic entry") Commit 56e62a737028 ("s390: convert to generic entry") Can you elso provide some benchmark comparisons, at least using the null_syscall selftest tools/testing/selftests/powerpc/benchmarks/null_syscall.c Signed-off-by: Luming Yu --- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/hw_irq.h | 5 + arch/powerpc/include/asm/processor.h | 6 ++ arch/powerpc/include/asm/syscall.h | 5 + arch/powerpc/include/asm/thread_info.h | 1 + arch/powerpc/kernel/syscall.c | 6 +- arch/powerpc/mm/fault.c| 5 + 7 files changed, 28 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index e21f72bcb61f..e94e7e4bfd40 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -202,6 +202,7 @@ config PPC select GENERIC_IRQ_SHOW_LEVEL select GENERIC_PCI_IOMAPif PCI select GENERIC_PTDUMP +select GENERIC_ENTRY select GENERIC_SMP_IDLE_THREAD select GENERIC_TIME_VSYSCALL select GENERIC_VDSO_TIME_NS diff --git a/arch/powerpc/include/asm/hw_irq.h b/arch/powerpc/include/asm/hw_irq.h index 317659fdeacf..a3d591784c95 100644 --- a/arch/powerpc/include/asm/hw_irq.h +++ b/arch/powerpc/include/asm/hw_irq.h @@ -216,6 +216,11 @@ static inline bool arch_irqs_disabled(void) return arch_irqs_disabled_flags(arch_local_save_flags()); } +/*common entry*/ +static __always_inline bool regs_irqs_disabled(struct pt_regs *regs) +{ + return arch_irqs_disabled(); +} static inline void set_pmi_irq_pending(void) { /* diff --git a/arch/powerpc/include/asm/processor.h b/arch/powerpc/include/asm/processor.h index b2c51d337e60..1292282f8b0e 100644 --- a/arch/powerpc/include/asm/processor.h +++ b/arch/powerpc/include/asm/processor.h @@ -383,6 +383,12 @@ int validate_sp(unsigned long sp, struct task_struct *p); int validate_sp_size(unsigned long sp, struct task_struct *p, unsigned long nbytes); +/*for common entry*/ +static __always_inline bool on_thread_stack(void) +{ + return validate_sp(current_stack_pointer, current); I don't understand. Other architectures have something more simple for on_thread_stack(). Also, validate_sp() will also return true when on irq_stack or emergency stack. +} + /* * Prefetch macros. */ diff --git a/arch/powerpc/include/asm/syscall.h b/arch/powerpc/include/asm/syscall.h index 3dd36c5e334a..0e94806c7bfe 100644 --- a/arch/powerpc/include/asm/syscall.h +++ b/arch/powerpc/include/asm/syscall.h @@ -119,4 +119,9 @@ static inline int syscall_get_arch(struct task_struct *task) else return AUDIT_ARCH_PPC64; } + +static inline bool arch_syscall_is_vdso_sigreturn(struct pt_regs *regs) +{ + return false; +} #endif/* _ASM_SYSCALL_H */ diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h index 47e226032f9c..c52ca3aaebb5 100644 --- a/arch/powerpc/include/asm/thread_info.h +++ b/arch/powerpc/include/asm/thread_info.h @@ -58,6 +58,7 @@ struct thread_info { unsigned intcpu; #endif unsigned long local_flags;/* private flags for thread */ + unsigned long syscall_work; #ifdef CONFIG_LIVEPATCH_64 unsigned long *livepatch_sp; #endif diff --git a/arch/powerpc/kernel/syscall.c b/arch/powerpc/kernel/syscall.c index 77fedb190c93..cbf0510ed10e 100644 --- a/arch/powerpc/kernel/syscall.c +++ b/arch/powerpc/kernel/syscall.c @@ -3,6 +3,7 @@ #include #include #include +#include #include #include @@ -131,7 +132,7 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0) * and the test against NR_syscalls will fail and the return * value to be used is in regs->gpr[3]. */ - r0 = do_syscall_trace_enter(regs); + syscall_enter_from_user_mode(regs, r0); shouldn't this be: r0 = syscall_enter_from_user_mode(regs, r0); if (unlikely(r0 >= NR_syscalls)) return regs->gpr[3]; @@ -185,5 +186,8 @@ notrace long system_call_exception(struct pt_regs *regs, unsigned long r0) */ choose_random_kstack_offset(mftb()); + /*common entry*/ + syscall_exit_to_user_mode(regs); + This seems to do a lot. Isn't there stuff that was previously done by powerpc and need
Re: [PATCH RFC v3 1/2] mm: Add personality flag to limit address to 47 bits
diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h index 49796b7756af..cd3b8c154d9b 100644 --- a/include/uapi/linux/personality.h +++ b/include/uapi/linux/personality.h @@ -22,6 +22,7 @@ enum { WHOLE_SECONDS = 0x200, STICKY_TIMEOUTS = 0x400, ADDR_LIMIT_3GB =0x800, + ADDR_LIMIT_47BIT = 0x1000, }; I wonder if ADDR_LIMIT_128T would be clearer? I don't follow, what does 128T represent? 128T is 128 Terabytes, that's the maximum size achievable with a 47BIT address, that naming would be more consistant with the ADDR_LIMIT_3GB just above that means a 3 Gigabytes limit. Christophe
Re: No rule to make target 'arch/powerpc/boot/dtbImage.ps3', needed by 'arch/powerpc/boot/zImage'.
Le 09/09/2024 à 21:25, Naresh Kamboju a écrit : The Powerpc cell_defconfig and mpc83xx_defconfig builds failed on the Linux next-20240909 due to following build warnings / errors with gcc-13 and clang-19. First seen on next-20240909 Good: next-20240906 BAD: next-20240909 Reported-by: Linux Kernel Functional Testing build log: make[3]: *** No rule to make target 'arch/powerpc/boot/dtbImage.ps3', needed by 'arch/powerpc/boot/zImage'. make[3]: Target 'arch/powerpc/boot/zImage' not remade because of errors. See https://lore.kernel.org/linuxppc-dev/b154ab25-70f6-46cd-99db-ccfbe3e13...@csgroup.eu/T/#m7cc489243ce5a17af97ff8ec7cc15c663565b6fd Christophe Build Log links, - https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fqa-reports.linaro.org%2Flkft%2Flinux-next-master%2Fbuild%2Fnext-20240909%2Ftestrun%2F25078675%2Fsuite%2Fbuild%2Ftest%2Fclang-19-cell_defconfig%2Flog&data=05%7C02%7Cchristophe.leroy2%40cs-soprasteria.com%7Cbea1fddc11ef4588817208dcd118fdb1%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638615152486474122%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=k4QsFvSrqrtJkwe5i8qvTetu941J%2FiokAMEDIy1hgO4%3D&reserved=0 Build failed comparison: - https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fqa-reports.linaro.org%2Flkft%2Flinux-next-master%2Fbuild%2Fnext-20240909%2Ftestrun%2F25078675%2Fsuite%2Fbuild%2Ftest%2Fclang-19-cell_defconfig%2Fhistory%2F&data=05%7C02%7Cchristophe.leroy2%40cs-soprasteria.com%7Cbea1fddc11ef4588817208dcd118fdb1%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638615152486482765%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=hZJF6oi09QQnOcjWlPkn5YQw3L33uG5vobqZX%2FJzW%2Fc%3D&reserved=0 metadata: git describe: next-20240909 git repo: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgitlab.com%2FLinaro%2Flkft%2Fmirrors%2Fnext%2Flinux-next&data=05%7C02%7Cchristophe.leroy2%40cs-soprasteria.com%7Cbea1fddc11ef4588817208dcd118fdb1%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638615152486487967%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=FIZK7ic0Dwbnt8zclmji5w2mTS0konX%2Bh6izCQ2QoqQ%3D&reserved=0 git sha: 100cc857359b5d731407d1038f7e76cd0e871d94 kernel config: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstorage.tuxsuite.com%2Fpublic%2Flinaro%2Flkft%2Fbuilds%2F2lpXzh3wwbuC6nYpMV2nPNA0IpF%2Fconfig&data=05%7C02%7Cchristophe.leroy2%40cs-soprasteria.com%7Cbea1fddc11ef4588817208dcd118fdb1%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638615152487540129%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=KPpD9d%2FM2gxLqjaVIsN26jwolSkzetd%2B0VGVMaV4Mwo%3D&reserved=0 build url: https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstorage.tuxsuite.com%2Fpublic%2Flinaro%2Flkft%2Fbuilds%2F2lpXzh3wwbuC6nYpMV2nPNA0IpF%2F&data=05%7C02%7Cchristophe.leroy2%40cs-soprasteria.com%7Cbea1fddc11ef4588817208dcd118fdb1%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638615152487548564%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=dS0BYsDDrcnW7fF2KeUZFBvFKnMKLz36nLWt%2BmeqIIQ%3D&reserved=0 toolchain: gcc-13, clang-19 and clang-nightly config: cell_defconfig and mpc83xx_defconfig Steps to reproduce: - - # tuxmake --runtime podman --target-arch powerpc --toolchain clang-19 --kconfig cell_defconfig LLVM_IAS=0 - # tuxmake --runtime podman --target-arch powerpc --toolchain gcc-13 --kconfig mpc83xx_defconfig -- Linaro LKFT https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flkft.linaro.org%2F&data=05%7C02%7Cchristophe.leroy2%40cs-soprasteria.com%7Cbea1fddc11ef4588817208dcd118fdb1%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638615152487553541%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=Pzu3tW7FdI%2F7FYj%2BUSz%2FTfENPPGRZUEf%2FsXcaSpPXB8%3D&reserved=0
Re: linux-next: build failure after merge of the powerpc tree
Le 09/09/2024 à 18:23, Masahiro Yamada a écrit : On Mon, Sep 9, 2024 at 11:58 PM Stephen Rothwell wrote: Hi Christophe, On Mon, 9 Sep 2024 16:22:26 +0200 Christophe Leroy wrote: Le 09/09/2024 à 12:09, Stephen Rothwell a écrit : Hi all, After merging the powerpc tree, today's linux-next build (powerpc ppc44x_defconfig) failed like this: make[3]: *** No rule to make target 'arch/powerpc/boot/treeImage.ebony', needed by 'arch/powerpc/boot/zImage'. Stop. make[2]: *** [/home/sfr/next/next/arch/powerpc/Makefile:236: zImage] Error 2 make[1]: *** [/home/sfr/next/next/Makefile:224: __sub-make] Error 2 make: *** [Makefile:224: __sub-make] Error 2 It is not obvious to me what change caused this, so I have just left the build broken for today. Bisected to commit e6abfb536d16 ("kbuild: split device tree build rules into scripts/Makefile.dtbs") Thanks for that. -- Cheers, Stephen Rothwell I squashed the following fix. Hopefully, it will be ok tomorrow. diff --git a/scripts/Makefile.build b/scripts/Makefile.build index 6385e7aa5dbb..8403eba15457 100644 --- a/scripts/Makefile.build +++ b/scripts/Makefile.build @@ -444,7 +444,7 @@ ifneq ($(userprogs),) include $(srctree)/scripts/Makefile.userprogs endif -ifneq ($(need-dtbslist)$(dtb-y)$(dtb-)$(filter %.dtb.o %.dtbo.o,$(targets)),) +ifneq ($(need-dtbslist)$(dtb-y)$(dtb-)$(filter %.dtb %.dtb.o %.dtbo.o,$(targets)),) include $(srctree)/scripts/Makefile.dtbs endif The build of ppc44x_defconfig is ok with this change on top of next-20240909
Re: linux-next: build failure after merge of the powerpc tree
Le 09/09/2024 à 12:09, Stephen Rothwell a écrit : Hi all, After merging the powerpc tree, today's linux-next build (powerpc ppc44x_defconfig) failed like this: make[3]: *** No rule to make target 'arch/powerpc/boot/treeImage.ebony', needed by 'arch/powerpc/boot/zImage'. Stop. make[2]: *** [/home/sfr/next/next/arch/powerpc/Makefile:236: zImage] Error 2 make[1]: *** [/home/sfr/next/next/Makefile:224: __sub-make] Error 2 make: *** [Makefile:224: __sub-make] Error 2 It is not obvious to me what change caused this, so I have just left the build broken for today. Bisected to commit e6abfb536d16 ("kbuild: split device tree build rules into scripts/Makefile.dtbs") Christophe
[PATCH] powerpc: Add __must_check to set_memory_...()
After the following powerpc commits, all calls to set_memory_...() functions check returned value. - Commit 8f17bd2f4196 ("powerpc: Handle error in mark_rodata_ro() and mark_initmem_nx()") - Commit f7f18e30b468 ("powerpc/kprobes: Handle error returned by set_memory_rox()") - Commit 009cf11d4aab ("powerpc: Don't ignore errors from set_memory_{n}p() in __kernel_map_pages()") - Commit 9cbacb834b4a ("powerpc: Don't ignore errors from set_memory_{n}p() in __kernel_map_pages()") - Commit 78cb0945f714 ("powerpc: Handle error in mark_rodata_ro() and mark_initmem_nx()") All calls in core parts of the kernel also always check returned value, can be looked at with following query: $ git grep -w -e set_memory_ro -e set_memory_rw -e set_memory_x -e set_memory_nx -e set_memory_rox `find . -maxdepth 1 -type d | grep -v arch | grep /` It is now possible to flag those functions with __must_check to make sure no new unchecked call it added. Link: https://github.com/KSPP/linux/issues/7 Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/set_memory.h | 14 +++--- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/arch/powerpc/include/asm/set_memory.h b/arch/powerpc/include/asm/set_memory.h index 9a025b776a4b..9c8d5747755d 100644 --- a/arch/powerpc/include/asm/set_memory.h +++ b/arch/powerpc/include/asm/set_memory.h @@ -12,37 +12,37 @@ int change_memory_attr(unsigned long addr, int numpages, long action); -static inline int set_memory_ro(unsigned long addr, int numpages) +static inline int __must_check set_memory_ro(unsigned long addr, int numpages) { return change_memory_attr(addr, numpages, SET_MEMORY_RO); } -static inline int set_memory_rw(unsigned long addr, int numpages) +static inline int __must_check set_memory_rw(unsigned long addr, int numpages) { return change_memory_attr(addr, numpages, SET_MEMORY_RW); } -static inline int set_memory_nx(unsigned long addr, int numpages) +static inline int __must_check set_memory_nx(unsigned long addr, int numpages) { return change_memory_attr(addr, numpages, SET_MEMORY_NX); } -static inline int set_memory_x(unsigned long addr, int numpages) +static inline int __must_check set_memory_x(unsigned long addr, int numpages) { return change_memory_attr(addr, numpages, SET_MEMORY_X); } -static inline int set_memory_np(unsigned long addr, int numpages) +static inline int __must_check set_memory_np(unsigned long addr, int numpages) { return change_memory_attr(addr, numpages, SET_MEMORY_NP); } -static inline int set_memory_p(unsigned long addr, int numpages) +static inline int __must_check set_memory_p(unsigned long addr, int numpages) { return change_memory_attr(addr, numpages, SET_MEMORY_P); } -static inline int set_memory_rox(unsigned long addr, int numpages) +static inline int __must_check set_memory_rox(unsigned long addr, int numpages) { return change_memory_attr(addr, numpages, SET_MEMORY_ROX); } -- 2.44.0
[PATCH] set_memory: Add __must_check to generic stubs
Following query shows that architectures that don't provide asm/set_memory.h don't use set_memory_...() functions. $ git grep set_memory_ alpha arc csky hexagon loongarch m68k microblaze mips nios2 openrisc parisc sh sparc um xtensa Following query shows that all core users of set_memory_...() functions always take returned value into account: $ git grep -w -e set_memory_ro -e set_memory_rw -e set_memory_x -e set_memory_nx -e set_memory_rox `find . -maxdepth 1 -type d | grep -v arch | grep /` set_memory_...() functions can fail, leaving the memory attributes unchanged. Make sure all callers check the returned code. Link: https://github.com/KSPP/linux/issues/7 Signed-off-by: Christophe Leroy --- include/linux/set_memory.h | 8 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/include/linux/set_memory.h b/include/linux/set_memory.h index 95ac8398ee72..e7aec20fb44f 100644 --- a/include/linux/set_memory.h +++ b/include/linux/set_memory.h @@ -8,10 +8,10 @@ #ifdef CONFIG_ARCH_HAS_SET_MEMORY #include #else -static inline int set_memory_ro(unsigned long addr, int numpages) { return 0; } -static inline int set_memory_rw(unsigned long addr, int numpages) { return 0; } -static inline int set_memory_x(unsigned long addr, int numpages) { return 0; } -static inline int set_memory_nx(unsigned long addr, int numpages) { return 0; } +static inline int __must_check set_memory_ro(unsigned long addr, int numpages) { return 0; } +static inline int __must_check set_memory_rw(unsigned long addr, int numpages) { return 0; } +static inline int __must_check set_memory_x(unsigned long addr, int numpages) { return 0; } +static inline int __must_check set_memory_nx(unsigned long addr, int numpages) { return 0; } #endif #ifndef set_memory_rox -- 2.44.0
Re: [PATCH 2/2] Fixup for 3279be36b671 ("powerpc/vdso: Wire up getrandom() vDSO implementation on VDSO32")
Le 07/09/2024 à 16:35, Jason A. Donenfeld a écrit : On Fri, Sep 06, 2024 at 08:54:49PM +0200, Jason A. Donenfeld wrote: On Fri, Sep 06, 2024 at 05:14:43PM +0200, Christophe Leroy wrote: Le 06/09/2024 à 16:46, Jason A. Donenfeld a écrit : On Fri, Sep 06, 2024 at 04:26:32PM +0200, Christophe Leroy wrote: On the long run I wonder if we should try to find a more generic solution for getrandom instead of requiring each architecture to handle it. On gettimeofday the selection of the right page is embeded in the generic part, see for instance : static __maybe_unused __kernel_old_time_t __cvdso_time_data(const struct vdso_data *vd, __kernel_old_time_t *time) { __kernel_old_time_t t; if (IS_ENABLED(CONFIG_TIME_NS) && vd->clock_mode == VDSO_CLOCKMODE_TIMENS) vd = __arch_get_timens_vdso_data(vd); t = READ_ONCE(vd[CS_HRES_COARSE].basetime[CLOCK_REALTIME].sec); if (time) *time = t; return t; } and powerpc just provides: static __always_inline const struct vdso_data *__arch_get_timens_vdso_data(const struct vdso_data *vd) { return (void *)vd + (1U << CONFIG_PAGE_SHIFT); } It's tempting, but maybe a bit tricky. LoongArch, for example, doesn't have this problem at all, because the layout of their vvars doesn't require it. So the vd->clock_mode access is unnecessary. Or another solution could be to put random data in a third page that is always at the same place regardless of timens ? Maybe that's the easier way, yea. Potentially wasteful, though. Indeed I just looked at Loongarch and that's exactly what they do: they have a third page after the two pages dedicated to TIME for arch specific data, and they have added getrandom data there. The third page is common to every process so it won't waste more than a few bytes. It doesn't worry me even on the older boards that only have 32 Mbytes of RAM. So yes, I may have a look at that in the future, what we have at the moment is good enough to move forward. My x86 code is kind of icky for this: static __always_inline const struct vdso_rng_data *__arch_get_vdso_rng_data(void) { if (IS_ENABLED(CONFIG_TIME_NS) && __vdso_data->clock_mode == VDSO_CLOCKMODE_TIMENS) return (void *)&__vdso_rng_data + ((void *)&__timens_vdso_data - (void *)&__vdso_data); return &__vdso_rng_data; } Doing the subtraction like that means that this is more clearly correct. But it also makes the compiler insert two jumps for the branch, and then reads the addresses of those variables and such. If I change it to: static __always_inline const struct vdso_rng_data *__arch_get_vdso_rng_data(void) { if (IS_ENABLED(CONFIG_TIME_NS) && __vdso_data->clock_mode == VDSO_CLOCKMODE_TIMENS) return (void *)&__vdso_rng_data + (3UL << CONFIG_PAGE_SHIFT); return &__vdso_rng_data; } Then there's a much nicer single `cmov` with no branching. But if I want to do that for real, I'll have to figure out what set of nice compile-time constants I can use. I haven't looked into this yet. https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Flore.kernel.org%2Fall%2F20240906190655.2777023-1-Jason%40zx2c4.com%2F&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C3ee8b35fe848434e72fd08dccf4a67ff%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638613165688600378%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=g4zcMonjJNYhwrUWeCDoL5Ri7Mbg5hVQJyZNU2zH4Pc%3D&reserved=0 Looks good. Allthough other architectures don't use defines but enums for that: arch/arm64/kernel/vdso.c-36- arch/arm64/kernel/vdso.c-37-enum vvar_pages { arch/arm64/kernel/vdso.c:38:VVAR_DATA_PAGE_OFFSET, arch/arm64/kernel/vdso.c:39:VVAR_TIMENS_PAGE_OFFSET, arch/arm64/kernel/vdso.c-40-VVAR_NR_PAGES, arch/arm64/kernel/vdso.c-41-}; -- arch/loongarch/include/asm/vdso/vdso.h-36- arch/loongarch/include/asm/vdso/vdso.h-37-enum vvar_pages { arch/loongarch/include/asm/vdso/vdso.h:38: VVAR_GENERIC_PAGE_OFFSET, arch/loongarch/include/asm/vdso/vdso.h:39: VVAR_TIMENS_PAGE_OFFSET, arch/loongarch/include/asm/vdso/vdso.h-40- VVAR_LOONGARCH_PAGES_START, arch/loongarch/include/asm/vdso/vdso.h-41- VVAR_LOONGARCH_PAGES_END = VVAR_LOONGARCH_PAGES_START + LOONGARCH_VDSO_DATA_PAGES - 1, -- arch/powerpc/kernel/vdso.c-54- arch/powerpc/kernel/vdso.c-55-enum vvar_pages { arch/powerpc/kernel/vdso.c:56: VVAR_DATA_PAGE_OFFSET, arch/powerpc/kernel/vdso.c:57: VVAR_TIMENS_PAGE_OFFSET, arch/powerpc/kernel/vdso.c-58- VVAR_NR_PAGES, arch/powerpc/kernel/vdso.c-59-}; -- arch/riscv/kernel/vdso.c-19- arch/riscv/kernel/vdso.c-20-enum vvar_pages { arch/riscv/kernel/vdso.c:21:VVAR_DATA_PAGE_OFFSET, arch/riscv/kernel/vdso.c:22:VVAR_TIMENS_PAGE_OFFSET, arch/riscv/kernel/v
Re: [PATCH 2/2] Fixup for 3279be36b671 ("powerpc/vdso: Wire up getrandom() vDSO implementation on VDSO32")
Le 06/09/2024 à 16:46, Jason A. Donenfeld a écrit : On Fri, Sep 06, 2024 at 04:26:32PM +0200, Christophe Leroy wrote: On the long run I wonder if we should try to find a more generic solution for getrandom instead of requiring each architecture to handle it. On gettimeofday the selection of the right page is embeded in the generic part, see for instance : static __maybe_unused __kernel_old_time_t __cvdso_time_data(const struct vdso_data *vd, __kernel_old_time_t *time) { __kernel_old_time_t t; if (IS_ENABLED(CONFIG_TIME_NS) && vd->clock_mode == VDSO_CLOCKMODE_TIMENS) vd = __arch_get_timens_vdso_data(vd); t = READ_ONCE(vd[CS_HRES_COARSE].basetime[CLOCK_REALTIME].sec); if (time) *time = t; return t; } and powerpc just provides: static __always_inline const struct vdso_data *__arch_get_timens_vdso_data(const struct vdso_data *vd) { return (void *)vd + (1U << CONFIG_PAGE_SHIFT); } It's tempting, but maybe a bit tricky. LoongArch, for example, doesn't have this problem at all, because the layout of their vvars doesn't require it. So the vd->clock_mode access is unnecessary. Or another solution could be to put random data in a third page that is always at the same place regardless of timens ? Maybe that's the easier way, yea. Potentially wasteful, though. Indeed I just looked at Loongarch and that's exactly what they do: they have a third page after the two pages dedicated to TIME for arch specific data, and they have added getrandom data there. The third page is common to every process so it won't waste more than a few bytes. It doesn't worry me even on the older boards that only have 32 Mbytes of RAM. So yes, I may have a look at that in the future, what we have at the moment is good enough to move forward. Christophe
Re: [PATCH 2/2] Fixup for 3279be36b671 ("powerpc/vdso: Wire up getrandom() vDSO implementation on VDSO32")
Le 06/09/2024 à 16:07, Jason A. Donenfeld a écrit : On Fri, Sep 06, 2024 at 10:33:44AM +0200, Christophe Leroy wrote: Use the new get_realdatapage macro instead of get_datapage Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/vdso/getrandom.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/vdso/getrandom.S b/arch/powerpc/kernel/vdso/getrandom.S index a957cd2b2b03..f3bbf931931c 100644 --- a/arch/powerpc/kernel/vdso/getrandom.S +++ b/arch/powerpc/kernel/vdso/getrandom.S @@ -31,7 +31,7 @@ PPC_STL r2, PPC_MIN_STKFRM + STK_GOT(r1) .cfi_rel_offset r2, PPC_MIN_STKFRM + STK_GOT #endif - get_datapager8 + get_realdatapager8, r11 addir8, r8, VDSO_RNG_DATA_OFFSET bl CFUNC(DOTSYM(\funct)) PPC_LL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1) I tested that this is working as intended on powerpc, powerpc64, and powerpc64le. Thanks for writing the patch so quickly. You are welcome. And thanks for playing up with it while I was sleeping and getting ideas too. Did you learn powerpc assembly during the night or did you know it already ? At the end I ended up with something which I think is simple enough for a backport to stable. On the long run I wonder if we should try to find a more generic solution for getrandom instead of requiring each architecture to handle it. On gettimeofday the selection of the right page is embeded in the generic part, see for instance : static __maybe_unused __kernel_old_time_t __cvdso_time_data(const struct vdso_data *vd, __kernel_old_time_t *time) { __kernel_old_time_t t; if (IS_ENABLED(CONFIG_TIME_NS) && vd->clock_mode == VDSO_CLOCKMODE_TIMENS) vd = __arch_get_timens_vdso_data(vd); t = READ_ONCE(vd[CS_HRES_COARSE].basetime[CLOCK_REALTIME].sec); if (time) *time = t; return t; } and powerpc just provides: static __always_inline const struct vdso_data *__arch_get_timens_vdso_data(const struct vdso_data *vd) { return (void *)vd + (1U << CONFIG_PAGE_SHIFT); } I know it may not be that simple for getrandom but its probably worth trying. Or another solution could be to put random data in a third page that is always at the same place regardless of timens ? Christophe
Re: [PATCH 1/2] powerpc/vdso: Fix VDSO data access when running in a non-root time namespace
Le 06/09/2024 à 14:23, Michael Ellerman a écrit : Christophe Leroy writes: When running in a non-root time namespace, the global VDSO data page is replaced by a dedicated namespace data page and the global data page is mapped next to it. Detailed explanations can be found at commit 660fd04f9317 ("lib/vdso: Prepare for time namespace support"). When it happens, __kernel_get_syscall_map and __kernel_get_tbfreq and __kernel_sync_dicache don't work anymore because they read 0 instead of the data they need. To address that, clock_mode has to be read. When it is set to VDSO_CLOCKMODE_TIMENS, it means it is a dedicated namespace data page and the global data is located on the following page. Add a macro called get_realdatapage which reads clock_mode and add PAGE_SIZE to the pointer provided by get_datapage macro when clock_mode is equal to VDSO_CLOCKMODE_TIMENS. Use this new macro instead of get_datapage macro except for time functions as they handle it internally. Fixes: 74205b3fc2ef ("powerpc/vdso: Add support for time namespaces") Signed-off-by: Christophe Leroy Oops. I guess it should also have: Cc: sta...@vger.kernel.org # v5.13+ Reported-by: Jason A. Donenfeld Closes: https://lore.kernel.org/all/ztnyqzi-nrsns...@zx2c4.com/ Jason only reported a problem with getrandom, the other three are "cherry on the cake". The bug has been there for 3 years, I'm sure it can stay 3-4 more weeks, I'm not sure there is a need to apply it in both trees. As far as I understood Jason was about to squash the fix into his tree so I was expecting him to apply patch 1 before "vDSO getrandom implementation for powerpc" patches and then squash patch 2 in place. Jason how do you want to handle this? I can put patch 1 in a topic branch that we both merge? Then you can apply patch 2 on top of that merge in your tree. Or we could both apply patch 1 to our trees, it might lead to a conflict but it wouldn't be anything drastic.
Re: [PATCH v2 7/8] execmem: add support for cache of large ROX pages
Le 26/08/2024 à 08:55, Mike Rapoport a écrit : From: "Mike Rapoport (Microsoft)" Using large pages to map text areas reduces iTLB pressure and improves performance. Extend execmem_alloc() with an ability to use PMD_SIZE'ed pages with ROX permissions as a cache for smaller allocations. Why only PMD_SIZE ? On power 8xx, PMD_SIZE is 4M and the 8xx doesn't have such a page size. When you call vmalloc() with VM_ALLOW_HUGE_VMAP you get 16k pages or 512k pages depending on the size you ask for, see function arch_vmap_pte_supported_shift() To populate the cache, a writable large page is allocated from vmalloc with VM_ALLOW_HUGE_VMAP, filled with invalid instructions and then remapped as ROX. Portions of that large page are handed out to execmem_alloc() callers without any changes to the permissions. When the memory is freed with execmem_free() it is invalidated again so that it won't contain stale instructions. The cache is enabled when an architecture sets EXECMEM_ROX_CACHE flag in definition of an execmem_range. Christophe
[PATCH 2/2] Fixup for 3279be36b671 ("powerpc/vdso: Wire up getrandom() vDSO implementation on VDSO32")
Use the new get_realdatapage macro instead of get_datapage Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/vdso/getrandom.S | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/vdso/getrandom.S b/arch/powerpc/kernel/vdso/getrandom.S index a957cd2b2b03..f3bbf931931c 100644 --- a/arch/powerpc/kernel/vdso/getrandom.S +++ b/arch/powerpc/kernel/vdso/getrandom.S @@ -31,7 +31,7 @@ PPC_STL r2, PPC_MIN_STKFRM + STK_GOT(r1) .cfi_rel_offset r2, PPC_MIN_STKFRM + STK_GOT #endif - get_datapager8 + get_realdatapager8, r11 addir8, r8, VDSO_RNG_DATA_OFFSET bl CFUNC(DOTSYM(\funct)) PPC_LL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1) -- 2.44.0
[PATCH 1/2] powerpc/vdso: Fix VDSO data access when running in a non-root time namespace
When running in a non-root time namespace, the global VDSO data page is replaced by a dedicated namespace data page and the global data page is mapped next to it. Detailed explanations can be found at commit 660fd04f9317 ("lib/vdso: Prepare for time namespace support"). When it happens, __kernel_get_syscall_map and __kernel_get_tbfreq and __kernel_sync_dicache don't work anymore because they read 0 instead of the data they need. To address that, clock_mode has to be read. When it is set to VDSO_CLOCKMODE_TIMENS, it means it is a dedicated namespace data page and the global data is located on the following page. Add a macro called get_realdatapage which reads clock_mode and add PAGE_SIZE to the pointer provided by get_datapage macro when clock_mode is equal to VDSO_CLOCKMODE_TIMENS. Use this new macro instead of get_datapage macro except for time functions as they handle it internally. Fixes: 74205b3fc2ef ("powerpc/vdso: Add support for time namespaces") Signed-off-by: Christophe Leroy --- arch/powerpc/include/asm/vdso_datapage.h | 15 +++ arch/powerpc/kernel/asm-offsets.c| 2 ++ arch/powerpc/kernel/vdso/cacheflush.S| 2 +- arch/powerpc/kernel/vdso/datapage.S | 4 ++-- 4 files changed, 20 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/include/asm/vdso_datapage.h b/arch/powerpc/include/asm/vdso_datapage.h index e17500c5237e..248dee138f7b 100644 --- a/arch/powerpc/include/asm/vdso_datapage.h +++ b/arch/powerpc/include/asm/vdso_datapage.h @@ -113,6 +113,21 @@ extern struct vdso_arch_data *vdso_data; addi\ptr, \ptr, (_vdso_datapage - 999b)@l .endm +#include +#include + +.macro get_realdatapage ptr scratch + get_datapage \ptr +#ifdef CONFIG_TIME_NS + lwz \scratch, VDSO_CLOCKMODE_OFFSET(\ptr) + xoris \scratch, \scratch, VDSO_CLOCKMODE_TIMENS@h + xori\scratch, \scratch, VDSO_CLOCKMODE_TIMENS@l + cntlzw \scratch, \scratch + rlwinm \scratch, \scratch, PAGE_SHIFT - 5, 1 << PAGE_SHIFT + add \ptr, \ptr, \scratch +#endif +.endm + #endif /* __ASSEMBLY__ */ #endif /* __KERNEL__ */ diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c index eedb2e04c785..131a8cc10dbe 100644 --- a/arch/powerpc/kernel/asm-offsets.c +++ b/arch/powerpc/kernel/asm-offsets.c @@ -347,6 +347,8 @@ int main(void) #else OFFSET(CFG_SYSCALL_MAP32, vdso_arch_data, syscall_map); #endif + OFFSET(VDSO_CLOCKMODE_OFFSET, vdso_arch_data, data[0].clock_mode); + DEFINE(VDSO_CLOCKMODE_TIMENS, VDSO_CLOCKMODE_TIMENS); #ifdef CONFIG_BUG DEFINE(BUG_ENTRY_SIZE, sizeof(struct bug_entry)); diff --git a/arch/powerpc/kernel/vdso/cacheflush.S b/arch/powerpc/kernel/vdso/cacheflush.S index 0085ae464dac..3b2479bd2f9a 100644 --- a/arch/powerpc/kernel/vdso/cacheflush.S +++ b/arch/powerpc/kernel/vdso/cacheflush.S @@ -30,7 +30,7 @@ END_FTR_SECTION_IFSET(CPU_FTR_COHERENT_ICACHE) #ifdef CONFIG_PPC64 mflrr12 .cfi_register lr,r12 - get_datapager10 + get_realdatapager10, r11 mtlrr12 .cfi_restore lr #endif diff --git a/arch/powerpc/kernel/vdso/datapage.S b/arch/powerpc/kernel/vdso/datapage.S index db8e167f0166..2b19b6201a33 100644 --- a/arch/powerpc/kernel/vdso/datapage.S +++ b/arch/powerpc/kernel/vdso/datapage.S @@ -28,7 +28,7 @@ V_FUNCTION_BEGIN(__kernel_get_syscall_map) mflrr12 .cfi_register lr,r12 mr. r4,r3 - get_datapager3 + get_realdatapager3, r11 mtlrr12 #ifdef __powerpc64__ addir3,r3,CFG_SYSCALL_MAP64 @@ -52,7 +52,7 @@ V_FUNCTION_BEGIN(__kernel_get_tbfreq) .cfi_startproc mflrr12 .cfi_register lr,r12 - get_datapager3 + get_realdatapager3, r11 #ifndef __powerpc64__ lwz r4,(CFG_TB_TICKS_PER_SEC + 4)(r3) #endif -- 2.44.0
Re: [PATCH v5 4/5] powerpc/vdso: Wire up getrandom() vDSO implementation on VDSO32
Hi Jason, Le 06/09/2024 à 05:24, Jason A. Donenfeld a écrit : On Fri, Sep 06, 2024 at 04:48:28AM +0200, Jason A. Donenfeld wrote: On Thu, Sep 05, 2024 at 10:41:40PM +0200, Jason A. Donenfeld wrote: On Thu, Sep 05, 2024 at 06:13:29PM +0200, Jason A. Donenfeld wrote: +/* + * The macro sets two stack frames, one for the caller and one for the callee + * because there are no requirement for the caller to set a stack frame when + * calling VDSO so it may have omitted to set one, especially on PPC64 + */ + +.macro cvdso_call funct + .cfi_startproc + PPC_STLUr1, -PPC_MIN_STKFRM(r1) + .cfi_adjust_cfa_offset PPC_MIN_STKFRM + mflrr0 + PPC_STLUr1, -PPC_MIN_STKFRM(r1) + .cfi_adjust_cfa_offset PPC_MIN_STKFRM + PPC_STL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1) + .cfi_rel_offset lr, PPC_MIN_STKFRM + PPC_LR_STKOFF + get_datapager8 + addir8, r8, VDSO_RNG_DATA_OFFSET + bl CFUNC(DOTSYM(\funct)) + PPC_LL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1) + cmpwi r3, 0 + mtlrr0 + addir1, r1, 2 * PPC_MIN_STKFRM + .cfi_restore lr + .cfi_def_cfa_offset 0 + crclr so + bgelr+ + crset so + neg r3, r3 + blr + .cfi_endproc +.endm Can you figure out what's going on and send a fix, which I'll squash into this commit? This doesn't work, but I wonder if something like it is what we want. I need to head out for the day, but here's what I've got. It's all wrong but might be of interest. Oh, I just got one small detail wrong before. The below actually works, and uses the same strategy as on arm64. Let me know if you'd like me to fix up this commit with the below patch, or if you have another way you'd like to go about it. And here's the much shorter version in assembly, which maybe you prefer. Also works, and is a bit less invasive than the other thing. diff --git a/arch/powerpc/kernel/vdso/getrandom.S b/arch/powerpc/kernel/vdso/getrandom.S index a957cd2b2b03..070daba2d547 100644 --- a/arch/powerpc/kernel/vdso/getrandom.S +++ b/arch/powerpc/kernel/vdso/getrandom.S @@ -32,6 +32,14 @@ .cfi_rel_offset r2, PPC_MIN_STKFRM + STK_GOT #endif get_datapager8 +#ifdef CONFIG_TIME_NS + lis r10, 0x7fff + ori r10, r10, 0x + lwz r9, VDSO_DATA_OFFSET + 4(r8) + cmpwr9, r10 + bne +8 + addir8, r8, (1 << CONFIG_PAGE_SHIFT) +#endif addir8, r8, VDSO_RNG_DATA_OFFSET bl CFUNC(DOTSYM(\funct)) PPC_LL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1) Thanks for looking. I came to more or less the same solutions thnt you with the following that seems to work: diff --git a/arch/powerpc/kernel/vdso/vgetrandom.c b/arch/powerpc/kernel/vdso/vgetrandom.c index 5f855d45fb7b..9705344d39d0 100644 --- a/arch/powerpc/kernel/vdso/vgetrandom.c +++ b/arch/powerpc/kernel/vdso/vgetrandom.c @@ -4,11 +4,19 @@ * * Copyright (C) 2024 Christophe Leroy , CS GROUP France */ +#include #include #include +#include + ssize_t __c_kernel_getrandom(void *buffer, size_t len, unsigned int flags, void *opaque_state, size_t opaque_len, const struct vdso_rng_data *vd) { + struct vdso_arch_data *arch_data = container_of(vd, struct vdso_arch_data, rng_data); + + if (IS_ENABLED(CONFIG_TIME_NS) && arch_data->data[0].clock_mode == VDSO_CLOCKMODE_TIMENS) + vd = (void *)vd + (1UL << CONFIG_PAGE_SHIFT); + return __cvdso_getrandom_data(vd, buffer, len, flags, opaque_state, opaque_len); } However, if we have this problem with __kernel_getrandom, don't we also have it with: ? __kernel_get_syscall_map; __kernel_get_tbfreq; __kernel_sync_dicache; If they are also affected, then get_page macro is the place to fix. I will check all of this now and keep you updated before noon (Paris Time). Christophe
Re: [PATCH v5 4/5] powerpc/vdso: Wire up getrandom() vDSO implementation on VDSO32
Le 05/09/2024 à 18:13, Jason A. Donenfeld a écrit : +/* + * The macro sets two stack frames, one for the caller and one for the callee + * because there are no requirement for the caller to set a stack frame when + * calling VDSO so it may have omitted to set one, especially on PPC64 + */ + +.macro cvdso_call funct + .cfi_startproc + PPC_STLUr1, -PPC_MIN_STKFRM(r1) + .cfi_adjust_cfa_offset PPC_MIN_STKFRM + mflrr0 + PPC_STLUr1, -PPC_MIN_STKFRM(r1) + .cfi_adjust_cfa_offset PPC_MIN_STKFRM + PPC_STL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1) + .cfi_rel_offset lr, PPC_MIN_STKFRM + PPC_LR_STKOFF + get_datapager8 + addir8, r8, VDSO_RNG_DATA_OFFSET + bl CFUNC(DOTSYM(\funct)) + PPC_LL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1) + cmpwi r3, 0 + mtlrr0 + addir1, r1, 2 * PPC_MIN_STKFRM + .cfi_restore lr + .cfi_def_cfa_offset 0 + crclr so + bgelr+ + crset so + neg r3, r3 + blr + .cfi_endproc +.endm You wrote in an earlier email that this worked with time namespaces, but in my testing that doesn't seem to be the case. Did I write that ? I can't remember and neither can I remember testing it with time namespaces. From my test harness [1]: Normal single thread vdso: 2500 times in 12.494133131 seconds libc: 2500 times in 69.594625188 seconds syscall: 2500 times in 67.349243972 seconds Time namespace single thread vdso: 2500 times in 71.673057436 seconds libc: 2500 times in 71.712774121 seconds syscall: 2500 times in 66.902318080 seconds I'm seeing this on ppc, ppc64, and ppc64le. What is the command to use to test with time namespace ? Can you figure out what's going on and send a fix, which I'll squash into this commit? Sure Jason [1] https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.zx2c4.com%2Flinux-rng%2Fcommit%2F%3Fh%3Djd%2Fvdso-test-harness&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C59fa9061064945c73a1608dccdc5b51c%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638611496253413014%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=ZUJqhcnZL7SYkuXUIt9Nlo46sZj26VYW%2F8I%2BrBLRpBE%3D&reserved=0
Re: [PATCH] soc: fsl: qe: ucc: Export ucc_mux_set_grant_tsa_bkpt
Le 05/09/2024 à 09:22, Herve Codina a écrit : When TSA is compiled as module the following error is reported: "ucc_mux_set_grant_tsa_bkpt" [drivers/soc/fsl/qe/tsa.ko] undefined! Indeed, the ucc_mux_set_grant_tsa_bkpt symbol is not exported. Simply export ucc_mux_set_grant_tsa_bkpt. Reported-by: kernel test robot Closes: https://lore.kernel.org/oe-kbuild-all/202409051409.fszn8reo-...@intel.com/ Signed-off-by: Herve Codina Acked-by: Christophe Leroy Arnd, it is ok for you to take this patch directly ? Thanks Christophe --- drivers/soc/fsl/qe/ucc.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/soc/fsl/qe/ucc.c b/drivers/soc/fsl/qe/ucc.c index 21dbcd787cd5..892aa5931d5b 100644 --- a/drivers/soc/fsl/qe/ucc.c +++ b/drivers/soc/fsl/qe/ucc.c @@ -114,6 +114,7 @@ int ucc_mux_set_grant_tsa_bkpt(unsigned int ucc_num, int set, u32 mask) return 0; } +EXPORT_SYMBOL(ucc_mux_set_grant_tsa_bkpt); int ucc_set_qe_mux_rxtx(unsigned int ucc_num, enum qe_clock clock, enum comm_dir mode)
Re: [PATCH v5 0/5] Wire up getrandom() vDSO implementation on powerpc
Le 04/09/2024 à 16:16, Jason A. Donenfeld a écrit : Hi Christophe, Michael, On Mon, Sep 02, 2024 at 09:17:17PM +0200, Christophe Leroy wrote: This series wires up getrandom() vDSO implementation on powerpc. Tested on PPC32 on real hardware. Tested on PPC64 (both BE and LE) on QEMU: Performance on powerpc 885: ~# ./vdso_test_getrandom bench-single vdso: 2500 times in 62.938002291 seconds libc: 2500 times in 535.581916866 seconds syscall: 2500 times in 531.525042806 seconds Performance on powerpc 8321: ~# ./vdso_test_getrandom bench-single vdso: 2500 times in 16.899318858 seconds libc: 2500 times in 131.050596522 seconds syscall: 2500 times in 129.794790389 seconds Performance on QEMU pseries: ~ # ./vdso_test_getrandom bench-single vdso: 2500 times in 4.97162 seconds libc: 2500 times in 75.516749981 seconds syscall: 2500 times in 86.842242014 seconds Looking good. I have no remaining nits on this patchset; it looks good to me. A review from Michael would be nice though (in addition to the necessary "Ack" I need to commit this to my tree), because there are a lot of PPC particulars that I don't know enough about to review properly. For example, you use -ffixed-r30 on PPC64. I'm sure there's a good reason for this, but I don't know enough to assess it. And cvdso_call I have no idea what's going on. Etc. You can learn a bit more about cvdso_call in commit ce7d8056e38b ("powerpc/vdso: Prepare for switching VDSO to generic C implementation.") About the fixed-r30, you can learn more in commit a88603f4b92e ("powerpc/vdso: Don't use r30 to avoid breaking Go lang") But anyway, awesome work, and I look forward to the final stretches. Thanks, looking forward to getting this series applied. Christophe
Profiling of vdso_test_random
Hi, I'm done a 'perf record' on vdso_test_random reduced to vdso test only, and I get the following function usage profile. Do you see the same type of percentage on your platforms ? I would have expected most of the time to be spent in __arch_chacha20_blocks_nostack() but that's in fact not the case. # Samples: 61K of event 'task-clock:ppp' # Event count (approx.): 1546350 # # Overhead Command Shared ObjectSymbol # ... ... # 57.74% vdso_test_getra [vdso] [.] __c_kernel_getrandom 22.49% vdso_test_getra [vdso] [.] __arch_chacha20_blocks_nostack 10.80% vdso_test_getra vdso_test_getrandom [.] test_vdso_getrandom 8.89% vdso_test_getra [vdso] [.] __kernel_getrandom 0.01% vdso_test_getra [kernel.kallsyms][k] finish_task_switch.isra.0 Christophe
[PATCH] soc: fsl: cpm1: qmc: Fix dependency on fsl_soc.h
QMC driver requires fsl_soc.h to use function get_immrbase(). This header is provided by powerpc architecture and the functions it declares are defined only when FSL_SOC is selected. Today the dependency is the following: depends on CPM1 || QUICC_ENGINE || \ (FSL_SOC && (CPM || QUICC_ENGINE) && COMPILE_TEST) This dependency tentatively ensure that FSL_SOC is there when doing a COMPILE_TEST. CPM1 is only selected by PPC_8xx and cannot be selected manually. CPM1 selects FSL_SOC QUICC_ENGINE on the other hand can be selected by ARM or ARM64 which doesn't select FSL_SOC. QUICC_ENGINE can also be selected with just COMPILE_TEST. It is therefore possible to end up with CPM_QMC selected without FSL_SOC. So fix it by making it depend on FSL_SOC at all time. The rest of the above dependency is the same as the one for CPM_TSA on which CPM_QMC also depends, so it can go away, leaving only a simple dependency on FSL_SOC. Reported-by: Stephen Rothwell Closes: https://lore.kernel.org/lkml/20240904104859.020fe...@canb.auug.org.au/ Fixes: 8655b76b7004 ("soc: fsl: cpm1: qmc: Handle QUICC Engine (QE) soft-qmc firmware") Signed-off-by: Christophe Leroy --- drivers/soc/fsl/qe/Kconfig | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/soc/fsl/qe/Kconfig b/drivers/soc/fsl/qe/Kconfig index 5e3c996eb19e..eb03f42ab978 100644 --- a/drivers/soc/fsl/qe/Kconfig +++ b/drivers/soc/fsl/qe/Kconfig @@ -48,8 +48,7 @@ config CPM_TSA config CPM_QMC tristate "CPM/QE QMC support" depends on OF && HAS_IOMEM - depends on CPM1 || QUICC_ENGINE || \ - (FSL_SOC && (CPM || QUICC_ENGINE) && COMPILE_TEST) + depends on FSL_SOC depends on CPM_TSA help Freescale CPM/QE QUICC Multichannel Controller -- 2.44.0
Re: [PATCH 2/2] mm: make copy_to_kernel_nofault() not fault on user addresses
Hi, Le 02/09/2024 à 07:31, Omar Sandoval a écrit : [Vous ne recevez pas souvent de courriers de osan...@osandov.com. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ] From: Omar Sandoval I found that on x86, copy_to_kernel_nofault() still faults on addresses outside of the kernel address range (including NULL): # echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc # echo g > /proc/sysrq-trigger ... [15]kdb> mm 0 1234 [ 94.652476] BUG: kernel NULL pointer dereference, address: ... Note that copy_to_kernel_nofault() uses pagefault_disable(), but it still faults. This is because with Supervisor Mode Access Prevention (SMAP) enabled, do_user_addr_fault() Oopses on a fault for a user address from kernel space _before_ checking faulthandler_disabled(). copy_from_kernel_nofault() avoids this by checking that the address is in the kernel before doing the actual memory access. Do the same in copy_to_kernel_nofault() so that we get an error as expected: # echo ttyS0 > /sys/module/kgdboc/parameters/kgdboc # echo g > /proc/sysrq-trigger ... [17]kdb> mm 0 1234 kdb_putarea_size: Bad address 0x0 diag: -21: Invalid address Signed-off-by: Omar Sandoval --- mm/maccess.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/maccess.c b/mm/maccess.c index 72e9c03ea37f..d67dee51a1cc 100644 --- a/mm/maccess.c +++ b/mm/maccess.c @@ -61,6 +61,9 @@ long copy_to_kernel_nofault(void *dst, const void *src, size_t size) if (!IS_ENABLED(CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS)) align = (unsigned long)dst | (unsigned long)src; + if (!copy_kernel_nofault_allowed(dst, size)) + return -ERANGE; + pagefault_disable(); if (!(align & 7)) copy_to_kernel_nofault_loop(dst, src, size, u64, Efault); -- 2.46.0 This patch leads to the following errors on ppc64le_defconfig: [2.423930][T1] Running code patching self-tests ... [2.428912][T1] code-patching: test failed at line 395 [2.429085][T1] code-patching: test failed at line 398 [2.429561][T1] code-patching: test failed at line 432 [2.429679][T1] code-patching: test failed at line 435 This seems to be linked to commit c28c15b6d28a ("powerpc/code-patching: Use temporary mm for Radix MMU"), copy_from_kernel_nofault_allowed() returns false for the patching area. Christophe
Re: [PATCH RFC v2 2/4] mm: Add hint and mmap_flags to struct vm_unmapped_area_info
Hi Charlie, Le 29/08/2024 à 09:15, Charlie Jenkins a écrit : The hint address and mmap_flags are necessary to determine if MAP_BELOW_HINT requirements are satisfied. Signed-off-by: Charlie Jenkins --- arch/alpha/kernel/osf_sys.c | 2 ++ arch/arc/mm/mmap.c | 3 +++ arch/arm/mm/mmap.c | 7 +++ arch/csky/abiv1/mmap.c | 3 +++ arch/loongarch/mm/mmap.c | 3 +++ arch/mips/mm/mmap.c | 3 +++ arch/parisc/kernel/sys_parisc.c | 3 +++ arch/powerpc/mm/book3s64/slice.c | 7 +++ arch/s390/mm/hugetlbpage.c | 4 arch/s390/mm/mmap.c | 6 ++ arch/sh/mm/mmap.c| 6 ++ arch/sparc/kernel/sys_sparc_32.c | 3 +++ arch/sparc/kernel/sys_sparc_64.c | 6 ++ arch/sparc/mm/hugetlbpage.c | 4 arch/x86/kernel/sys_x86_64.c | 6 ++ arch/x86/mm/hugetlbpage.c| 4 fs/hugetlbfs/inode.c | 4 include/linux/mm.h | 2 ++ mm/mmap.c| 6 ++ 19 files changed, 82 insertions(+) diff --git a/arch/powerpc/mm/book3s64/slice.c b/arch/powerpc/mm/book3s64/slice.c index ef3ce37f1bb3..f0e2550af6d0 100644 --- a/arch/powerpc/mm/book3s64/slice.c +++ b/arch/powerpc/mm/book3s64/slice.c @@ -286,6 +286,10 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm, .length = len, .align_mask = PAGE_MASK & ((1ul << pshift) - 1), }; + + info.hint = addr; + info.mmap_flags = flags; + /* * Check till the allow max value for this mmap request */ @@ -331,6 +335,9 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm, }; unsigned long min_addr = max(PAGE_SIZE, mmap_min_addr); + info.hint = addr; + info.mmap_flags = flags; + /* * If we are trying to allocate above DEFAULT_MAP_WINDOW * Add the different to the mmap_base. ppc64_defconfig: CC arch/powerpc/mm/book3s64/slice.o arch/powerpc/mm/book3s64/slice.c: In function 'slice_find_area_bottomup': arch/powerpc/mm/book3s64/slice.c:291:27: error: 'flags' undeclared (first use in this function) 291 | info.mmap_flags = flags; | ^ arch/powerpc/mm/book3s64/slice.c:291:27: note: each undeclared identifier is reported only once for each function it appears in arch/powerpc/mm/book3s64/slice.c: In function 'slice_find_area_topdown': arch/powerpc/mm/book3s64/slice.c:339:27: error: 'flags' undeclared (first use in this function) 339 | info.mmap_flags = flags; | ^ make[5]: *** [scripts/Makefile.build:244: arch/powerpc/mm/book3s64/slice.o] Error 1
Re: [PATCH] of/irq: handle irq_of_parse_and_map() errors
Le 30/08/2024 à 16:21, Ma Ke a écrit : Zero and negative number is not a valid IRQ for in-kernel code and the irq_of_parse_and_map() function returns zero on error. So this check for valid IRQs should only accept values > 0. unsigned int irq_of_parse_and_map(struct device_node *node, int index); I can't see how an 'unsigned int' can be negative. Christophe Cc: sta...@vger.kernel.org Fixes: f7578496a671 ("of/irq: Use irq_of_parse_and_map()") Signed-off-by: Ma Ke --- drivers/i2c/busses/i2c-cpm.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-cpm.c b/drivers/i2c/busses/i2c-cpm.c index 4794ec066eb0..41e3c95c0ef7 100644 --- a/drivers/i2c/busses/i2c-cpm.c +++ b/drivers/i2c/busses/i2c-cpm.c @@ -435,7 +435,7 @@ static int cpm_i2c_setup(struct cpm_i2c *cpm) init_waitqueue_head(&cpm->i2c_wait); cpm->irq = irq_of_parse_and_map(ofdev->dev.of_node, 0); - if (!cpm->irq) + if (cpm->irq <= 0) return -EINVAL; /* Install interrupt handler. */
Re: [PATCH] soc: fsl: qbman: Remove redundant warnings
Le 02/08/2024 à 04:16, Xiaolei Wang a écrit : [Vous ne recevez pas souvent de courriers de xiaolei.w...@windriver.com. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ] RESERVEDMEM_OF_DECLARE usage has been removed. For non-popwerpc platforms, such as ls1043, this warning is redundant. ls1043 itself uses shared-dma-mem. Fixes: 3e62273ac63a ("soc: fsl: qbman: Remove RESERVEDMEM_OF_DECLARE usage") Signed-off-by: Xiaolei Wang --- drivers/soc/fsl/qbman/qman_ccsr.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/drivers/soc/fsl/qbman/qman_ccsr.c b/drivers/soc/fsl/qbman/qman_ccsr.c index 392e54f14dbe..aa5348f4902f 100644 --- a/drivers/soc/fsl/qbman/qman_ccsr.c +++ b/drivers/soc/fsl/qbman/qman_ccsr.c @@ -791,8 +791,6 @@ static int fsl_qman_probe(struct platform_device *pdev) * FQD memory MUST be zero'd by software */ zero_priv_mem(fqd_a, fqd_sz); -#else - WARN(1, "Unexpected architecture using non shared-dma-mem reservations"); #endif dev_dbg(dev, "Allocated FQD 0x%llx 0x%zx\n", fqd_a, fqd_sz); -- 2.25.1 Applied for 6.12 Thanks Christophe
Re: [PATCH 1/1] soc/fsl/qbman: Use iommu_paging_domain_alloc()
Le 12/08/2024 à 09:25, Lu Baolu a écrit : [Vous ne recevez pas souvent de courriers de baolu...@linux.intel.com. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ] An iommu domain is allocated in portal_set_cpu() and is attached to pcfg->dev in the same function. Use iommu_paging_domain_alloc() to make it explicit. Signed-off-by: Lu Baolu Reviewed-by: Jason Gunthorpe Link: https://lore.kernel.org/r/2024061008.88197-14-baolu...@linux.intel.com --- drivers/soc/fsl/qbman/qman_portal.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/soc/fsl/qbman/qman_portal.c b/drivers/soc/fsl/qbman/qman_portal.c index e23b60618c1a..456ef5d5c199 100644 --- a/drivers/soc/fsl/qbman/qman_portal.c +++ b/drivers/soc/fsl/qbman/qman_portal.c @@ -48,9 +48,10 @@ static void portal_set_cpu(struct qm_portal_config *pcfg, int cpu) struct device *dev = pcfg->dev; int ret; - pcfg->iommu_domain = iommu_domain_alloc(&platform_bus_type); - if (!pcfg->iommu_domain) { + pcfg->iommu_domain = iommu_paging_domain_alloc(dev); + if (IS_ERR(pcfg->iommu_domain)) { dev_err(dev, "%s(): iommu_domain_alloc() failed", __func__); + pcfg->iommu_domain = NULL; goto no_iommu; } ret = fsl_pamu_configure_l1_stash(pcfg->iommu_domain, cpu); -- 2.34.1 Applied for 6.12 Thanks Christophe
Re: [PATCH v2 00/36] soc: fsl: Add support for QUICC Engine TSA and QMC
Le 08/08/2024 à 09:10, Herve Codina a écrit : Hi, This series add support for the QUICC Engine (QE) version of TSA and QMC components. CPM1 version is already supported and, as the QE version of those component are pretty similar to the CPM1 version, the series extend the already existing drivers to support for the QE version. The TSA and QMC components are tightly coupled and so the series provides modifications on both components. Of course, this series can be split if it is needed. Let me know. The series is composed of: - Patches 1 and 2: Fixes related to TRNSYNC in the QMC driver - Patches 3..6: Fixes of checkpatch detected issues in the TSA driver - Patch 7: The QE TSA device-tree binding - Patches 8..13: TSA driver preparations for adding support for QE - Patches 14 and 15: The support for QE in TSA + MAINTAINERS update - Patch 16: A TSA API improvement needed for the QE QMC driver - Patch 17: A clarification in the QE QMC driver - Patches 18..22: Fixes of checkpatch detected issues in the QMC driver - Patch 23: The QE QMC device-tree binding - Patches 24..31: QMC driver preparations for adding support for QE - Patches 32 and 33: Missing features additions in QE code - Patches 34..36: The QMC support for QE in QMC + MAINTAINERS update Compared to the previous iteration, this v2 series updates device-tree bindings and fixes issues detected by kernel test robots. Related to the QE QMC device-tree binding, I kept the unit address in decimal and the 3 compatible strings in order to avoid blocking the review waiting for a confirmation. Of course, this can be change in a next iteration. Series applied for 6.12 Thanks Christophe
[GIT PULL] SOC FSL for 6.12 (retry)
Hi Arnd, Please pull the following Freescale Soc Drivers changes for 6.12 There are no conflicts with latest linux-next tree. Thanks Christophe The following changes since commit 8400291e289ee6b2bf9779ff1c83a291501f017b: Linux 6.11-rc1 (2024-07-28 14:19:55 -0700) are available in the Git repository at: https://github.com/chleroy/linux.git tags/soc_fsl-6.12-2 for you to fetch changes up to 7a99b1c0bce5cf8c554ceecd29ad1e8085557fd3: Merge branch 'support-for-quicc-engine-tsa-and-qmc' (2024-09-03 07:51:34 +0200) - A series from Hervé Codina that bring support for the newer version of QMC (QUICC Multi-channel Controller) and TSA (Time Slots Assigner) found on MPC 83xx micro-controllers. - Misc changes for qbman freescale drivers for removing a redundant warning and using iommu_paging_domain_alloc() ---- Christophe Leroy (1): Merge branch 'support-for-quicc-engine-tsa-and-qmc' Herve Codina (36): soc: fsl: cpm1: qmc: Update TRNSYNC only in transparent mode soc: fsl: cpm1: qmc: Enable TRNSYNC only when needed soc: fsl: cpm1: tsa: Fix tsa_write8() soc: fsl: cpm1: tsa: Use BIT(), GENMASK() and FIELD_PREP() macros soc: fsl: cpm1: tsa: Fix blank line and spaces soc: fsl: cpm1: tsa: Add missing spinlock comment dt-bindings: soc: fsl: cpm_qe: Add QUICC Engine (QE) TSA controller soc: fsl: cpm1: tsa: Remove unused registers offset definition soc: fsl: cpm1: tsa: Use ARRAY_SIZE() instead of hardcoded integer values soc: fsl: cpm1: tsa: Make SIRAM entries specific to CPM1 soc: fsl: cpm1: tsa: Introduce tsa_setup() and its CPM1 compatible version soc: fsl: cpm1: tsa: Isolate specific CPM1 part from tsa_serial_{dis}connect() soc: fsl: cpm1: tsa: Introduce tsa_version soc: fsl: cpm1: tsa: Add support for QUICC Engine (QE) implementation MAINTAINERS: Add QE files related to the Freescale TSA controller soc: fsl: cpm1: tsa: Introduce tsa_serial_get_num() soc: fsl: cpm1: qmc: Rename QMC_TSA_MASK soc: fsl: cpm1: qmc: Use BIT(), GENMASK() and FIELD_PREP() macros soc: fsl: cpm1: qmc: Fix blank line and spaces soc: fsl: cpm1: qmc: Remove unneeded parenthesis soc: fsl: cpm1: qmc: Fix 'transmiter' typo soc: fsl: cpm1: qmc: Add missing spinlock comment dt-bindings: soc: fsl: cpm_qe: Add QUICC Engine (QE) QMC controller soc: fsl: cpm1: qmc: Introduce qmc_data structure soc: fsl: cpm1: qmc: Re-order probe() operations soc: fsl: cpm1: qmc: Introduce qmc_init_resource() and its CPM1 version soc: fsl: cpm1: qmc: Introduce qmc_{init,exit}_xcc() and their CPM1 version soc: fsl: cpm1: qmc: Rename qmc_chan_command() soc: fsl: cpm1: qmc: Handle RPACK initialization soc: fsl: cpm1: qmc: Rename SCC_GSMRL_MODE_QMC soc: fsl: cpm1: qmc: Introduce qmc_version soc: fsl: qe: Add resource-managed muram allocators soc: fsl: qe: Add missing PUSHSCHED command soc: fsl: cpm1: qmc: Add support for QUICC Engine (QE) implementation soc: fsl: cpm1: qmc: Handle QUICC Engine (QE) soft-qmc firmware MAINTAINERS: Add QE files related to the Freescale QMC controller Lu Baolu (1): soc: fsl: qbman: Use iommu_paging_domain_alloc() Xiaolei Wang (1): soc: fsl: qbman: Remove redundant warnings .../bindings/soc/fsl/cpm_qe/fsl,qe-tsa.yaml| 210 +++ .../bindings/soc/fsl/cpm_qe/fsl,qe-ucc-qmc.yaml| 197 ++ MAINTAINERS| 3 + drivers/soc/fsl/qbman/qman_ccsr.c | 2 - drivers/soc/fsl/qbman/qman_portal.c| 5 +- drivers/soc/fsl/qe/Kconfig | 18 +- drivers/soc/fsl/qe/qe_common.c | 80 +++ drivers/soc/fsl/qe/qmc.c | 667 - drivers/soc/fsl/qe/tsa.c | 659 +++- drivers/soc/fsl/qe/tsa.h | 3 + include/dt-bindings/soc/qe-fsl,tsa.h | 13 + include/soc/fsl/qe/qe.h| 23 +- 12 files changed, 1552 insertions(+), 328 deletions(-) create mode 100644 Documentation/devicetree/bindings/soc/fsl/cpm_qe/fsl,qe-tsa.yaml create mode 100644 Documentation/devicetree/bindings/soc/fsl/cpm_qe/fsl,qe-ucc-qmc.yaml create mode 100644 include/dt-bindings/soc/qe-fsl,tsa.h
[PATCH v5 5/5] powerpc/vdso: Wire up getrandom() vDSO implementation on VDSO64
Extend getrandom() vDSO implementation to VDSO64 Tested on QEMU on both ppc64_defconfig and ppc64le_defconfig. The results are not precise as it is QEMU on an x86 laptop, but no need to be precise to see the benefit. ~ # ./vdso_test_getrandom bench-single vdso: 2500 times in 4.97162 seconds libc: 2500 times in 75.516749981 seconds syscall: 2500 times in 86.842242014 seconds ~ # ./vdso_test_getrandom bench-single vdso: 2500 times in 6.473814156 seconds libc: 2500 times in 73.875109463 seconds syscall: 2500 times in 71.805066229 seconds Signed-off-by: Christophe Leroy --- v5: - VDSO32 for both PPC32 and PPC64 is in previous patch. This patch have the logic for VDSO64. v4: - Use __BIG_ENDIAN__ which is defined by GCC instead of CONFIG_CPU_BIG_ENDIAN which is unknown by selftests - Implement a cleaner/smaller output copy for little endian instead of keeping compat macro. v3: New (split out of previous patch) --- arch/powerpc/Kconfig | 2 +- arch/powerpc/kernel/vdso/Makefile| 8 ++- arch/powerpc/kernel/vdso/getrandom.S | 8 +++ arch/powerpc/kernel/vdso/vdso64.lds.S| 1 + arch/powerpc/kernel/vdso/vgetrandom-chacha.S | 53 5 files changed, 69 insertions(+), 3 deletions(-) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index e500a59ddecc..b45452ac4a73 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -311,7 +311,7 @@ config PPC select SYSCTL_EXCEPTION_TRACE select THREAD_INFO_IN_TASK select TRACE_IRQFLAGS_SUPPORT - select VDSO_GETRANDOM if VDSO32 + select VDSO_GETRANDOM # # Please keep this list sorted alphabetically. # diff --git a/arch/powerpc/kernel/vdso/Makefile b/arch/powerpc/kernel/vdso/Makefile index 7a4a935406d8..56fb1633529a 100644 --- a/arch/powerpc/kernel/vdso/Makefile +++ b/arch/powerpc/kernel/vdso/Makefile @@ -9,6 +9,7 @@ obj-vdso32 = sigtramp32-32.o gettimeofday-32.o datapage-32.o cacheflush-32.o not obj-vdso64 = sigtramp64-64.o gettimeofday-64.o datapage-64.o cacheflush-64.o note-64.o getcpu-64.o obj-vdso32 += getrandom-32.o vgetrandom-chacha-32.o +obj-vdso64 += getrandom-64.o vgetrandom-chacha-64.o ifneq ($(c-gettimeofday-y),) CFLAGS_vgettimeofday-32.o += -include $(c-gettimeofday-y) @@ -21,6 +22,7 @@ endif ifneq ($(c-getrandom-y),) CFLAGS_vgetrandom-32.o += -include $(c-getrandom-y) + CFLAGS_vgetrandom-64.o += -include $(c-getrandom-y) $(call cc-option, -ffixed-r30) endif # Build rules @@ -34,7 +36,7 @@ endif targets := $(obj-vdso32) vdso32.so.dbg vgettimeofday-32.o vgetrandom-32.o targets += crtsavres-32.o obj-vdso32 := $(addprefix $(obj)/, $(obj-vdso32)) -targets += $(obj-vdso64) vdso64.so.dbg vgettimeofday-64.o +targets += $(obj-vdso64) vdso64.so.dbg vgettimeofday-64.o vgetrandom-64.o obj-vdso64 := $(addprefix $(obj)/, $(obj-vdso64)) ccflags-y := -fno-common -fno-builtin -DBUILD_VDSO @@ -71,7 +73,7 @@ CPPFLAGS_vdso64.lds += -P -C # link rule for the .so file, .lds has to be first $(obj)/vdso32.so.dbg: $(obj)/vdso32.lds $(obj-vdso32) $(obj)/vgettimeofday-32.o $(obj)/vgetrandom-32.o $(obj)/crtsavres-32.o FORCE $(call if_changed,vdso32ld_and_check) -$(obj)/vdso64.so.dbg: $(obj)/vdso64.lds $(obj-vdso64) $(obj)/vgettimeofday-64.o FORCE +$(obj)/vdso64.so.dbg: $(obj)/vdso64.lds $(obj-vdso64) $(obj)/vgettimeofday-64.o $(obj)/vgetrandom-64.o FORCE $(call if_changed,vdso64ld_and_check) # assembly rules for the .S files @@ -87,6 +89,8 @@ $(obj-vdso64): %-64.o: %.S FORCE $(call if_changed_dep,vdso64as) $(obj)/vgettimeofday-64.o: %-64.o: %.c FORCE $(call if_changed_dep,cc_o_c) +$(obj)/vgetrandom-64.o: %-64.o: %.c FORCE + $(call if_changed_dep,cc_o_c) # Generate VDSO offsets using helper script gen-vdso32sym := $(src)/gen_vdso32_offsets.sh diff --git a/arch/powerpc/kernel/vdso/getrandom.S b/arch/powerpc/kernel/vdso/getrandom.S index 21773ef3fc1d..a957cd2b2b03 100644 --- a/arch/powerpc/kernel/vdso/getrandom.S +++ b/arch/powerpc/kernel/vdso/getrandom.S @@ -27,10 +27,18 @@ .cfi_adjust_cfa_offset PPC_MIN_STKFRM PPC_STL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1) .cfi_rel_offset lr, PPC_MIN_STKFRM + PPC_LR_STKOFF +#ifdef __powerpc64__ + PPC_STL r2, PPC_MIN_STKFRM + STK_GOT(r1) + .cfi_rel_offset r2, PPC_MIN_STKFRM + STK_GOT +#endif get_datapager8 addir8, r8, VDSO_RNG_DATA_OFFSET bl CFUNC(DOTSYM(\funct)) PPC_LL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1) +#ifdef __powerpc64__ + PPC_LL r2, PPC_MIN_STKFRM + STK_GOT(r1) + .cfi_restore r2 +#endif cmpwi r3, 0 mtlrr0 addir1, r1, 2 * PPC_MIN_STKFRM diff --git a/arch/powerpc/kernel/vdso/vdso64.lds.S b/arch/powerpc/kernel/vdso/vdso64.lds.S index 400819258c06..9481e4b892ed 100644 --- a/arch
[PATCH v5 4/5] powerpc/vdso: Wire up getrandom() vDSO implementation on VDSO32
To be consistent with other VDSO functions, the function is called __kernel_getrandom() __arch_chacha20_blocks_nostack() fonction is implemented basically with 32 bits operations. It performs 4 QUARTERROUND operations in parallele. There are enough registers to avoid using the stack: On input: r3: output bytes r4: 32-byte key input r5: 8-byte counter input/output r6: number of 64-byte blocks to write to output During operation: stack: pointer to counter (r5) and non-volatile registers (r14-131) r0: counter of blocks (initialised with r6) r4: Value '4' after key has been read, used for indexing r5-r12: key r14-r15: block counter r16-r31: chacha state At the end: r0, r6-r12: Zeroised r5, r14-r31: Restored Performance on powerpc 885 (using kernel selftest): ~# ./vdso_test_getrandom bench-single vdso: 2500 times in 62.938002291 seconds libc: 2500 times in 535.581916866 seconds syscall: 2500 times in 531.525042806 seconds Performance on powerpc 8321 (using kernel selftest): ~# ./vdso_test_getrandom bench-single vdso: 2500 times in 16.899318858 seconds libc: 2500 times in 131.050596522 seconds syscall: 2500 times in 129.794790389 seconds This first patch adds support for VDSO32. As selftests cannot easily be generated only for VDSO32, and because the following patch brings support for VDSO64 anyway, this patch opts out all code in __arch_chacha20_blocks_nostack() so that vdso_test_chacha will not fail to compile and will not crash on PPC64/PPC64LE, allthough the selftest itself will fail. Signed-off-by: Christophe Leroy --- v5: - Add back vdso symlink that vanished in v4 after a rebase back and forth with rejected patch "selftests: vDSO: Do not rely on $ARCH for vdso_test_getrandom && vdso_test_chacha" - Set meaningfull names to registers and constants in chacha assembly - Add 32 bits LE logic in this patch as well allthought it is only usefull for ppc64le. - Remove the temporary ppc64 __kernel_getrandom added in v4, selftest will return KSFT_FAIL until following patch, not a big issue. - Move the -DBUILD_VDSO logic in patch 3 to allow build VDSO32 on ppc64. v4: - Counter has native byte order - Fix selftest build on ppc64le until implemented. - On ppc64, for now implement __kernel_getrandom to return ENOSYS error - Use stwbrx directly, not compat macro. v3: - Preserve r13, implies saving r5 on stack - Split PPC64 implementation out. --- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/mman.h | 2 +- arch/powerpc/include/asm/vdso/getrandom.h| 54 arch/powerpc/include/asm/vdso/vsyscall.h | 6 + arch/powerpc/include/asm/vdso_datapage.h | 2 + arch/powerpc/kernel/asm-offsets.c| 1 + arch/powerpc/kernel/vdso/Makefile| 14 +- arch/powerpc/kernel/vdso/getrandom.S | 50 +++ arch/powerpc/kernel/vdso/vdso32.lds.S| 1 + arch/powerpc/kernel/vdso/vgetrandom-chacha.S | 312 +++ arch/powerpc/kernel/vdso/vgetrandom.c| 14 + tools/arch/powerpc/vdso | 1 + tools/testing/selftests/vDSO/Makefile| 2 +- 13 files changed, 455 insertions(+), 5 deletions(-) create mode 100644 arch/powerpc/include/asm/vdso/getrandom.h create mode 100644 arch/powerpc/kernel/vdso/getrandom.S create mode 100644 arch/powerpc/kernel/vdso/vgetrandom-chacha.S create mode 100644 arch/powerpc/kernel/vdso/vgetrandom.c create mode 12 tools/arch/powerpc/vdso diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index d7b09b064a8a..e500a59ddecc 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -311,6 +311,7 @@ config PPC select SYSCTL_EXCEPTION_TRACE select THREAD_INFO_IN_TASK select TRACE_IRQFLAGS_SUPPORT + select VDSO_GETRANDOM if VDSO32 # # Please keep this list sorted alphabetically. # diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h index 17a77d47ed6d..42a51a993d94 100644 --- a/arch/powerpc/include/asm/mman.h +++ b/arch/powerpc/include/asm/mman.h @@ -6,7 +6,7 @@ #include -#ifdef CONFIG_PPC64 +#if defined(CONFIG_PPC64) && !defined(BUILD_VDSO) #include #include diff --git a/arch/powerpc/include/asm/vdso/getrandom.h b/arch/powerpc/include/asm/vdso/getrandom.h new file mode 100644 index ..501d6bb14e8a --- /dev/null +++ b/arch/powerpc/include/asm/vdso/getrandom.h @@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2024 Christophe Leroy , CS GROUP France + */ +#ifndef _ASM_POWERPC_VDSO_GETRANDOM_H +#define _ASM_POWERPC_VDSO_GETRANDOM_H + +#ifndef __ASSEMBLY__ + +static __always_inline int do_syscall_3(const unsigned long _r0, const unsigned long _r3, +
[PATCH v5 3/5] powerpc/vdso: Refactor CFLAGS for CVDSO build
In order to avoid two much duplication when we add new VDSO functionnalities in C like getrandom, refactor common CFLAGS. Signed-off-by: Christophe Leroy --- v3: Also refactor removed flags --- arch/powerpc/kernel/vdso/Makefile | 32 +-- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/arch/powerpc/kernel/vdso/Makefile b/arch/powerpc/kernel/vdso/Makefile index c07a425b8f78..67fe79d26fae 100644 --- a/arch/powerpc/kernel/vdso/Makefile +++ b/arch/powerpc/kernel/vdso/Makefile @@ -10,28 +10,11 @@ obj-vdso64 = sigtramp64-64.o gettimeofday-64.o datapage-64.o cacheflush-64.o not ifneq ($(c-gettimeofday-y),) CFLAGS_vgettimeofday-32.o += -include $(c-gettimeofday-y) - CFLAGS_vgettimeofday-32.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) - CFLAGS_vgettimeofday-32.o += $(call cc-option, -fno-stack-protector) - CFLAGS_vgettimeofday-32.o += -DDISABLE_BRANCH_PROFILING - CFLAGS_vgettimeofday-32.o += -ffreestanding -fasynchronous-unwind-tables - CFLAGS_REMOVE_vgettimeofday-32.o = $(CC_FLAGS_FTRACE) - CFLAGS_REMOVE_vgettimeofday-32.o += -mcmodel=medium -mabi=elfv1 -mabi=elfv2 -mcall-aixdesc - # This flag is supported by clang for 64-bit but not 32-bit so it will cause - # an unused command line flag warning for this file. - ifdef CONFIG_CC_IS_CLANG - CFLAGS_REMOVE_vgettimeofday-32.o += -fno-stack-clash-protection - endif - CFLAGS_vgettimeofday-64.o += -include $(c-gettimeofday-y) - CFLAGS_vgettimeofday-64.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) - CFLAGS_vgettimeofday-64.o += $(call cc-option, -fno-stack-protector) - CFLAGS_vgettimeofday-64.o += -DDISABLE_BRANCH_PROFILING - CFLAGS_vgettimeofday-64.o += -ffreestanding -fasynchronous-unwind-tables - CFLAGS_REMOVE_vgettimeofday-64.o = $(CC_FLAGS_FTRACE) # Go prior to 1.16.x assumes r30 is not clobbered by any VDSO code. That used to be true # by accident when the VDSO was hand-written asm code, but may not be now that the VDSO is # compiler generated. To avoid breaking Go tell GCC not to use r30. Impact on code # generation is minimal, it will just use r29 instead. - CFLAGS_vgettimeofday-64.o += $(call cc-option, -ffixed-r30) + CFLAGS_vgettimeofday-64.o += -include $(c-gettimeofday-y) $(call cc-option, -ffixed-r30) endif # Build rules @@ -49,6 +32,11 @@ targets += $(obj-vdso64) vdso64.so.dbg vgettimeofday-64.o obj-vdso64 := $(addprefix $(obj)/, $(obj-vdso64)) ccflags-y := -fno-common -fno-builtin +ccflags-y += $(DISABLE_LATENT_ENTROPY_PLUGIN) +ccflags-y += $(call cc-option, -fno-stack-protector) +ccflags-y += -DDISABLE_BRANCH_PROFILING +ccflags-y += -ffreestanding -fasynchronous-unwind-tables +ccflags-remove-y := $(CC_FLAGS_FTRACE) ldflags-y := -Wl,--hash-style=both -nostdlib -shared -z noexecstack $(CLANG_FLAGS) ldflags-$(CONFIG_LD_IS_LLD) += $(call cc-option,--ld-path=$(LD),-fuse-ld=lld) ldflags-$(CONFIG_LD_ORPHAN_WARN) += -Wl,--orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL) @@ -57,6 +45,12 @@ ldflags-$(CONFIG_LD_ORPHAN_WARN) += -Wl,--orphan-handling=$(CONFIG_LD_ORPHAN_WAR ldflags-y += $(filter-out $(CC_AUTO_VAR_INIT_ZERO_ENABLER) $(CC_FLAGS_FTRACE) -Wa$(comma)%, $(KBUILD_CFLAGS)) CC32FLAGS := -m32 +CC32FLAGSREMOVE := -mcmodel=medium -mabi=elfv1 -mabi=elfv2 -mcall-aixdesc + # This flag is supported by clang for 64-bit but not 32-bit so it will cause + # an unused command line flag warning for this file. +ifdef CONFIG_CC_IS_CLANG +CC32FLAGSREMOVE += -fno-stack-clash-protection +endif LD32FLAGS := -Wl,-soname=linux-vdso32.so.1 AS32FLAGS := -D__VDSO32__ @@ -105,7 +99,7 @@ quiet_cmd_vdso32ld_and_check = VDSO32L $@ quiet_cmd_vdso32as = VDSO32A $@ cmd_vdso32as = $(VDSOCC) $(a_flags) $(CC32FLAGS) $(AS32FLAGS) -c -o $@ $< quiet_cmd_vdso32cc = VDSO32C $@ - cmd_vdso32cc = $(VDSOCC) $(c_flags) $(CC32FLAGS) -c -o $@ $< + cmd_vdso32cc = $(VDSOCC) $(filter-out $(CC32FLAGSREMOVE), $(c_flags)) $(CC32FLAGS) -c -o $@ $< quiet_cmd_vdso64ld_and_check = VDSO64L $@ cmd_vdso64ld_and_check = $(VDSOCC) $(ldflags-y) $(LD64FLAGS) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^); $(cmd_vdso_check) -- 2.44.0
[PATCH v5 2/5] powerpc/vdso32: Add crtsavres
Commit 08c18b63d965 ("powerpc/vdso32: Add missing _restgpr_31_x to fix build failure") added _restgpr_31_x to the vdso for gettimeofday, but the work on getrandom shows that we will need more of those functions. Remove _restgpr_31_x and link in crtsavres.o so that we get all save/restore functions when optimising the kernel for size. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/vdso/Makefile | 5 - arch/powerpc/kernel/vdso/gettimeofday.S | 13 - 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/arch/powerpc/kernel/vdso/Makefile b/arch/powerpc/kernel/vdso/Makefile index 1425b6edc66b..c07a425b8f78 100644 --- a/arch/powerpc/kernel/vdso/Makefile +++ b/arch/powerpc/kernel/vdso/Makefile @@ -43,6 +43,7 @@ else endif targets := $(obj-vdso32) vdso32.so.dbg vgettimeofday-32.o +targets += crtsavres-32.o obj-vdso32 := $(addprefix $(obj)/, $(obj-vdso32)) targets += $(obj-vdso64) vdso64.so.dbg vgettimeofday-64.o obj-vdso64 := $(addprefix $(obj)/, $(obj-vdso64)) @@ -68,7 +69,7 @@ targets += vdso64.lds CPPFLAGS_vdso64.lds += -P -C # link rule for the .so file, .lds has to be first -$(obj)/vdso32.so.dbg: $(obj)/vdso32.lds $(obj-vdso32) $(obj)/vgettimeofday-32.o FORCE +$(obj)/vdso32.so.dbg: $(obj)/vdso32.lds $(obj-vdso32) $(obj)/vgettimeofday-32.o $(obj)/crtsavres-32.o FORCE $(call if_changed,vdso32ld_and_check) $(obj)/vdso64.so.dbg: $(obj)/vdso64.lds $(obj-vdso64) $(obj)/vgettimeofday-64.o FORCE $(call if_changed,vdso64ld_and_check) @@ -76,6 +77,8 @@ $(obj)/vdso64.so.dbg: $(obj)/vdso64.lds $(obj-vdso64) $(obj)/vgettimeofday-64.o # assembly rules for the .S files $(obj-vdso32): %-32.o: %.S FORCE $(call if_changed_dep,vdso32as) +$(obj)/crtsavres-32.o: %-32.o: $(srctree)/arch/powerpc/lib/crtsavres.S FORCE + $(call if_changed_dep,vdso32as) $(obj)/vgettimeofday-32.o: %-32.o: %.c FORCE $(call if_changed_dep,vdso32cc) $(obj-vdso64): %-64.o: %.S FORCE diff --git a/arch/powerpc/kernel/vdso/gettimeofday.S b/arch/powerpc/kernel/vdso/gettimeofday.S index 48fc6658053a..67254ac9c8bb 100644 --- a/arch/powerpc/kernel/vdso/gettimeofday.S +++ b/arch/powerpc/kernel/vdso/gettimeofday.S @@ -118,16 +118,3 @@ V_FUNCTION_END(__kernel_clock_getres) V_FUNCTION_BEGIN(__kernel_time) cvdso_call __c_kernel_time call_time=1 V_FUNCTION_END(__kernel_time) - -/* Routines for restoring integer registers, called by the compiler. */ -/* Called with r11 pointing to the stack header word of the caller of the */ -/* function, just beyond the end of the integer restore area. */ -#ifndef __powerpc64__ -_GLOBAL(_restgpr_31_x) -_GLOBAL(_rest32gpr_31_x) - lwz r0,4(r11) - lwz r31,-4(r11) - mtlrr0 - mr r1,r11 - blr -#endif -- 2.44.0
[PATCH v5 1/5] mm: Define VM_DROPPABLE for powerpc/32
Commit 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings") only adds VM_DROPPABLE for 64 bits architectures. In order to also use the getrandom vDSO implementation on powerpc/32, use VM_ARCH_1 for VM_DROPPABLE on powerpc/32. This is possible because VM_ARCH_1 is used for VM_SAO on powerpc and VM_SAO is only for powerpc/64. It is used in combination with PROT_SAO in some parts of code that are restricted to CONFIG_PPC64 through #ifdefs, it is therefore possible to define VM_SAO for CONFIG_PPC64 only. Signed-off-by: Christophe Leroy --- v4: Added more details in commit message following comment from Michael. v3: Fixed build failure reported by robots. --- fs/proc/task_mmu.c | 4 +++- include/linux/mm.h | 4 +++- include/trace/events/mmflags.h | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 5f171ad7b436..3a07e13e2f81 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -987,8 +987,10 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma) #ifdef CONFIG_X86_USER_SHADOW_STACK [ilog2(VM_SHADOW_STACK)] = "ss", #endif -#ifdef CONFIG_64BIT +#if defined(CONFIG_64BIT) || defined(CONFIG_PPC32) [ilog2(VM_DROPPABLE)] = "dp", +#endif +#ifdef CONFIG_64BIT [ilog2(VM_SEALED)] = "sl", #endif }; diff --git a/include/linux/mm.h b/include/linux/mm.h index 6549d0979b28..028847f39442 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -359,7 +359,7 @@ extern unsigned int kobjsize(const void *objp); #if defined(CONFIG_X86) # define VM_PATVM_ARCH_1 /* PAT reserves whole VMA at once (x86) */ -#elif defined(CONFIG_PPC) +#elif defined(CONFIG_PPC64) # define VM_SAOVM_ARCH_1 /* Strong Access Ordering (powerpc) */ #elif defined(CONFIG_PARISC) # define VM_GROWSUPVM_ARCH_1 @@ -409,6 +409,8 @@ extern unsigned int kobjsize(const void *objp); #ifdef CONFIG_64BIT #define VM_DROPPABLE_BIT 40 #define VM_DROPPABLE BIT(VM_DROPPABLE_BIT) +#elif defined(CONFIG_PPC32) +#define VM_DROPPABLE VM_ARCH_1 #else #define VM_DROPPABLE VM_NONE #endif diff --git a/include/trace/events/mmflags.h b/include/trace/events/mmflags.h index b63d211bd141..37265977d524 100644 --- a/include/trace/events/mmflags.h +++ b/include/trace/events/mmflags.h @@ -143,7 +143,7 @@ IF_HAVE_PG_ARCH_X(arch_3) #if defined(CONFIG_X86) #define __VM_ARCH_SPECIFIC_1 {VM_PAT, "pat" } -#elif defined(CONFIG_PPC) +#elif defined(CONFIG_PPC64) #define __VM_ARCH_SPECIFIC_1 {VM_SAO, "sao" } #elif defined(CONFIG_PARISC) #define __VM_ARCH_SPECIFIC_1 {VM_GROWSUP, "growsup" } @@ -165,7 +165,7 @@ IF_HAVE_PG_ARCH_X(arch_3) # define IF_HAVE_UFFD_MINOR(flag, name) #endif -#ifdef CONFIG_64BIT +#if defined(CONFIG_64BIT) || defined(CONFIG_PPC32) # define IF_HAVE_VM_DROPPABLE(flag, name) {flag, name}, #else # define IF_HAVE_VM_DROPPABLE(flag, name) -- 2.44.0
[PATCH v5 0/5] Wire up getrandom() vDSO implementation on powerpc
This series wires up getrandom() vDSO implementation on powerpc. Tested on PPC32 on real hardware. Tested on PPC64 (both BE and LE) on QEMU: Performance on powerpc 885: ~# ./vdso_test_getrandom bench-single vdso: 2500 times in 62.938002291 seconds libc: 2500 times in 535.581916866 seconds syscall: 2500 times in 531.525042806 seconds Performance on powerpc 8321: ~# ./vdso_test_getrandom bench-single vdso: 2500 times in 16.899318858 seconds libc: 2500 times in 131.050596522 seconds syscall: 2500 times in 129.794790389 seconds Performance on QEMU pseries: ~ # ./vdso_test_getrandom bench-single vdso: 2500 times in 4.97162 seconds libc: 2500 times in 75.516749981 seconds syscall: 2500 times in 86.842242014 seconds Changes in v5: - The split between last two patches is not anymore PPC32/PPC64 but VDSO32/VDSO64 - Removed the stub returning ENOSYS - Using meaningfull names for registers - Restored symbolic link that disappeared in v4 Changes in v4: - Rebased on recent random git tree (963233ff0133) (The new tree includes selftests fixes) - Read/write counter in native byte order - Don't use anymore compat macros to write output - Fixed selftests build failure with patch 4 (without patch 5) on little endian on PPC64 - Implement a __kernel_getrandom() stub returning ENOSYS on ppc64 in patch 4 (without patch 5) to make selftests happy. Changes in v3: - Rebased on recent random git tree (0c7e00e22c21) - Fixed build failures reported by robots around VM_DROPPABLE - Fixed crash on PPC64 due to clobbered r13 by not using r13 anymore (saving it was not enough for signals). - Split final patch in two, first for PPC32, second for PPC64 - Moved selftest fixes out of this series Changes in v2: - Define VM_DROPPABLE for powerpc/32 - Fixes generic vDSO getrandom headers to enable CONFIG_COMPAT build. - Fixed size of generation counter - Fixed selftests to work on non x86 architectures Christophe Leroy (5): mm: Define VM_DROPPABLE for powerpc/32 powerpc/vdso32: Add crtsavres powerpc/vdso: Refactor CFLAGS for CVDSO build powerpc/vdso: Wire up getrandom() vDSO implementation on VDSO32 powerpc/vdso: Wire up getrandom() vDSO implementation on VDSO64 arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/mman.h | 2 +- arch/powerpc/include/asm/vdso/getrandom.h| 54 +++ arch/powerpc/include/asm/vdso/vsyscall.h | 6 + arch/powerpc/include/asm/vdso_datapage.h | 2 + arch/powerpc/kernel/asm-offsets.c| 1 + arch/powerpc/kernel/vdso/Makefile| 57 +-- arch/powerpc/kernel/vdso/getrandom.S | 58 +++ arch/powerpc/kernel/vdso/gettimeofday.S | 13 - arch/powerpc/kernel/vdso/vdso32.lds.S| 1 + arch/powerpc/kernel/vdso/vdso64.lds.S| 1 + arch/powerpc/kernel/vdso/vgetrandom-chacha.S | 365 +++ arch/powerpc/kernel/vdso/vgetrandom.c| 14 + fs/proc/task_mmu.c | 4 +- include/linux/mm.h | 4 +- include/trace/events/mmflags.h | 4 +- tools/arch/powerpc/vdso | 1 + tools/testing/selftests/vDSO/Makefile| 2 +- 18 files changed, 547 insertions(+), 43 deletions(-) create mode 100644 arch/powerpc/include/asm/vdso/getrandom.h create mode 100644 arch/powerpc/kernel/vdso/getrandom.S create mode 100644 arch/powerpc/kernel/vdso/vgetrandom-chacha.S create mode 100644 arch/powerpc/kernel/vdso/vgetrandom.c create mode 12 tools/arch/powerpc/vdso -- 2.44.0
Re: [PATCH v4 5/5] powerpc/vdso: Wire up getrandom() vDSO implementation on PPC64
Hi Jason, hi Michael, Le 02/09/2024 à 16:19, Jason A. Donenfeld a écrit : On Mon, Sep 02, 2024 at 04:16:48PM +0200, Christophe Leroy wrote: Can do that, but there will still be a problem with chacha selftests if I don't opt-out the entire function content when it is ppc64. It will build properly but if someone runs it on a ppc64 it will likely crash because only the low 32 bits of registers will be saved. What if you don't wire up the selftests _at all_ until the ppc64 commit? Then there'll be no risk. (And I think I would prefer to see the 32-bit code all in the 32-bit commit; that'd make it more straight forward to review too.) I'd be fine with that but I'd like feedback from Michael on it: Is there a risk to only get PPC32 part merged as a first step or will both PPC32 and PPC64 go together anyway ? I would prefer not to delay PPC32 because someone doesn't feel confident with PPC64. Christophe
Re: [PATCH v4 5/5] powerpc/vdso: Wire up getrandom() vDSO implementation on PPC64
Le 02/09/2024 à 16:00, Jason A. Donenfeld a écrit : On Mon, Sep 02, 2024 at 03:12:47PM +0200, Christophe Leroy wrote: Le 02/09/2024 à 14:41, Jason A. Donenfeld a écrit : On Mon, Sep 02, 2024 at 02:04:42PM +0200, Christophe Leroy wrote: SYM_FUNC_START(__arch_chacha20_blocks_nostack) #ifdef __powerpc64__ - blr + std r5, -216(r1) + + std r14, -144(r1) + std r15, -136(r1) + std r16, -128(r1) + std r17, -120(r1) + std r18, -112(r1) + std r19, -104(r1) + std r20, -96(r1) + std r21, -88(r1) + std r22, -80(r1) + std r23, -72(r1) + std r24, -64(r1) + std r25, -56(r1) + std r26, -48(r1) + std r27, -40(r1) + std r28, -32(r1) + std r29, -24(r1) + std r30, -16(r1) + std r31, -8(r1) #else stwur1, -96(r1) stw r5, 20(r1) +#ifdef __BIG_ENDIAN__ stmwr14, 24(r1) +#else + stw r14, 24(r1) + stw r15, 28(r1) + stw r16, 32(r1) + stw r17, 36(r1) + stw r18, 40(r1) + stw r19, 44(r1) + stw r20, 48(r1) + stw r21, 52(r1) + stw r22, 56(r1) + stw r23, 60(r1) + stw r24, 64(r1) + stw r25, 68(r1) + stw r26, 72(r1) + stw r27, 76(r1) + stw r28, 80(r1) + stw r29, 84(r1) + stw r30, 88(r1) + stw r31, 92(r1) +#endif +#endif This confuses me. Why are you adding code to the !__powerpc64__ branch in this commit? (Also, why does stmw not work on LE?) That's for the VDSO32 ie running 32 bits binaries on a 64 bits kernel. "Programming Environments Manual for 32-Bit Implementations of the PowerPC™ Architecture" say: In some implementations operating with little-endian byte order, execution of an lmw or stmw instruction causes the system alignment error handler to be invoked And GCC doesn't like it either: tools/arch/powerpc/vdso/vgetrandom-chacha.S:84: Error: `stmw' invalid when little-endian Does it make sense to do all the 32-bit stuff in the PPC32 commit (and then you can introduce the selftests there without the error you mentioned), and then add the 64-bit stuff in this commit? Can do that, but there will still be a problem with chacha selftests if I don't opt-out the entire function content when it is ppc64. It will build properly but if someone runs it on a ppc64 it will likely crash because only the low 32 bits of registers will be saved. That's the reason why I really prefered the approach where I set something in vdso_config.h so that the assembly is used only for powerpc32 and when building powerpc64 the assembly part is kept out and vdso_test_chacha simply tells it is not supported. Christophe
Re: [PATCH v4 5/5] powerpc/vdso: Wire up getrandom() vDSO implementation on PPC64
Le 02/09/2024 à 14:41, Jason A. Donenfeld a écrit : On Mon, Sep 02, 2024 at 02:04:42PM +0200, Christophe Leroy wrote: SYM_FUNC_START(__arch_chacha20_blocks_nostack) #ifdef __powerpc64__ - blr + std r5, -216(r1) + + std r14, -144(r1) + std r15, -136(r1) + std r16, -128(r1) + std r17, -120(r1) + std r18, -112(r1) + std r19, -104(r1) + std r20, -96(r1) + std r21, -88(r1) + std r22, -80(r1) + std r23, -72(r1) + std r24, -64(r1) + std r25, -56(r1) + std r26, -48(r1) + std r27, -40(r1) + std r28, -32(r1) + std r29, -24(r1) + std r30, -16(r1) + std r31, -8(r1) #else stwur1, -96(r1) stw r5, 20(r1) +#ifdef __BIG_ENDIAN__ stmwr14, 24(r1) +#else + stw r14, 24(r1) + stw r15, 28(r1) + stw r16, 32(r1) + stw r17, 36(r1) + stw r18, 40(r1) + stw r19, 44(r1) + stw r20, 48(r1) + stw r21, 52(r1) + stw r22, 56(r1) + stw r23, 60(r1) + stw r24, 64(r1) + stw r25, 68(r1) + stw r26, 72(r1) + stw r27, 76(r1) + stw r28, 80(r1) + stw r29, 84(r1) + stw r30, 88(r1) + stw r31, 92(r1) +#endif +#endif This confuses me. Why are you adding code to the !__powerpc64__ branch in this commit? (Also, why does stmw not work on LE?) That's for the VDSO32 ie running 32 bits binaries on a 64 bits kernel. "Programming Environments Manual for 32-Bit Implementations of the PowerPC™ Architecture" say: In some implementations operating with little-endian byte order, execution of an lmw or stmw instruction causes the system alignment error handler to be invoked And GCC doesn't like it either: tools/arch/powerpc/vdso/vgetrandom-chacha.S:84: Error: `stmw' invalid when little-endian
Re: [PATCH v4 4/5] powerpc/vdso: Wire up getrandom() vDSO implementation on PPC32
Le 02/09/2024 à 14:34, Jason A. Donenfeld a écrit : On Mon, Sep 02, 2024 at 02:04:41PM +0200, Christophe Leroy wrote: This first patch adds support for PPC32. As selftests cannot easily be generated only for PPC32, and because the following patch brings support for PPC64 anyway, this patch opts out all code in __arch_chacha20_blocks_nostack() so that vdso_test_chacha will not fail to compile and will not crash on PPC64/PPC64LE, allthough the selftest itself will fail. This patch also adds a dummy __kernel_getrandom() function that returns ENOSYS on PPC64 so that vdso_test_getrandom returns KSFT_SKIP instead of KSFT_FAIL. Why not just wire up the selftests in the next patch like you did for v3? This seems like extra stuff for no huge reason? In v3 selftests were already wired up in v3, and there was the following build failure: $ make ARCH=powerpc CROSS_COMPILE=powerpc64le-linux- CC vdso_test_gettimeofday CC vdso_test_getcpu CC vdso_test_abi CC vdso_test_clock_getres CC vdso_test_correctness CC vdso_test_getrandom CC vdso_test_chacha /home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/arch/powerpc/vdso/vgetrandom-chacha.S: Assembler messages: /home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/arch/powerpc/vdso/vgetrandom-chacha.S:84: Error: `stmw' invalid when little-endian /home/chleroy/linux-powerpc/tools/testing/selftests/../../../tools/arch/powerpc/vdso/vgetrandom-chacha.S:198: Error: `lmw' invalid when little-endian make: *** [../lib.mk:222: /home/chleroy/linux-powerpc/tools/testing/selftests/vDSO/vdso_test_chacha] Error 1 So I did this change to get a clean PPC32 implementation before going into PPC64. I thought it was easier to go in two steps for reviews, bisectability, etc for just a very little extra stuff. arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/vdso/getrandom.h| 54 + arch/powerpc/include/asm/vdso/vsyscall.h | 6 + arch/powerpc/include/asm/vdso_datapage.h | 2 + arch/powerpc/kernel/asm-offsets.c| 1 + arch/powerpc/kernel/vdso/Makefile| 13 +- arch/powerpc/kernel/vdso/getrandom.S | 58 ++ arch/powerpc/kernel/vdso/vdso32.lds.S| 1 + arch/powerpc/kernel/vdso/vdso64.lds.S| 1 + arch/powerpc/kernel/vdso/vgetrandom-chacha.S | 207 +++ arch/powerpc/kernel/vdso/vgetrandom.c| 16 ++ tools/testing/selftests/vDSO/Makefile| 2 +- 12 files changed, 359 insertions(+), 3 deletions(-) create mode 100644 arch/powerpc/include/asm/vdso/getrandom.h create mode 100644 arch/powerpc/kernel/vdso/getrandom.S create mode 100644 arch/powerpc/kernel/vdso/vgetrandom-chacha.S create mode 100644 arch/powerpc/kernel/vdso/vgetrandom.c I think you might have forgotten to add the symlink in this commit (or the next one, per my comment above, if you agree with it). That's odd. All CI tests on github went ok !!! Looks like the CI tests for selftests are broken. Argh ! And of course on my computer the link was there so I didn't notice. +/* + * Very basic 32 bits implementation of ChaCha20. Produces a given positive number + * of blocks of output with a nonce of 0, taking an input key and 8-byte + * counter. Importantly does not spill to the stack. Its arguments are: + * + * r3: output bytes + * r4: 32-byte key input + * r5: 8-byte counter input/output (saved on stack) + * r6: number of 64-byte blocks to write to output + * + * r0: counter of blocks (initialised with r6) + * r4: Value '4' after key has been read. + * r5-r12: key + * r14-r15: counter + * r16-r31: state + */ +SYM_FUNC_START(__arch_chacha20_blocks_nostack) +#ifdef __powerpc64__ + blr +#else + stwur1, -96(r1) + stw r5, 20(r1) + stmwr14, 24(r1) + + lwz r14, 0(r5) + lwz r15, 4(r5) + mr r0, r6 + subir3, r3, 4 + + lwz r5, 0(r4) + lwz r6, 4(r4) + lwz r7, 8(r4) + lwz r8, 12(r4) + lwz r9, 16(r4) + lwz r10, 20(r4) + lwz r11, 24(r4) + lwz r12, 28(r4) If you don't want to do this, don't worry about it, but while I'm commenting on things, I think it's worth noting that x86, loongarch, and arm64 implementations all use the preprocessor or macros to give names to these registers -- state1,2,3,...copy1,2,3 and so forth. Might be worth doing the same if you think there's an easy and obvious way of doing it. If not -- or if that kind of work abhors you -- don't worry about it, as I'm confident enough that this code works fine. But it might be "nice to have". Up to you. I'll have a look. + + li r4, 4 +.Lblock: + li r31, 10 + Maybe a comment here, "expand 32-byte k"
[PATCH v4 5/5] powerpc/vdso: Wire up getrandom() vDSO implementation on PPC64
Extend getrandom() vDSO implementation to powerpc64. Tested on QEMU on both ppc64_defconfig and ppc64le_defconfig. The results are not precise as it is QEMU on an x86 laptop, but no need to be precise to see the benefit. ~ # ./vdso_test_getrandom bench-single vdso: 2500 times in 4.97162 seconds libc: 2500 times in 75.516749981 seconds syscall: 2500 times in 86.842242014 seconds ~ # ./vdso_test_getrandom bench-single vdso: 2500 times in 6.473814156 seconds libc: 2500 times in 73.875109463 seconds syscall: 2500 times in 71.805066229 seconds Signed-off-by: Christophe Leroy --- v4: - Use __BIG_ENDIAN__ which is defined by GCC instead of CONFIG_CPU_BIG_ENDIAN which is unknown by selftests - Implement a cleaner/smaller output copy for little endian instead of keeping compat macro. v3: New (split out of previous patch) --- arch/powerpc/Kconfig | 2 +- arch/powerpc/include/asm/mman.h | 2 +- arch/powerpc/kernel/vdso/Makefile| 11 +- arch/powerpc/kernel/vdso/getrandom.S | 16 +-- arch/powerpc/kernel/vdso/vgetrandom-chacha.S | 117 ++- arch/powerpc/kernel/vdso/vgetrandom.c| 2 - 6 files changed, 132 insertions(+), 18 deletions(-) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 54b270ef18b1..b45452ac4a73 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -311,7 +311,7 @@ config PPC select SYSCTL_EXCEPTION_TRACE select THREAD_INFO_IN_TASK select TRACE_IRQFLAGS_SUPPORT - select VDSO_GETRANDOM if PPC32 + select VDSO_GETRANDOM # # Please keep this list sorted alphabetically. # diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h index 17a77d47ed6d..42a51a993d94 100644 --- a/arch/powerpc/include/asm/mman.h +++ b/arch/powerpc/include/asm/mman.h @@ -6,7 +6,7 @@ #include -#ifdef CONFIG_PPC64 +#if defined(CONFIG_PPC64) && !defined(BUILD_VDSO) #include #include diff --git a/arch/powerpc/kernel/vdso/Makefile b/arch/powerpc/kernel/vdso/Makefile index af3ba61b022e..56fb1633529a 100644 --- a/arch/powerpc/kernel/vdso/Makefile +++ b/arch/powerpc/kernel/vdso/Makefile @@ -9,7 +9,7 @@ obj-vdso32 = sigtramp32-32.o gettimeofday-32.o datapage-32.o cacheflush-32.o not obj-vdso64 = sigtramp64-64.o gettimeofday-64.o datapage-64.o cacheflush-64.o note-64.o getcpu-64.o obj-vdso32 += getrandom-32.o vgetrandom-chacha-32.o -obj-vdso64 += getrandom-64.o +obj-vdso64 += getrandom-64.o vgetrandom-chacha-64.o ifneq ($(c-gettimeofday-y),) CFLAGS_vgettimeofday-32.o += -include $(c-gettimeofday-y) @@ -22,6 +22,7 @@ endif ifneq ($(c-getrandom-y),) CFLAGS_vgetrandom-32.o += -include $(c-getrandom-y) + CFLAGS_vgetrandom-64.o += -include $(c-getrandom-y) $(call cc-option, -ffixed-r30) endif # Build rules @@ -35,10 +36,10 @@ endif targets := $(obj-vdso32) vdso32.so.dbg vgettimeofday-32.o vgetrandom-32.o targets += crtsavres-32.o obj-vdso32 := $(addprefix $(obj)/, $(obj-vdso32)) -targets += $(obj-vdso64) vdso64.so.dbg vgettimeofday-64.o +targets += $(obj-vdso64) vdso64.so.dbg vgettimeofday-64.o vgetrandom-64.o obj-vdso64 := $(addprefix $(obj)/, $(obj-vdso64)) -ccflags-y := -fno-common -fno-builtin +ccflags-y := -fno-common -fno-builtin -DBUILD_VDSO ccflags-y += $(DISABLE_LATENT_ENTROPY_PLUGIN) ccflags-y += $(call cc-option, -fno-stack-protector) ccflags-y += -DDISABLE_BRANCH_PROFILING @@ -72,7 +73,7 @@ CPPFLAGS_vdso64.lds += -P -C # link rule for the .so file, .lds has to be first $(obj)/vdso32.so.dbg: $(obj)/vdso32.lds $(obj-vdso32) $(obj)/vgettimeofday-32.o $(obj)/vgetrandom-32.o $(obj)/crtsavres-32.o FORCE $(call if_changed,vdso32ld_and_check) -$(obj)/vdso64.so.dbg: $(obj)/vdso64.lds $(obj-vdso64) $(obj)/vgettimeofday-64.o FORCE +$(obj)/vdso64.so.dbg: $(obj)/vdso64.lds $(obj-vdso64) $(obj)/vgettimeofday-64.o $(obj)/vgetrandom-64.o FORCE $(call if_changed,vdso64ld_and_check) # assembly rules for the .S files @@ -88,6 +89,8 @@ $(obj-vdso64): %-64.o: %.S FORCE $(call if_changed_dep,vdso64as) $(obj)/vgettimeofday-64.o: %-64.o: %.c FORCE $(call if_changed_dep,cc_o_c) +$(obj)/vgetrandom-64.o: %-64.o: %.c FORCE + $(call if_changed_dep,cc_o_c) # Generate VDSO offsets using helper script gen-vdso32sym := $(src)/gen_vdso32_offsets.sh diff --git a/arch/powerpc/kernel/vdso/getrandom.S b/arch/powerpc/kernel/vdso/getrandom.S index 7db51c0635a5..a957cd2b2b03 100644 --- a/arch/powerpc/kernel/vdso/getrandom.S +++ b/arch/powerpc/kernel/vdso/getrandom.S @@ -5,8 +5,6 @@ * * Copyright (C) 2024 Christophe Leroy , CS GROUP France */ -#include - #include #include #include @@ -29,10 +27,18 @@ .cfi_adjust_cfa_offset PPC_MIN_STKFRM PPC_STL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1) .cfi_rel_offset lr, PPC_MIN_STKFRM + PPC_LR_STKOFF +#ifdef __powerpc64__ + PPC_STL
[PATCH v4 4/5] powerpc/vdso: Wire up getrandom() vDSO implementation on PPC32
To be consistent with other VDSO functions, the function is called __kernel_getrandom() __arch_chacha20_blocks_nostack() fonction is implemented basically with 32 bits operations. It performs 4 QUARTERROUND operations in parallele. There are enough registers to avoid using the stack: On input: r3: output bytes r4: 32-byte key input r5: 8-byte counter input/output r6: number of 64-byte blocks to write to output During operation: stack: pointer to counter (r5) and non-volatile registers (r14-131) r0: counter of blocks (initialised with r6) r4: Value '4' after key has been read, used for indexing r5-r12: key r14-r15: block counter r16-r31: chacha state At the end: r0, r6-r12: Zeroised r5, r14-r31: Restored Performance on powerpc 885 (using kernel selftest): ~# ./vdso_test_getrandom bench-single vdso: 2500 times in 62.938002291 seconds libc: 2500 times in 535.581916866 seconds syscall: 2500 times in 531.525042806 seconds Performance on powerpc 8321 (using kernel selftest): ~# ./vdso_test_getrandom bench-single vdso: 2500 times in 16.899318858 seconds libc: 2500 times in 131.050596522 seconds syscall: 2500 times in 129.794790389 seconds This first patch adds support for PPC32. As selftests cannot easily be generated only for PPC32, and because the following patch brings support for PPC64 anyway, this patch opts out all code in __arch_chacha20_blocks_nostack() so that vdso_test_chacha will not fail to compile and will not crash on PPC64/PPC64LE, allthough the selftest itself will fail. This patch also adds a dummy __kernel_getrandom() function that returns ENOSYS on PPC64 so that vdso_test_getrandom returns KSFT_SKIP instead of KSFT_FAIL. Signed-off-by: Christophe Leroy --- v4: - Counter has native byte order - Fix selftest build on ppc64le until implemented. - On ppc64, for now implement __kernel_getrandom to return ENOSYS error - Use stwbrx directly, not compat macro. v3: - Preserve r13, implies saving r5 on stack - Split PPC64 implementation out. --- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/vdso/getrandom.h| 54 + arch/powerpc/include/asm/vdso/vsyscall.h | 6 + arch/powerpc/include/asm/vdso_datapage.h | 2 + arch/powerpc/kernel/asm-offsets.c| 1 + arch/powerpc/kernel/vdso/Makefile| 13 +- arch/powerpc/kernel/vdso/getrandom.S | 58 ++ arch/powerpc/kernel/vdso/vdso32.lds.S| 1 + arch/powerpc/kernel/vdso/vdso64.lds.S| 1 + arch/powerpc/kernel/vdso/vgetrandom-chacha.S | 207 +++ arch/powerpc/kernel/vdso/vgetrandom.c| 16 ++ tools/testing/selftests/vDSO/Makefile| 2 +- 12 files changed, 359 insertions(+), 3 deletions(-) create mode 100644 arch/powerpc/include/asm/vdso/getrandom.h create mode 100644 arch/powerpc/kernel/vdso/getrandom.S create mode 100644 arch/powerpc/kernel/vdso/vgetrandom-chacha.S create mode 100644 arch/powerpc/kernel/vdso/vgetrandom.c diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index d7b09b064a8a..54b270ef18b1 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -311,6 +311,7 @@ config PPC select SYSCTL_EXCEPTION_TRACE select THREAD_INFO_IN_TASK select TRACE_IRQFLAGS_SUPPORT + select VDSO_GETRANDOM if PPC32 # # Please keep this list sorted alphabetically. # diff --git a/arch/powerpc/include/asm/vdso/getrandom.h b/arch/powerpc/include/asm/vdso/getrandom.h new file mode 100644 index ..501d6bb14e8a --- /dev/null +++ b/arch/powerpc/include/asm/vdso/getrandom.h @@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2024 Christophe Leroy , CS GROUP France + */ +#ifndef _ASM_POWERPC_VDSO_GETRANDOM_H +#define _ASM_POWERPC_VDSO_GETRANDOM_H + +#ifndef __ASSEMBLY__ + +static __always_inline int do_syscall_3(const unsigned long _r0, const unsigned long _r3, + const unsigned long _r4, const unsigned long _r5) +{ + register long r0 asm("r0") = _r0; + register unsigned long r3 asm("r3") = _r3; + register unsigned long r4 asm("r4") = _r4; + register unsigned long r5 asm("r5") = _r5; + register int ret asm ("r3"); + + asm volatile( + " sc\n" + " bns+1f\n" + " neg %0, %0\n" + "1:\n" + : "=r" (ret), "+r" (r4), "+r" (r5), "+r" (r0) + : "r" (r3) + : "memory", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "cr0", &
[PATCH v4 3/5] powerpc/vdso: Refactor CFLAGS for CVDSO build
In order to avoid two much duplication when we add new VDSO functionnalities in C like getrandom, refactor common CFLAGS. Signed-off-by: Christophe Leroy --- v3: Also refactor removed flags --- arch/powerpc/kernel/vdso/Makefile | 32 +-- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/arch/powerpc/kernel/vdso/Makefile b/arch/powerpc/kernel/vdso/Makefile index c07a425b8f78..67fe79d26fae 100644 --- a/arch/powerpc/kernel/vdso/Makefile +++ b/arch/powerpc/kernel/vdso/Makefile @@ -10,28 +10,11 @@ obj-vdso64 = sigtramp64-64.o gettimeofday-64.o datapage-64.o cacheflush-64.o not ifneq ($(c-gettimeofday-y),) CFLAGS_vgettimeofday-32.o += -include $(c-gettimeofday-y) - CFLAGS_vgettimeofday-32.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) - CFLAGS_vgettimeofday-32.o += $(call cc-option, -fno-stack-protector) - CFLAGS_vgettimeofday-32.o += -DDISABLE_BRANCH_PROFILING - CFLAGS_vgettimeofday-32.o += -ffreestanding -fasynchronous-unwind-tables - CFLAGS_REMOVE_vgettimeofday-32.o = $(CC_FLAGS_FTRACE) - CFLAGS_REMOVE_vgettimeofday-32.o += -mcmodel=medium -mabi=elfv1 -mabi=elfv2 -mcall-aixdesc - # This flag is supported by clang for 64-bit but not 32-bit so it will cause - # an unused command line flag warning for this file. - ifdef CONFIG_CC_IS_CLANG - CFLAGS_REMOVE_vgettimeofday-32.o += -fno-stack-clash-protection - endif - CFLAGS_vgettimeofday-64.o += -include $(c-gettimeofday-y) - CFLAGS_vgettimeofday-64.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) - CFLAGS_vgettimeofday-64.o += $(call cc-option, -fno-stack-protector) - CFLAGS_vgettimeofday-64.o += -DDISABLE_BRANCH_PROFILING - CFLAGS_vgettimeofday-64.o += -ffreestanding -fasynchronous-unwind-tables - CFLAGS_REMOVE_vgettimeofday-64.o = $(CC_FLAGS_FTRACE) # Go prior to 1.16.x assumes r30 is not clobbered by any VDSO code. That used to be true # by accident when the VDSO was hand-written asm code, but may not be now that the VDSO is # compiler generated. To avoid breaking Go tell GCC not to use r30. Impact on code # generation is minimal, it will just use r29 instead. - CFLAGS_vgettimeofday-64.o += $(call cc-option, -ffixed-r30) + CFLAGS_vgettimeofday-64.o += -include $(c-gettimeofday-y) $(call cc-option, -ffixed-r30) endif # Build rules @@ -49,6 +32,11 @@ targets += $(obj-vdso64) vdso64.so.dbg vgettimeofday-64.o obj-vdso64 := $(addprefix $(obj)/, $(obj-vdso64)) ccflags-y := -fno-common -fno-builtin +ccflags-y += $(DISABLE_LATENT_ENTROPY_PLUGIN) +ccflags-y += $(call cc-option, -fno-stack-protector) +ccflags-y += -DDISABLE_BRANCH_PROFILING +ccflags-y += -ffreestanding -fasynchronous-unwind-tables +ccflags-remove-y := $(CC_FLAGS_FTRACE) ldflags-y := -Wl,--hash-style=both -nostdlib -shared -z noexecstack $(CLANG_FLAGS) ldflags-$(CONFIG_LD_IS_LLD) += $(call cc-option,--ld-path=$(LD),-fuse-ld=lld) ldflags-$(CONFIG_LD_ORPHAN_WARN) += -Wl,--orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL) @@ -57,6 +45,12 @@ ldflags-$(CONFIG_LD_ORPHAN_WARN) += -Wl,--orphan-handling=$(CONFIG_LD_ORPHAN_WAR ldflags-y += $(filter-out $(CC_AUTO_VAR_INIT_ZERO_ENABLER) $(CC_FLAGS_FTRACE) -Wa$(comma)%, $(KBUILD_CFLAGS)) CC32FLAGS := -m32 +CC32FLAGSREMOVE := -mcmodel=medium -mabi=elfv1 -mabi=elfv2 -mcall-aixdesc + # This flag is supported by clang for 64-bit but not 32-bit so it will cause + # an unused command line flag warning for this file. +ifdef CONFIG_CC_IS_CLANG +CC32FLAGSREMOVE += -fno-stack-clash-protection +endif LD32FLAGS := -Wl,-soname=linux-vdso32.so.1 AS32FLAGS := -D__VDSO32__ @@ -105,7 +99,7 @@ quiet_cmd_vdso32ld_and_check = VDSO32L $@ quiet_cmd_vdso32as = VDSO32A $@ cmd_vdso32as = $(VDSOCC) $(a_flags) $(CC32FLAGS) $(AS32FLAGS) -c -o $@ $< quiet_cmd_vdso32cc = VDSO32C $@ - cmd_vdso32cc = $(VDSOCC) $(c_flags) $(CC32FLAGS) -c -o $@ $< + cmd_vdso32cc = $(VDSOCC) $(filter-out $(CC32FLAGSREMOVE), $(c_flags)) $(CC32FLAGS) -c -o $@ $< quiet_cmd_vdso64ld_and_check = VDSO64L $@ cmd_vdso64ld_and_check = $(VDSOCC) $(ldflags-y) $(LD64FLAGS) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^); $(cmd_vdso_check) -- 2.44.0
[PATCH v4 1/5] mm: Define VM_DROPPABLE for powerpc/32
Commit 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings") only adds VM_DROPPABLE for 64 bits architectures. In order to also use the getrandom vDSO implementation on powerpc/32, use VM_ARCH_1 for VM_DROPPABLE on powerpc/32. This is possible because VM_ARCH_1 is used for VM_SAO on powerpc and VM_SAO is only for powerpc/64. It is used in combination with PROT_SAO in some parts of code that are restricted to CONFIG_PPC64 through #ifdefs, it is therefore possible to define VM_SAO for CONFIG_PPC64 only. Signed-off-by: Christophe Leroy --- v4: Added more details in commit message following comment from Michael. v3: Fixed build failure reported by robots. --- fs/proc/task_mmu.c | 4 +++- include/linux/mm.h | 4 +++- include/trace/events/mmflags.h | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 5f171ad7b436..3a07e13e2f81 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -987,8 +987,10 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma) #ifdef CONFIG_X86_USER_SHADOW_STACK [ilog2(VM_SHADOW_STACK)] = "ss", #endif -#ifdef CONFIG_64BIT +#if defined(CONFIG_64BIT) || defined(CONFIG_PPC32) [ilog2(VM_DROPPABLE)] = "dp", +#endif +#ifdef CONFIG_64BIT [ilog2(VM_SEALED)] = "sl", #endif }; diff --git a/include/linux/mm.h b/include/linux/mm.h index 6549d0979b28..028847f39442 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -359,7 +359,7 @@ extern unsigned int kobjsize(const void *objp); #if defined(CONFIG_X86) # define VM_PATVM_ARCH_1 /* PAT reserves whole VMA at once (x86) */ -#elif defined(CONFIG_PPC) +#elif defined(CONFIG_PPC64) # define VM_SAOVM_ARCH_1 /* Strong Access Ordering (powerpc) */ #elif defined(CONFIG_PARISC) # define VM_GROWSUPVM_ARCH_1 @@ -409,6 +409,8 @@ extern unsigned int kobjsize(const void *objp); #ifdef CONFIG_64BIT #define VM_DROPPABLE_BIT 40 #define VM_DROPPABLE BIT(VM_DROPPABLE_BIT) +#elif defined(CONFIG_PPC32) +#define VM_DROPPABLE VM_ARCH_1 #else #define VM_DROPPABLE VM_NONE #endif diff --git a/include/trace/events/mmflags.h b/include/trace/events/mmflags.h index b63d211bd141..37265977d524 100644 --- a/include/trace/events/mmflags.h +++ b/include/trace/events/mmflags.h @@ -143,7 +143,7 @@ IF_HAVE_PG_ARCH_X(arch_3) #if defined(CONFIG_X86) #define __VM_ARCH_SPECIFIC_1 {VM_PAT, "pat" } -#elif defined(CONFIG_PPC) +#elif defined(CONFIG_PPC64) #define __VM_ARCH_SPECIFIC_1 {VM_SAO, "sao" } #elif defined(CONFIG_PARISC) #define __VM_ARCH_SPECIFIC_1 {VM_GROWSUP, "growsup" } @@ -165,7 +165,7 @@ IF_HAVE_PG_ARCH_X(arch_3) # define IF_HAVE_UFFD_MINOR(flag, name) #endif -#ifdef CONFIG_64BIT +#if defined(CONFIG_64BIT) || defined(CONFIG_PPC32) # define IF_HAVE_VM_DROPPABLE(flag, name) {flag, name}, #else # define IF_HAVE_VM_DROPPABLE(flag, name) -- 2.44.0
[PATCH v4 2/5] powerpc/vdso32: Add crtsavres
Commit 08c18b63d965 ("powerpc/vdso32: Add missing _restgpr_31_x to fix build failure") added _restgpr_31_x to the vdso for gettimeofday, but the work on getrandom shows that we will need more of those functions. Remove _restgpr_31_x and link in crtsavres.o so that we get all save/restore functions when optimising the kernel for size. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/vdso/Makefile | 5 - arch/powerpc/kernel/vdso/gettimeofday.S | 13 - 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/arch/powerpc/kernel/vdso/Makefile b/arch/powerpc/kernel/vdso/Makefile index 1425b6edc66b..c07a425b8f78 100644 --- a/arch/powerpc/kernel/vdso/Makefile +++ b/arch/powerpc/kernel/vdso/Makefile @@ -43,6 +43,7 @@ else endif targets := $(obj-vdso32) vdso32.so.dbg vgettimeofday-32.o +targets += crtsavres-32.o obj-vdso32 := $(addprefix $(obj)/, $(obj-vdso32)) targets += $(obj-vdso64) vdso64.so.dbg vgettimeofday-64.o obj-vdso64 := $(addprefix $(obj)/, $(obj-vdso64)) @@ -68,7 +69,7 @@ targets += vdso64.lds CPPFLAGS_vdso64.lds += -P -C # link rule for the .so file, .lds has to be first -$(obj)/vdso32.so.dbg: $(obj)/vdso32.lds $(obj-vdso32) $(obj)/vgettimeofday-32.o FORCE +$(obj)/vdso32.so.dbg: $(obj)/vdso32.lds $(obj-vdso32) $(obj)/vgettimeofday-32.o $(obj)/crtsavres-32.o FORCE $(call if_changed,vdso32ld_and_check) $(obj)/vdso64.so.dbg: $(obj)/vdso64.lds $(obj-vdso64) $(obj)/vgettimeofday-64.o FORCE $(call if_changed,vdso64ld_and_check) @@ -76,6 +77,8 @@ $(obj)/vdso64.so.dbg: $(obj)/vdso64.lds $(obj-vdso64) $(obj)/vgettimeofday-64.o # assembly rules for the .S files $(obj-vdso32): %-32.o: %.S FORCE $(call if_changed_dep,vdso32as) +$(obj)/crtsavres-32.o: %-32.o: $(srctree)/arch/powerpc/lib/crtsavres.S FORCE + $(call if_changed_dep,vdso32as) $(obj)/vgettimeofday-32.o: %-32.o: %.c FORCE $(call if_changed_dep,vdso32cc) $(obj-vdso64): %-64.o: %.S FORCE diff --git a/arch/powerpc/kernel/vdso/gettimeofday.S b/arch/powerpc/kernel/vdso/gettimeofday.S index 48fc6658053a..67254ac9c8bb 100644 --- a/arch/powerpc/kernel/vdso/gettimeofday.S +++ b/arch/powerpc/kernel/vdso/gettimeofday.S @@ -118,16 +118,3 @@ V_FUNCTION_END(__kernel_clock_getres) V_FUNCTION_BEGIN(__kernel_time) cvdso_call __c_kernel_time call_time=1 V_FUNCTION_END(__kernel_time) - -/* Routines for restoring integer registers, called by the compiler. */ -/* Called with r11 pointing to the stack header word of the caller of the */ -/* function, just beyond the end of the integer restore area. */ -#ifndef __powerpc64__ -_GLOBAL(_restgpr_31_x) -_GLOBAL(_rest32gpr_31_x) - lwz r0,4(r11) - lwz r31,-4(r11) - mtlrr0 - mr r1,r11 - blr -#endif -- 2.44.0
[PATCH v4 0/5] Wire up getrandom() vDSO implementation on powerpc
This series wires up getrandom() vDSO implementation on powerpc. Tested on PPC32 on real hardware. Tested on PPC64 (both BE and LE) on QEMU: Performance on powerpc 885: ~# ./vdso_test_getrandom bench-single vdso: 2500 times in 62.938002291 seconds libc: 2500 times in 535.581916866 seconds syscall: 2500 times in 531.525042806 seconds Performance on powerpc 8321: ~# ./vdso_test_getrandom bench-single vdso: 2500 times in 16.899318858 seconds libc: 2500 times in 131.050596522 seconds syscall: 2500 times in 129.794790389 seconds Performance on QEMU pseries: ~ # ./vdso_test_getrandom bench-single vdso: 2500 times in 4.97162 seconds libc: 2500 times in 75.516749981 seconds syscall: 2500 times in 86.842242014 seconds Changes in v4: - Rebased on recent random git tree (963233ff0133) (The new tree includes selftests fixes) - Read/write counter in native byte order - Don't use anymore compat macros to write output - Fixed selftests build failure with patch 4 (without patch 5) on little endian on PPC64 - Implement a __kernel_getrandom() stub returning ENOSYS on ppc64 in patch 4 (without patch 5) to make selftests happy. Changes in v3: - Rebased on recent random git tree (0c7e00e22c21) - Fixed build failures reported by robots around VM_DROPPABLE - Fixed crash on PPC64 due to clobbered r13 by not using r13 anymore (saving it was not enough for signals). - Split final patch in two, first for PPC32, second for PPC64 - Moved selftest fixes out of this series Changes in v2: - Define VM_DROPPABLE for powerpc/32 - Fixes generic vDSO getrandom headers to enable CONFIG_COMPAT build. - Fixed size of generation counter - Fixed selftests to work on non x86 architectures Christophe Leroy (5): mm: Define VM_DROPPABLE for powerpc/32 powerpc/vdso32: Add crtsavres powerpc/vdso: Refactor CFLAGS for CVDSO build powerpc/vdso: Wire up getrandom() vDSO implementation on PPC32 powerpc/vdso: Wire up getrandom() vDSO implementation on PPC64 arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/mman.h | 2 +- arch/powerpc/include/asm/vdso/getrandom.h| 54 arch/powerpc/include/asm/vdso/vsyscall.h | 6 + arch/powerpc/include/asm/vdso_datapage.h | 2 + arch/powerpc/kernel/asm-offsets.c| 1 + arch/powerpc/kernel/vdso/Makefile| 57 ++-- arch/powerpc/kernel/vdso/getrandom.S | 58 arch/powerpc/kernel/vdso/gettimeofday.S | 13 - arch/powerpc/kernel/vdso/vdso32.lds.S| 1 + arch/powerpc/kernel/vdso/vdso64.lds.S| 1 + arch/powerpc/kernel/vdso/vgetrandom-chacha.S | 320 +++ arch/powerpc/kernel/vdso/vgetrandom.c| 14 + fs/proc/task_mmu.c | 4 +- include/linux/mm.h | 4 +- include/trace/events/mmflags.h | 4 +- tools/testing/selftests/vDSO/Makefile| 2 +- 17 files changed, 501 insertions(+), 43 deletions(-) create mode 100644 arch/powerpc/include/asm/vdso/getrandom.h create mode 100644 arch/powerpc/kernel/vdso/getrandom.S create mode 100644 arch/powerpc/kernel/vdso/vgetrandom-chacha.S create mode 100644 arch/powerpc/kernel/vdso/vgetrandom.c -- 2.44.0
Re: [PATCH 0/2] mm: make copy_to_kernel_nofault() not fault on user addresses
Le 02/09/2024 à 07:31, Omar Sandoval a écrit : [Vous ne recevez pas souvent de courriers de osan...@osandov.com. Découvrez pourquoi ceci est important à https://aka.ms/LearnAboutSenderIdentification ] From: Omar Sandoval Hi, I hit a case where copy_to_kernel_nofault() will fault (lol): if the destination address is in userspace and x86 Supervisor Mode Access Prevention is enabled. Patch 2 has the details and the fix. Patch 1 renames a helper function so that its use in patch 2 makes more sense. If the rename is too intrusive, I can drop it. The name of the function is "copy_to_kernel". If the destination is a user address, it is not a copy to kernel but a copy to user and you already have the function copy_to_user() for that. copy_to_user() properly handles SMAP. Christophe Thanks, Omar Omar Sandoval (2): mm: rename copy_from_kernel_nofault_allowed() to copy_kernel_nofault_allowed() mm: make copy_to_kernel_nofault() not fault on user addresses arch/arm/mm/fault.c | 2 +- arch/loongarch/mm/maccess.c | 2 +- arch/mips/mm/maccess.c | 2 +- arch/parisc/lib/memcpy.c| 2 +- arch/powerpc/mm/maccess.c | 2 +- arch/um/kernel/maccess.c| 2 +- arch/x86/mm/maccess.c | 4 ++-- include/linux/uaccess.h | 2 +- mm/maccess.c| 10 ++ 9 files changed, 15 insertions(+), 13 deletions(-) -- 2.46.0
[PATCH] selftests: vDSO: Also test counter in vdso_test_chacha
The chacha vDSO selftest doesn't check the way the counter is handled by __arch_chacha20_blocks_nostack(). It indirectly checks that the counter is writen on exit and read back on new entry, but it doesn't check that the format is correct. It has led to an invisible erroneous implementation on powerpc where the counter was writen and read in wrong byte order. Also, the counter uses two words, but the tests with a zero counter and uses a small amount of blocks so at the end the upper part of the counter is always 0 so it is not checked. Add a verification of counter's content in addition to the verification of the output. Also add two tests where the counter crosses the u32 upper limit. The first test verifies that the function properly writes back the upper word, the second test verifies that the function properly reads back the upper word. While at it, remove 'nonce' which is not unused anymore after the replacement of libsodium by open coded chacha implementation. Signed-off-by: Christophe Leroy --- .../testing/selftests/vDSO/vdso_test_chacha.c | 39 ++- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/tools/testing/selftests/vDSO/vdso_test_chacha.c b/tools/testing/selftests/vDSO/vdso_test_chacha.c index 9d18d49a82f8..ed6cf372d9ee 100644 --- a/tools/testing/selftests/vDSO/vdso_test_chacha.c +++ b/tools/testing/selftests/vDSO/vdso_test_chacha.c @@ -17,11 +17,12 @@ static uint32_t rol32(uint32_t word, unsigned int shift) return (word << (shift & 31)) | (word >> ((-shift) & 31)); } -static void reference_chacha20_blocks(uint8_t *dst_bytes, const uint32_t *key, size_t nblocks) +static void reference_chacha20_blocks(uint8_t *dst_bytes, const uint32_t *key, uint32_t *counter, size_t nblocks) { uint32_t s[16] = { 0x61707865U, 0x3320646eU, 0x79622d32U, 0x6b206574U, - key[0], key[1], key[2], key[3], key[4], key[5], key[6], key[7] + key[0], key[1], key[2], key[3], key[4], key[5], key[6], key[7], + counter[0], counter[1], }; while (nblocks--) { @@ -52,6 +53,8 @@ static void reference_chacha20_blocks(uint8_t *dst_bytes, const uint32_t *key, s if (!++s[12]) ++s[13]; } + counter[0] = s[12]; + counter[1] = s[13]; } typedef uint8_t u8; @@ -66,8 +69,7 @@ typedef uint64_t u64; int main(int argc, char *argv[]) { enum { TRIALS = 1000, BLOCKS = 128, BLOCK_SIZE = 64 }; - static const uint8_t nonce[8] = { 0 }; - uint32_t counter[2]; + uint32_t counter1[2], counter2[2]; uint32_t key[8]; uint8_t output1[BLOCK_SIZE * BLOCKS], output2[BLOCK_SIZE * BLOCKS]; @@ -84,17 +86,36 @@ int main(int argc, char *argv[]) printf("getrandom() failed!\n"); return KSFT_SKIP; } - reference_chacha20_blocks(output1, key, BLOCKS); + memset(counter1, 0, sizeof(counter1)); + reference_chacha20_blocks(output1, key, counter1, BLOCKS); for (unsigned int split = 0; split < BLOCKS; ++split) { memset(output2, 'X', sizeof(output2)); - memset(counter, 0, sizeof(counter)); + memset(counter2, 0, sizeof(counter2)); if (split) - __arch_chacha20_blocks_nostack(output2, key, counter, split); - __arch_chacha20_blocks_nostack(output2 + split * BLOCK_SIZE, key, counter, BLOCKS - split); - if (memcmp(output1, output2, sizeof(output1))) + __arch_chacha20_blocks_nostack(output2, key, counter2, split); + __arch_chacha20_blocks_nostack(output2 + split * BLOCK_SIZE, key, counter2, BLOCKS - split); + if (memcmp(output1, output2, sizeof(output1)) || + memcmp(counter2, counter2, sizeof(counter1))) return KSFT_FAIL; } } + memset(counter1, 0, sizeof(counter1)); + counter1[0] = (uint32_t)-BLOCKS + 2; + memset(counter2, 0, sizeof(counter2)); + counter2[0] = (uint32_t)-BLOCKS + 2; + + reference_chacha20_blocks(output1, key, counter1, BLOCKS); + __arch_chacha20_blocks_nostack(output2, key, counter2, BLOCKS); + if (memcmp(output1, output2, sizeof(output1)) || + memcmp(counter2, counter2, sizeof(counter1))) + return KSFT_FAIL; + + reference_chacha20_blocks(output1, key, counter1, BLOCKS); + __arch_chacha20_blocks_nostack(output2, key, counter2, BLOCKS); + if (memcmp(output1, output2, sizeof(output1)) || + memcmp(counter2, counter2, sizeof(counter1))) + return KSFT_FAIL; + ksft_test_result_pass("chacha: PASS\n"); return KSFT_PASS; } -- 2.44.0
[PATCH] selftests: vDSO: Build vDSO tests with O2 optimisation
Without -O2, the generated code for testing chacha function is awful. GCC even implements rol32() as a function instead of just using the rotlwi instruction, that function is 20 instructions long. ~# time ./vdso_test_chacha TAP version 13 1..1 ok 1 chacha: PASS real0m 37.16s user0m 36.89s sys 0m 0.26s Several other selftests directory add -O2, and the kernel is also always built with optimisation active. Do the same for vDSO selftests. With this patch the time is reduced by approx 15%. ~# time ./vdso_test_chacha TAP version 13 1..1 ok 1 chacha: PASS real0m 32.09s user0m 31.86s sys 0m 0.22s Signed-off-by: Christophe Leroy --- tools/testing/selftests/vDSO/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/testing/selftests/vDSO/Makefile b/tools/testing/selftests/vDSO/Makefile index cfb7c281b22c..96f25aa2f84e 100644 --- a/tools/testing/selftests/vDSO/Makefile +++ b/tools/testing/selftests/vDSO/Makefile @@ -13,7 +13,7 @@ TEST_GEN_PROGS += vdso_test_correctness TEST_GEN_PROGS += vdso_test_getrandom TEST_GEN_PROGS += vdso_test_chacha -CFLAGS := -std=gnu99 +CFLAGS := -std=gnu99 -O2 ifeq ($(CONFIG_X86_32),y) LDLIBS += -lgcc_s -- 2.44.0
Re: [PATCH v3 4/5] powerpc/vdso: Wire up getrandom() vDSO implementation on PPC32
Le 30/08/2024 à 18:17, Jason A. Donenfeld a écrit : On Fri, Aug 30, 2024 at 05:57:08PM +0200, Christophe Leroy wrote: @@ -14,6 +14,10 @@ ifeq ($(uname_M),x86_64) TEST_GEN_PROGS += vdso_test_getrandom TEST_GEN_PROGS += vdso_test_chacha endif +ifeq ($(ARCH),powerpc) +TEST_GEN_PROGS += vdso_test_getrandom +TEST_GEN_PROGS += vdso_test_chacha +endif FYI, as of [1], you should now be able to add powerpc to the filter list instead of having to duplicate a new stanza: [1] https://eur01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgit.kernel.org%2Fpub%2Fscm%2Flinux%2Fkernel%2Fgit%2Fcrng%2Frandom.git%2Fcommit%2F%3Fid%3Dbbaae98172ed284fc0d5d39cc0d68f5d06164f06&data=05%7C02%7Cchristophe.leroy%40csgroup.eu%7C4f51736c027a44cc7df908dcc90f46d6%7C8b87af7d86474dc78df45f69a2011bb5%7C0%7C0%7C638606314665557021%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C0%7C%7C%7C&sdata=UtLdKTuEaZVhsguKa7kX1TBJ%2BvvQtl7DmU9hSBeThWo%3D&reserved=0 I'm a bit sceptic with that commit. IIUC you are changing the meaning of $ARCH. How does that fit with the $ARCH we give when we cross-build or with the ARCH which is set by the top-level Makefile in tools/testing/selftests ? Also, wouldn't there be a way to use scripts/subarch.include instead of opencoding ? Afterall, would it be a problem to build it even for i386 ? It should now be ignored anyway with your new commit f78280b1a3ce ("selftests: vDSO: skip getrandom test if architecture is unsupported") Christophe
Re: [PATCH v3 4/5] powerpc/vdso: Wire up getrandom() vDSO implementation on PPC32
Le 30/08/2024 à 18:42, Christophe Leroy a écrit : Le 30/08/2024 à 18:14, Jason A. Donenfeld a écrit : On Fri, Aug 30, 2024 at 05:57:08PM +0200, Christophe Leroy wrote: + * r5: 8-byte counter input/output (saved on stack) + * + * r14-r15: counter + */ +SYM_FUNC_START(__arch_chacha20_blocks_nostack) + stwu r1, -96(r1) + stw r5, 20(r1) + stmw r14, 24(r1) + li r31, 4 + LWZX_LE r14, 0, r5 + LWZX_LE r15, r31, r5 Why swap endian on the counter? Unlike the keys, the counter is passed to the function as an u8*, not as a u64*, so I thought it was raw data in little endian order, same as when using Sodium. Is it wrong ? Hum . I looked again and it seems it is already a u32 *. Looks like I mis-read the 8-byte comment. Or I did it right in the begining then I swapped it at the same time as I swapped the keys after my first test when the selftest was using Sodium. I can't remember. I'll fix it. Christophe
Re: [PATCH v3 4/5] powerpc/vdso: Wire up getrandom() vDSO implementation on PPC32
Le 30/08/2024 à 18:14, Jason A. Donenfeld a écrit : On Fri, Aug 30, 2024 at 05:57:08PM +0200, Christophe Leroy wrote: + * r5: 8-byte counter input/output (saved on stack) + * + * r14-r15: counter + */ +SYM_FUNC_START(__arch_chacha20_blocks_nostack) + stwur1, -96(r1) + stw r5, 20(r1) + stmwr14, 24(r1) + li r31, 4 + LWZX_LE r14, 0, r5 + LWZX_LE r15, r31, r5 Why swap endian on the counter? Unlike the keys, the counter is passed to the function as an u8*, not as a u64*, so I thought it was raw data in little endian order, same as when using Sodium. Is it wrong ? Christophe
[PATCH v3 5/5] powerpc/vdso: Wire up getrandom() vDSO implementation on PPC64
Extend getrandom() vDSO implementation to powerpc64. Tested on QEMU on both ppc64_defconfig and ppc64le_defconfig. The results are not precise as it is QEMU on an x86 laptop, but no need to be precise to see the benefit. ~ # ./vdso_test_getrandom bench-single vdso: 2500 times in 4.97162 seconds libc: 2500 times in 75.516749981 seconds syscall: 2500 times in 86.842242014 seconds ~ # ./vdso_test_getrandom bench-single vdso: 2500 times in 6.473814156 seconds libc: 2500 times in 73.875109463 seconds syscall: 2500 times in 71.805066229 seconds Signed-off-by: Christophe Leroy --- v3: New (split out of previous patch) --- arch/powerpc/Kconfig | 2 +- arch/powerpc/include/asm/mman.h | 2 +- arch/powerpc/kernel/vdso/Makefile| 10 +- arch/powerpc/kernel/vdso/getrandom.S | 8 ++ arch/powerpc/kernel/vdso/vdso64.lds.S| 1 + arch/powerpc/kernel/vdso/vgetrandom-chacha.S | 98 6 files changed, 116 insertions(+), 5 deletions(-) diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index 54b270ef18b1..b45452ac4a73 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -311,7 +311,7 @@ config PPC select SYSCTL_EXCEPTION_TRACE select THREAD_INFO_IN_TASK select TRACE_IRQFLAGS_SUPPORT - select VDSO_GETRANDOM if PPC32 + select VDSO_GETRANDOM # # Please keep this list sorted alphabetically. # diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h index 17a77d47ed6d..42a51a993d94 100644 --- a/arch/powerpc/include/asm/mman.h +++ b/arch/powerpc/include/asm/mman.h @@ -6,7 +6,7 @@ #include -#ifdef CONFIG_PPC64 +#if defined(CONFIG_PPC64) && !defined(BUILD_VDSO) #include #include diff --git a/arch/powerpc/kernel/vdso/Makefile b/arch/powerpc/kernel/vdso/Makefile index fa0b9b3b51af..56fb1633529a 100644 --- a/arch/powerpc/kernel/vdso/Makefile +++ b/arch/powerpc/kernel/vdso/Makefile @@ -9,6 +9,7 @@ obj-vdso32 = sigtramp32-32.o gettimeofday-32.o datapage-32.o cacheflush-32.o not obj-vdso64 = sigtramp64-64.o gettimeofday-64.o datapage-64.o cacheflush-64.o note-64.o getcpu-64.o obj-vdso32 += getrandom-32.o vgetrandom-chacha-32.o +obj-vdso64 += getrandom-64.o vgetrandom-chacha-64.o ifneq ($(c-gettimeofday-y),) CFLAGS_vgettimeofday-32.o += -include $(c-gettimeofday-y) @@ -21,6 +22,7 @@ endif ifneq ($(c-getrandom-y),) CFLAGS_vgetrandom-32.o += -include $(c-getrandom-y) + CFLAGS_vgetrandom-64.o += -include $(c-getrandom-y) $(call cc-option, -ffixed-r30) endif # Build rules @@ -34,10 +36,10 @@ endif targets := $(obj-vdso32) vdso32.so.dbg vgettimeofday-32.o vgetrandom-32.o targets += crtsavres-32.o obj-vdso32 := $(addprefix $(obj)/, $(obj-vdso32)) -targets += $(obj-vdso64) vdso64.so.dbg vgettimeofday-64.o +targets += $(obj-vdso64) vdso64.so.dbg vgettimeofday-64.o vgetrandom-64.o obj-vdso64 := $(addprefix $(obj)/, $(obj-vdso64)) -ccflags-y := -fno-common -fno-builtin +ccflags-y := -fno-common -fno-builtin -DBUILD_VDSO ccflags-y += $(DISABLE_LATENT_ENTROPY_PLUGIN) ccflags-y += $(call cc-option, -fno-stack-protector) ccflags-y += -DDISABLE_BRANCH_PROFILING @@ -71,7 +73,7 @@ CPPFLAGS_vdso64.lds += -P -C # link rule for the .so file, .lds has to be first $(obj)/vdso32.so.dbg: $(obj)/vdso32.lds $(obj-vdso32) $(obj)/vgettimeofday-32.o $(obj)/vgetrandom-32.o $(obj)/crtsavres-32.o FORCE $(call if_changed,vdso32ld_and_check) -$(obj)/vdso64.so.dbg: $(obj)/vdso64.lds $(obj-vdso64) $(obj)/vgettimeofday-64.o FORCE +$(obj)/vdso64.so.dbg: $(obj)/vdso64.lds $(obj-vdso64) $(obj)/vgettimeofday-64.o $(obj)/vgetrandom-64.o FORCE $(call if_changed,vdso64ld_and_check) # assembly rules for the .S files @@ -87,6 +89,8 @@ $(obj-vdso64): %-64.o: %.S FORCE $(call if_changed_dep,vdso64as) $(obj)/vgettimeofday-64.o: %-64.o: %.c FORCE $(call if_changed_dep,cc_o_c) +$(obj)/vgetrandom-64.o: %-64.o: %.c FORCE + $(call if_changed_dep,cc_o_c) # Generate VDSO offsets using helper script gen-vdso32sym := $(src)/gen_vdso32_offsets.sh diff --git a/arch/powerpc/kernel/vdso/getrandom.S b/arch/powerpc/kernel/vdso/getrandom.S index 21773ef3fc1d..a957cd2b2b03 100644 --- a/arch/powerpc/kernel/vdso/getrandom.S +++ b/arch/powerpc/kernel/vdso/getrandom.S @@ -27,10 +27,18 @@ .cfi_adjust_cfa_offset PPC_MIN_STKFRM PPC_STL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1) .cfi_rel_offset lr, PPC_MIN_STKFRM + PPC_LR_STKOFF +#ifdef __powerpc64__ + PPC_STL r2, PPC_MIN_STKFRM + STK_GOT(r1) + .cfi_rel_offset r2, PPC_MIN_STKFRM + STK_GOT +#endif get_datapager8 addir8, r8, VDSO_RNG_DATA_OFFSET bl CFUNC(DOTSYM(\funct)) PPC_LL r0, PPC_MIN_STKFRM + PPC_LR_STKOFF(r1) +#ifdef __powerpc64__ + PPC_LL r2, PPC_MIN_STKFRM + STK_GOT(r1) + .cfi_restore r2
[PATCH v3 3/5] powerpc/vdso: Refactor CFLAGS for CVDSO build
In order to avoid two much duplication when we add new VDSO functionnalities in C like getrandom, refactor common CFLAGS. Signed-off-by: Christophe Leroy --- v3: Also refactor removed flags --- arch/powerpc/kernel/vdso/Makefile | 32 +-- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/arch/powerpc/kernel/vdso/Makefile b/arch/powerpc/kernel/vdso/Makefile index c07a425b8f78..67fe79d26fae 100644 --- a/arch/powerpc/kernel/vdso/Makefile +++ b/arch/powerpc/kernel/vdso/Makefile @@ -10,28 +10,11 @@ obj-vdso64 = sigtramp64-64.o gettimeofday-64.o datapage-64.o cacheflush-64.o not ifneq ($(c-gettimeofday-y),) CFLAGS_vgettimeofday-32.o += -include $(c-gettimeofday-y) - CFLAGS_vgettimeofday-32.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) - CFLAGS_vgettimeofday-32.o += $(call cc-option, -fno-stack-protector) - CFLAGS_vgettimeofday-32.o += -DDISABLE_BRANCH_PROFILING - CFLAGS_vgettimeofday-32.o += -ffreestanding -fasynchronous-unwind-tables - CFLAGS_REMOVE_vgettimeofday-32.o = $(CC_FLAGS_FTRACE) - CFLAGS_REMOVE_vgettimeofday-32.o += -mcmodel=medium -mabi=elfv1 -mabi=elfv2 -mcall-aixdesc - # This flag is supported by clang for 64-bit but not 32-bit so it will cause - # an unused command line flag warning for this file. - ifdef CONFIG_CC_IS_CLANG - CFLAGS_REMOVE_vgettimeofday-32.o += -fno-stack-clash-protection - endif - CFLAGS_vgettimeofday-64.o += -include $(c-gettimeofday-y) - CFLAGS_vgettimeofday-64.o += $(DISABLE_LATENT_ENTROPY_PLUGIN) - CFLAGS_vgettimeofday-64.o += $(call cc-option, -fno-stack-protector) - CFLAGS_vgettimeofday-64.o += -DDISABLE_BRANCH_PROFILING - CFLAGS_vgettimeofday-64.o += -ffreestanding -fasynchronous-unwind-tables - CFLAGS_REMOVE_vgettimeofday-64.o = $(CC_FLAGS_FTRACE) # Go prior to 1.16.x assumes r30 is not clobbered by any VDSO code. That used to be true # by accident when the VDSO was hand-written asm code, but may not be now that the VDSO is # compiler generated. To avoid breaking Go tell GCC not to use r30. Impact on code # generation is minimal, it will just use r29 instead. - CFLAGS_vgettimeofday-64.o += $(call cc-option, -ffixed-r30) + CFLAGS_vgettimeofday-64.o += -include $(c-gettimeofday-y) $(call cc-option, -ffixed-r30) endif # Build rules @@ -49,6 +32,11 @@ targets += $(obj-vdso64) vdso64.so.dbg vgettimeofday-64.o obj-vdso64 := $(addprefix $(obj)/, $(obj-vdso64)) ccflags-y := -fno-common -fno-builtin +ccflags-y += $(DISABLE_LATENT_ENTROPY_PLUGIN) +ccflags-y += $(call cc-option, -fno-stack-protector) +ccflags-y += -DDISABLE_BRANCH_PROFILING +ccflags-y += -ffreestanding -fasynchronous-unwind-tables +ccflags-remove-y := $(CC_FLAGS_FTRACE) ldflags-y := -Wl,--hash-style=both -nostdlib -shared -z noexecstack $(CLANG_FLAGS) ldflags-$(CONFIG_LD_IS_LLD) += $(call cc-option,--ld-path=$(LD),-fuse-ld=lld) ldflags-$(CONFIG_LD_ORPHAN_WARN) += -Wl,--orphan-handling=$(CONFIG_LD_ORPHAN_WARN_LEVEL) @@ -57,6 +45,12 @@ ldflags-$(CONFIG_LD_ORPHAN_WARN) += -Wl,--orphan-handling=$(CONFIG_LD_ORPHAN_WAR ldflags-y += $(filter-out $(CC_AUTO_VAR_INIT_ZERO_ENABLER) $(CC_FLAGS_FTRACE) -Wa$(comma)%, $(KBUILD_CFLAGS)) CC32FLAGS := -m32 +CC32FLAGSREMOVE := -mcmodel=medium -mabi=elfv1 -mabi=elfv2 -mcall-aixdesc + # This flag is supported by clang for 64-bit but not 32-bit so it will cause + # an unused command line flag warning for this file. +ifdef CONFIG_CC_IS_CLANG +CC32FLAGSREMOVE += -fno-stack-clash-protection +endif LD32FLAGS := -Wl,-soname=linux-vdso32.so.1 AS32FLAGS := -D__VDSO32__ @@ -105,7 +99,7 @@ quiet_cmd_vdso32ld_and_check = VDSO32L $@ quiet_cmd_vdso32as = VDSO32A $@ cmd_vdso32as = $(VDSOCC) $(a_flags) $(CC32FLAGS) $(AS32FLAGS) -c -o $@ $< quiet_cmd_vdso32cc = VDSO32C $@ - cmd_vdso32cc = $(VDSOCC) $(c_flags) $(CC32FLAGS) -c -o $@ $< + cmd_vdso32cc = $(VDSOCC) $(filter-out $(CC32FLAGSREMOVE), $(c_flags)) $(CC32FLAGS) -c -o $@ $< quiet_cmd_vdso64ld_and_check = VDSO64L $@ cmd_vdso64ld_and_check = $(VDSOCC) $(ldflags-y) $(LD64FLAGS) -o $@ -Wl,-T$(filter %.lds,$^) $(filter %.o,$^); $(cmd_vdso_check) -- 2.44.0
[PATCH v3 4/5] powerpc/vdso: Wire up getrandom() vDSO implementation on PPC32
To be consistent with other VDSO functions, the function is called __kernel_getrandom() __arch_chacha20_blocks_nostack() fonction is implemented basically with 32 bits operations. It performs 4 QUARTERROUND operations in parallele. There are enough registers to avoid using the stack: On input: r3: output bytes r4: 32-byte key input r5: 8-byte counter input/output r6: number of 64-byte blocks to write to output During operation: stack: pointer to counter (r5) and non-volatile registers (r14-131) r0: counter of blocks (initialised with r6) r4: Value '4' after key has been read, used for indexing r5-r12: key r14-r15: block counter r16-r31: chacha state At the end: r0, r6-r12: Zeroised r5, r14-r31: Restored Performance on powerpc 885 (using kernel selftest): ~# ./vdso_test_getrandom bench-single vdso: 2500 times in 62.938002291 seconds libc: 2500 times in 535.581916866 seconds syscall: 2500 times in 531.525042806 seconds Performance on powerpc 8321 (using kernel selftest): ~# ./vdso_test_getrandom bench-single vdso: 2500 times in 16.899318858 seconds libc: 2500 times in 131.050596522 seconds syscall: 2500 times in 129.794790389 seconds Signed-off-by: Christophe Leroy --- v3: - Preserve r13, implies saving r5 on stack - Split PPC64 implementation out. --- arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/asm-compat.h| 8 + arch/powerpc/include/asm/vdso/getrandom.h| 54 + arch/powerpc/include/asm/vdso/vsyscall.h | 6 + arch/powerpc/include/asm/vdso_datapage.h | 2 + arch/powerpc/kernel/asm-offsets.c| 1 + arch/powerpc/kernel/vdso/Makefile| 12 +- arch/powerpc/kernel/vdso/getrandom.S | 50 + arch/powerpc/kernel/vdso/vdso32.lds.S| 1 + arch/powerpc/kernel/vdso/vgetrandom-chacha.S | 201 +++ arch/powerpc/kernel/vdso/vgetrandom.c| 14 ++ tools/arch/powerpc/vdso | 1 + tools/testing/selftests/vDSO/Makefile| 4 + 13 files changed, 353 insertions(+), 2 deletions(-) create mode 100644 arch/powerpc/include/asm/vdso/getrandom.h create mode 100644 arch/powerpc/kernel/vdso/getrandom.S create mode 100644 arch/powerpc/kernel/vdso/vgetrandom-chacha.S create mode 100644 arch/powerpc/kernel/vdso/vgetrandom.c create mode 12 tools/arch/powerpc/vdso diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig index d7b09b064a8a..54b270ef18b1 100644 --- a/arch/powerpc/Kconfig +++ b/arch/powerpc/Kconfig @@ -311,6 +311,7 @@ config PPC select SYSCTL_EXCEPTION_TRACE select THREAD_INFO_IN_TASK select TRACE_IRQFLAGS_SUPPORT + select VDSO_GETRANDOM if PPC32 # # Please keep this list sorted alphabetically. # diff --git a/arch/powerpc/include/asm/asm-compat.h b/arch/powerpc/include/asm/asm-compat.h index b0b209c1df50..cce8c31b1b33 100644 --- a/arch/powerpc/include/asm/asm-compat.h +++ b/arch/powerpc/include/asm/asm-compat.h @@ -59,4 +59,12 @@ #endif +#ifdef __BIG_ENDIAN__ +#define LWZX_LEstringify_in_c(lwbrx) +#define STWX_LEstringify_in_c(stwbrx) +#else +#define LWZX_LEstringify_in_c(lwzx) +#define STWX_LEstringify_in_c(stwx) +#endif + #endif /* _ASM_POWERPC_ASM_COMPAT_H */ diff --git a/arch/powerpc/include/asm/vdso/getrandom.h b/arch/powerpc/include/asm/vdso/getrandom.h new file mode 100644 index ..501d6bb14e8a --- /dev/null +++ b/arch/powerpc/include/asm/vdso/getrandom.h @@ -0,0 +1,54 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2024 Christophe Leroy , CS GROUP France + */ +#ifndef _ASM_POWERPC_VDSO_GETRANDOM_H +#define _ASM_POWERPC_VDSO_GETRANDOM_H + +#ifndef __ASSEMBLY__ + +static __always_inline int do_syscall_3(const unsigned long _r0, const unsigned long _r3, + const unsigned long _r4, const unsigned long _r5) +{ + register long r0 asm("r0") = _r0; + register unsigned long r3 asm("r3") = _r3; + register unsigned long r4 asm("r4") = _r4; + register unsigned long r5 asm("r5") = _r5; + register int ret asm ("r3"); + + asm volatile( + " sc\n" + " bns+1f\n" + " neg %0, %0\n" + "1:\n" + : "=r" (ret), "+r" (r4), "+r" (r5), "+r" (r0) + : "r" (r3) + : "memory", "r6", "r7", "r8", "r9", "r10", "r11", "r12", "cr0", "ctr"); + + return ret; +} + +/** + * getrandom_syscall - Invoke the getrandom() sy
[PATCH v3 2/5] powerpc/vdso32: Add crtsavres
Commit 08c18b63d965 ("powerpc/vdso32: Add missing _restgpr_31_x to fix build failure") added _restgpr_31_x to the vdso for gettimeofday, but the work on getrandom shows that we will need more of those functions. Remove _restgpr_31_x and link in crtsavres.o so that we get all save/restore functions when optimising the kernel for size. Signed-off-by: Christophe Leroy --- arch/powerpc/kernel/vdso/Makefile | 5 - arch/powerpc/kernel/vdso/gettimeofday.S | 13 - 2 files changed, 4 insertions(+), 14 deletions(-) diff --git a/arch/powerpc/kernel/vdso/Makefile b/arch/powerpc/kernel/vdso/Makefile index 1425b6edc66b..c07a425b8f78 100644 --- a/arch/powerpc/kernel/vdso/Makefile +++ b/arch/powerpc/kernel/vdso/Makefile @@ -43,6 +43,7 @@ else endif targets := $(obj-vdso32) vdso32.so.dbg vgettimeofday-32.o +targets += crtsavres-32.o obj-vdso32 := $(addprefix $(obj)/, $(obj-vdso32)) targets += $(obj-vdso64) vdso64.so.dbg vgettimeofday-64.o obj-vdso64 := $(addprefix $(obj)/, $(obj-vdso64)) @@ -68,7 +69,7 @@ targets += vdso64.lds CPPFLAGS_vdso64.lds += -P -C # link rule for the .so file, .lds has to be first -$(obj)/vdso32.so.dbg: $(obj)/vdso32.lds $(obj-vdso32) $(obj)/vgettimeofday-32.o FORCE +$(obj)/vdso32.so.dbg: $(obj)/vdso32.lds $(obj-vdso32) $(obj)/vgettimeofday-32.o $(obj)/crtsavres-32.o FORCE $(call if_changed,vdso32ld_and_check) $(obj)/vdso64.so.dbg: $(obj)/vdso64.lds $(obj-vdso64) $(obj)/vgettimeofday-64.o FORCE $(call if_changed,vdso64ld_and_check) @@ -76,6 +77,8 @@ $(obj)/vdso64.so.dbg: $(obj)/vdso64.lds $(obj-vdso64) $(obj)/vgettimeofday-64.o # assembly rules for the .S files $(obj-vdso32): %-32.o: %.S FORCE $(call if_changed_dep,vdso32as) +$(obj)/crtsavres-32.o: %-32.o: $(srctree)/arch/powerpc/lib/crtsavres.S FORCE + $(call if_changed_dep,vdso32as) $(obj)/vgettimeofday-32.o: %-32.o: %.c FORCE $(call if_changed_dep,vdso32cc) $(obj-vdso64): %-64.o: %.S FORCE diff --git a/arch/powerpc/kernel/vdso/gettimeofday.S b/arch/powerpc/kernel/vdso/gettimeofday.S index 48fc6658053a..67254ac9c8bb 100644 --- a/arch/powerpc/kernel/vdso/gettimeofday.S +++ b/arch/powerpc/kernel/vdso/gettimeofday.S @@ -118,16 +118,3 @@ V_FUNCTION_END(__kernel_clock_getres) V_FUNCTION_BEGIN(__kernel_time) cvdso_call __c_kernel_time call_time=1 V_FUNCTION_END(__kernel_time) - -/* Routines for restoring integer registers, called by the compiler. */ -/* Called with r11 pointing to the stack header word of the caller of the */ -/* function, just beyond the end of the integer restore area. */ -#ifndef __powerpc64__ -_GLOBAL(_restgpr_31_x) -_GLOBAL(_rest32gpr_31_x) - lwz r0,4(r11) - lwz r31,-4(r11) - mtlrr0 - mr r1,r11 - blr -#endif -- 2.44.0
[PATCH v3 1/5] mm: Define VM_DROPPABLE for powerpc/32
Commit 9651fcedf7b9 ("mm: add MAP_DROPPABLE for designating always lazily freeable mappings") only adds VM_DROPPABLE for 64 bits architectures. In order to also use the getrandom vDSO implementation on powerpc/32, use VM_ARCH_1 for VM_DROPPABLE on powerpc/32. This is possible because VM_ARCH_1 is used for VM_SAO on powerpc and VM_SAO is only for powerpc/64. Signed-off-by: Christophe Leroy --- v3: Fixed build failure reported by robots. --- fs/proc/task_mmu.c | 4 +++- include/linux/mm.h | 4 +++- include/trace/events/mmflags.h | 4 ++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c index 5f171ad7b436..3a07e13e2f81 100644 --- a/fs/proc/task_mmu.c +++ b/fs/proc/task_mmu.c @@ -987,8 +987,10 @@ static void show_smap_vma_flags(struct seq_file *m, struct vm_area_struct *vma) #ifdef CONFIG_X86_USER_SHADOW_STACK [ilog2(VM_SHADOW_STACK)] = "ss", #endif -#ifdef CONFIG_64BIT +#if defined(CONFIG_64BIT) || defined(CONFIG_PPC32) [ilog2(VM_DROPPABLE)] = "dp", +#endif +#ifdef CONFIG_64BIT [ilog2(VM_SEALED)] = "sl", #endif }; diff --git a/include/linux/mm.h b/include/linux/mm.h index 6549d0979b28..028847f39442 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -359,7 +359,7 @@ extern unsigned int kobjsize(const void *objp); #if defined(CONFIG_X86) # define VM_PATVM_ARCH_1 /* PAT reserves whole VMA at once (x86) */ -#elif defined(CONFIG_PPC) +#elif defined(CONFIG_PPC64) # define VM_SAOVM_ARCH_1 /* Strong Access Ordering (powerpc) */ #elif defined(CONFIG_PARISC) # define VM_GROWSUPVM_ARCH_1 @@ -409,6 +409,8 @@ extern unsigned int kobjsize(const void *objp); #ifdef CONFIG_64BIT #define VM_DROPPABLE_BIT 40 #define VM_DROPPABLE BIT(VM_DROPPABLE_BIT) +#elif defined(CONFIG_PPC32) +#define VM_DROPPABLE VM_ARCH_1 #else #define VM_DROPPABLE VM_NONE #endif diff --git a/include/trace/events/mmflags.h b/include/trace/events/mmflags.h index b63d211bd141..37265977d524 100644 --- a/include/trace/events/mmflags.h +++ b/include/trace/events/mmflags.h @@ -143,7 +143,7 @@ IF_HAVE_PG_ARCH_X(arch_3) #if defined(CONFIG_X86) #define __VM_ARCH_SPECIFIC_1 {VM_PAT, "pat" } -#elif defined(CONFIG_PPC) +#elif defined(CONFIG_PPC64) #define __VM_ARCH_SPECIFIC_1 {VM_SAO, "sao" } #elif defined(CONFIG_PARISC) #define __VM_ARCH_SPECIFIC_1 {VM_GROWSUP, "growsup" } @@ -165,7 +165,7 @@ IF_HAVE_PG_ARCH_X(arch_3) # define IF_HAVE_UFFD_MINOR(flag, name) #endif -#ifdef CONFIG_64BIT +#if defined(CONFIG_64BIT) || defined(CONFIG_PPC32) # define IF_HAVE_VM_DROPPABLE(flag, name) {flag, name}, #else # define IF_HAVE_VM_DROPPABLE(flag, name) -- 2.44.0
[PATCH v3 0/5] Wire up getrandom() vDSO implementation on powerpc
This series wires up getrandom() vDSO implementation on powerpc. Tested on PPC32 on real hardware. Tested on PPC64 (both BE and LE) on QEMU: Performance on powerpc 885: ~# ./vdso_test_getrandom bench-single vdso: 2500 times in 62.938002291 seconds libc: 2500 times in 535.581916866 seconds syscall: 2500 times in 531.525042806 seconds Performance on powerpc 8321: ~# ./vdso_test_getrandom bench-single vdso: 2500 times in 16.899318858 seconds libc: 2500 times in 131.050596522 seconds syscall: 2500 times in 129.794790389 seconds Performance on QEMU pseries: ~ # ./vdso_test_getrandom bench-single vdso: 2500 times in 4.97162 seconds libc: 2500 times in 75.516749981 seconds syscall: 2500 times in 86.842242014 seconds In order to run selftests, some fixes are needed, see https://lore.kernel.org/linuxppc-dev/6c5da802e72befecfa09046c489aa45d934d611f.1725020674.git.christophe.le...@csgroup.eu/ Those selftest fixes are independant and are not required to apply and use this series. Changes in v3: - Rebased on recent random git tree (0c7e00e22c21) - Fixed build failures reported by robots around VM_DROPPABLE - Fixed crash on PPC64 due to clobbered r13 by not using r13 anymore (saving it was not enough for signals). - Split final patch in two, first for PPC32, second for PPC64 - Moved selftest fixes out of this series Changes in v2: - Define VM_DROPPABLE for powerpc/32 - Fixes generic vDSO getrandom headers to enable CONFIG_COMPAT build. - Fixed size of generation counter - Fixed selftests to work on non x86 architectures Christophe Leroy (5): mm: Define VM_DROPPABLE for powerpc/32 powerpc/vdso32: Add crtsavres powerpc/vdso: Refactor CFLAGS for CVDSO build powerpc/vdso: Wire up getrandom() vDSO implementation on PPC32 powerpc/vdso: Wire up getrandom() vDSO implementation on PPC64 arch/powerpc/Kconfig | 1 + arch/powerpc/include/asm/asm-compat.h| 8 + arch/powerpc/include/asm/mman.h | 2 +- arch/powerpc/include/asm/vdso/getrandom.h| 54 arch/powerpc/include/asm/vdso/vsyscall.h | 6 + arch/powerpc/include/asm/vdso_datapage.h | 2 + arch/powerpc/kernel/asm-offsets.c| 1 + arch/powerpc/kernel/vdso/Makefile| 57 ++-- arch/powerpc/kernel/vdso/getrandom.S | 58 arch/powerpc/kernel/vdso/gettimeofday.S | 13 - arch/powerpc/kernel/vdso/vdso32.lds.S| 1 + arch/powerpc/kernel/vdso/vdso64.lds.S| 1 + arch/powerpc/kernel/vdso/vgetrandom-chacha.S | 299 +++ arch/powerpc/kernel/vdso/vgetrandom.c| 14 + fs/proc/task_mmu.c | 4 +- include/linux/mm.h | 4 +- include/trace/events/mmflags.h | 4 +- tools/arch/powerpc/vdso | 1 + tools/testing/selftests/vDSO/Makefile| 4 + 19 files changed, 492 insertions(+), 42 deletions(-) create mode 100644 arch/powerpc/include/asm/vdso/getrandom.h create mode 100644 arch/powerpc/kernel/vdso/getrandom.S create mode 100644 arch/powerpc/kernel/vdso/vgetrandom-chacha.S create mode 100644 arch/powerpc/kernel/vdso/vgetrandom.c create mode 12 tools/arch/powerpc/vdso -- 2.44.0
[PATCH 5/5] selftests: vdso: Use parse_vdso.h in vdso_test_abi
Don't duplicate parse_vdso function prototypes, include the header instead. Fixes: 693f5ca08ca0 ("kselftest: Extend vDSO selftest") Signed-off-by: Christophe Leroy --- tools/testing/selftests/vDSO/vdso_test_abi.c | 5 + 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/tools/testing/selftests/vDSO/vdso_test_abi.c b/tools/testing/selftests/vDSO/vdso_test_abi.c index 00034208c4c6..a54424e2336f 100644 --- a/tools/testing/selftests/vDSO/vdso_test_abi.c +++ b/tools/testing/selftests/vDSO/vdso_test_abi.c @@ -21,10 +21,7 @@ #include "../kselftest.h" #include "vdso_config.h" #include "vdso_call.h" - -extern void *vdso_sym(const char *version, const char *name); -extern void vdso_init_from_sysinfo_ehdr(uintptr_t base); -extern void vdso_init_from_auxv(void *auxv); +#include "parse_vdso.h" static const char *version; static const char **name; -- 2.44.0
[PATCH 4/5] selftests: vdso: Fix the way vDSO functions are called for powerpc
vdso_test_correctness test fails on powerpc: ~ # ./vdso_test_correctness ... [RUN] Testing clock_gettime for clock CLOCK_REALTIME_ALARM (8)... [FAIL] No such clock, but __vdso_clock_gettime returned 22 [RUN] Testing clock_gettime for clock CLOCK_BOOTTIME_ALARM (9)... [FAIL] No such clock, but __vdso_clock_gettime returned 22 [RUN] Testing clock_gettime for clock CLOCK_SGI_CYCLE (10)... [FAIL] No such clock, but __vdso_clock_gettime returned 22 ... [RUN] Testing clock_gettime for clock invalid (-1)... [FAIL] No such clock, but __vdso_clock_gettime returned 22 [RUN] Testing clock_gettime for clock invalid (-2147483648)... [FAIL] No such clock, but __vdso_clock_gettime returned 22 [RUN] Testing clock_gettime for clock invalid (2147483647)... [FAIL] No such clock, but __vdso_clock_gettime returned 22 On powerpc, a call to a VDSO function is not an ordinary C function call. Unlike several architectures which returns a negative error code in case of an error, powerpc sets CR[SO] and returns the error code as a positive value. Define and use a macro called VDSO_CALL() which takes a pointer to the function to call, the number of arguments and the arguments. Also update ABI vdso documentation to reflect this subtlety. Provide a specific version of VDSO_CALL() for powerpc that negates the error code on return when CR[SO] is set. Fixes: c7e5789b24d3 ("kselftest: Move test_vdso to the vDSO test suite") Fixes: 2e9a97256616 ("selftests: vdso: Add a selftest for vDSO getcpu()") Fixes: 693f5ca08ca0 ("kselftest: Extend vDSO selftest") Fixes: b2f1c3db2887 ("kselftest: Extend vdso correctness test to clock_gettime64") Fixes: 4920a2590e91 ("selftests/vDSO: add tests for vgetrandom") Signed-off-by: Christophe Leroy --- Documentation/ABI/stable/vdso | 8 ++- tools/testing/selftests/vDSO/vdso_call.h | 70 +++ tools/testing/selftests/vDSO/vdso_test_abi.c | 9 +-- .../selftests/vDSO/vdso_test_correctness.c| 15 ++-- .../testing/selftests/vDSO/vdso_test_getcpu.c | 3 +- .../selftests/vDSO/vdso_test_getrandom.c | 5 +- .../selftests/vDSO/vdso_test_gettimeofday.c | 3 +- 7 files changed, 95 insertions(+), 18 deletions(-) create mode 100644 tools/testing/selftests/vDSO/vdso_call.h diff --git a/Documentation/ABI/stable/vdso b/Documentation/ABI/stable/vdso index 951838d42781..85dbb6a160df 100644 --- a/Documentation/ABI/stable/vdso +++ b/Documentation/ABI/stable/vdso @@ -9,9 +9,11 @@ maps an ELF DSO into that program's address space. This DSO is called the vDSO and it often contains useful and highly-optimized alternatives to real syscalls. -These functions are called just like ordinary C function according to -your platform's ABI. Call them from a sensible context. (For example, -if you set CS on x86 to something strange, the vDSO functions are +These functions are called according to your platform's ABI. On many +platforms they are called just like ordinary C function. On other platforms +(ex: powerpc) they are called with the same convention as system calls which +is different from ordinary C functions. Call them from a sensible context. +(For example, if you set CS on x86 to something strange, the vDSO functions are within their rights to crash.) In addition, if you pass a bad pointer to a vDSO function, you might get SIGSEGV instead of -EFAULT. diff --git a/tools/testing/selftests/vDSO/vdso_call.h b/tools/testing/selftests/vDSO/vdso_call.h new file mode 100644 index ..bb237d771051 --- /dev/null +++ b/tools/testing/selftests/vDSO/vdso_call.h @@ -0,0 +1,70 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Macro to call vDSO functions + * + * Copyright (C) 2024 Christophe Leroy , CS GROUP France + */ +#ifndef __VDSO_CALL_H__ +#define __VDSO_CALL_H__ + +#ifdef __powerpc__ + +#define LOADARGS_1(fn, __arg1) do {\ + _r0 = fn; \ + _r3 = (long)__arg1; \ +} while (0) + +#define LOADARGS_2(fn, __arg1, __arg2) do {\ + _r0 = fn; \ + _r3 = (long)__arg1; \ + _r4 = (long)__arg2; \ +} while (0) + +#define LOADARGS_3(fn, __arg1, __arg2, __arg3) do {\ + _r0 = fn; \ + _r3 = (long)__arg1; \ + _r4 = (long)__arg2; \ + _r5 = (long)__arg3; \ +} while (0) + +#define LOADARGS_5(fn, __arg1, __arg2, __arg3, __arg4, __arg5) do {\ + _r0 = fn; \ + _r3 = (long)__arg1;
[PATCH 3/5] selftests: vdso: Fix vDSO symbols lookup for powerpc64
On powerpc64, following tests fail locating vDSO functions: ~ # ./vdso_test_abi TAP version 13 1..16 # [vDSO kselftest] VDSO_VERSION: LINUX_2.6.15 # Couldn't find __kernel_gettimeofday ok 1 # SKIP __kernel_gettimeofday # clock_id: CLOCK_REALTIME # Couldn't find __kernel_clock_gettime ok 2 # SKIP __kernel_clock_gettime CLOCK_REALTIME # Couldn't find __kernel_clock_getres ok 3 # SKIP __kernel_clock_getres CLOCK_REALTIME ... # Couldn't find __kernel_time ok 16 # SKIP __kernel_time # Totals: pass:0 fail:0 xfail:0 xpass:0 skip:16 error:0 ~ # ./vdso_test_getrandom __kernel_getrandom is missing! ~ # ./vdso_test_gettimeofday Could not find __kernel_gettimeofday ~ # ./vdso_test_getcpu Could not find __kernel_getcpu On powerpc64, as shown below by readelf, vDSO functions symbols have type NOTYPE, so also accept that type when looking for symbols. $ powerpc64-linux-gnu-readelf -a arch/powerpc/kernel/vdso/vdso64.so.dbg ELF Header: Magic: 7f 45 4c 46 02 02 01 00 00 00 00 00 00 00 00 00 Class: ELF64 Data: 2's complement, big endian Version: 1 (current) OS/ABI:UNIX - System V ABI Version: 0 Type: DYN (Shared object file) Machine: PowerPC64 Version: 0x1 ... Symbol table '.dynsym' contains 12 entries: Num:Value Size TypeBind Vis Ndx Name 0: 0 NOTYPE LOCAL DEFAULT UND 1: 052484 NOTYPE GLOBAL DEFAULT8 __[...]@@LINUX_2.6.15 2: 05f036 NOTYPE GLOBAL DEFAULT8 __[...]@@LINUX_2.6.15 3: 057868 NOTYPE GLOBAL DEFAULT8 __[...]@@LINUX_2.6.15 4: 0 OBJECT GLOBAL DEFAULT ABS LINUX_2.6.15 5: 06c048 NOTYPE GLOBAL DEFAULT8 __[...]@@LINUX_2.6.15 6: 0614 172 NOTYPE GLOBAL DEFAULT8 __[...]@@LINUX_2.6.15 7: 06f084 NOTYPE GLOBAL DEFAULT8 __[...]@@LINUX_2.6.15 8: 047c84 NOTYPE GLOBAL DEFAULT8 __[...]@@LINUX_2.6.15 9: 045412 NOTYPE GLOBAL DEFAULT8 __[...]@@LINUX_2.6.15 10: 04d084 NOTYPE GLOBAL DEFAULT8 __[...]@@LINUX_2.6.15 11: 05bc52 NOTYPE GLOBAL DEFAULT8 __[...]@@LINUX_2.6.15 Symbol table '.symtab' contains 56 entries: Num:Value Size TypeBind Vis Ndx Name ... 45: 0 OBJECT GLOBAL DEFAULT ABS LINUX_2.6.15 46: 06c048 NOTYPE GLOBAL DEFAULT8 __kernel_getcpu 47: 052484 NOTYPE GLOBAL DEFAULT8 __kernel_clock_getres 48: 05f036 NOTYPE GLOBAL DEFAULT8 __kernel_get_tbfreq 49: 047c84 NOTYPE GLOBAL DEFAULT8 __kernel_gettimeofday 50: 0614 172 NOTYPE GLOBAL DEFAULT8 __kernel_sync_dicache 51: 06f084 NOTYPE GLOBAL DEFAULT8 __kernel_getrandom 52: 045412 NOTYPE GLOBAL DEFAULT8 __kernel_sigtram[...] 53: 057868 NOTYPE GLOBAL DEFAULT8 __kernel_time 54: 04d084 NOTYPE GLOBAL DEFAULT8 __kernel_clock_g[...] 55: 05bc52 NOTYPE GLOBAL DEFAULT8 __kernel_get_sys[...] Fixes: 98eedc3a9dbf ("Document the vDSO and add a reference parser") Signed-off-by: Christophe Leroy --- tools/testing/selftests/vDSO/parse_vdso.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/testing/selftests/vDSO/parse_vdso.c b/tools/testing/selftests/vDSO/parse_vdso.c index 4ae417372e9e..d9ccc5acac18 100644 --- a/tools/testing/selftests/vDSO/parse_vdso.c +++ b/tools/testing/selftests/vDSO/parse_vdso.c @@ -216,7 +216,8 @@ void *vdso_sym(const char *version, const char *name) ELF(Sym) *sym = &vdso_info.symtab[chain]; /* Check for a defined global or weak function w/ right name. */ - if (ELF64_ST_TYPE(sym->st_info) != STT_FUNC) + if (ELF64_ST_TYPE(sym->st_info) != STT_FUNC && + ELF64_ST_TYPE(sym->st_info) != STT_NOTYPE) continue; if (ELF64_ST_BIND(sym->st_info) != STB_GLOBAL && ELF64_ST_BIND(sym->st_info) != STB_WEAK) -- 2.44.0
[PATCH 2/5] selftests: vdso: Fix vdso_config for powerpc
Running vdso_test_correctness on powerpc64 gives the following warning: ~ # ./vdso_test_correctness Warning: failed to find clock_gettime64 in vDSO This is because vdso_test_correctness was built with VDSO_32BIT defined. __powerpc__ macro is defined on both powerpc32 and powerpc64 so __powerpc64__ needs to be checked first in vdso_config.h Fixes: 693f5ca08ca0 ("kselftest: Extend vDSO selftest") Signed-off-by: Christophe Leroy --- tools/testing/selftests/vDSO/vdso_config.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/vDSO/vdso_config.h b/tools/testing/selftests/vDSO/vdso_config.h index 7b543e7f04d7..00bfed6e4922 100644 --- a/tools/testing/selftests/vDSO/vdso_config.h +++ b/tools/testing/selftests/vDSO/vdso_config.h @@ -18,13 +18,13 @@ #elif defined(__aarch64__) #define VDSO_VERSION 3 #define VDSO_NAMES 0 -#elif defined(__powerpc__) +#elif defined(__powerpc64__) #define VDSO_VERSION 1 #define VDSO_NAMES 0 -#define VDSO_32BIT 1 -#elif defined(__powerpc64__) +#elif defined(__powerpc__) #define VDSO_VERSION 1 #define VDSO_NAMES 0 +#define VDSO_32BIT 1 #elif defined (__s390__) #define VDSO_VERSION 2 #define VDSO_NAMES 0 -- 2.44.0
[PATCH 1/5] selftests: vdso: Fix vDSO name for powerpc
Following error occurs when running vdso_test_correctness on powerpc: ~ # ./vdso_test_correctness [WARN] failed to find vDSO [SKIP] No vDSO, so skipping clock_gettime() tests [SKIP] No vDSO, so skipping clock_gettime64() tests [RUN] Testing getcpu... [OK]CPU 0: syscall: cpu 0, node 0 On powerpc, vDSO is neither called linux-vdso.so.1 nor linux-gate.so.1 but linux-vdso32.so.1 or linux-vdso64.so.1. Also search those two names before giving up. Fixes: c7e5789b24d3 ("kselftest: Move test_vdso to the vDSO test suite") Signed-off-by: Christophe Leroy --- tools/testing/selftests/vDSO/vdso_test_correctness.c | 6 ++ 1 file changed, 6 insertions(+) diff --git a/tools/testing/selftests/vDSO/vdso_test_correctness.c b/tools/testing/selftests/vDSO/vdso_test_correctness.c index e691a3cf1491..cdb697ae8343 100644 --- a/tools/testing/selftests/vDSO/vdso_test_correctness.c +++ b/tools/testing/selftests/vDSO/vdso_test_correctness.c @@ -114,6 +114,12 @@ static void fill_function_pointers() if (!vdso) vdso = dlopen("linux-gate.so.1", RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD); + if (!vdso) + vdso = dlopen("linux-vdso32.so.1", + RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD); + if (!vdso) + vdso = dlopen("linux-vdso64.so.1", + RTLD_LAZY | RTLD_LOCAL | RTLD_NOLOAD); if (!vdso) { printf("[WARN]\tfailed to find vDSO\n"); return; -- 2.44.0
Re: [PATCH v2 05/17] vdso: Avoid call to memset() by getrandom
Le 29/08/2024 à 20:02, Segher Boessenkool a écrit : On Thu, Aug 29, 2024 at 07:36:38PM +0200, Christophe Leroy wrote: Le 28/08/2024 à 19:25, Segher Boessenkool a écrit : Not sure about static binaries, though: do those even use the VDSO? With "static binary" people usually mean "a binary not using any DSOs", I think the VDSO is a DSO, also in this respect? As always, -static builds are *way* less problematic (and faster and smaller :-) ) AFAIK on powerpc even static binaries use the vDSO, otherwise signals don't work. How can that work? Non-dynamic binaries do not use ld.so (that is the definition of a dynamic binary, even). So they cannot link (at runtime) to any DSO (unless that is done manually?!) Maybe there is something at a fixed offset in the vDSO, or something like that? Is this documented somewhere? You've got some explanation here : https://github.com/torvalds/linux/blob/master/Documentation/ABI/stable/vdso
Re: [PATCH v2 05/17] vdso: Avoid call to memset() by getrandom
Le 28/08/2024 à 19:25, Segher Boessenkool a écrit : Not sure about static binaries, though: do those even use the VDSO? With "static binary" people usually mean "a binary not using any DSOs", I think the VDSO is a DSO, also in this respect? As always, -static builds are *way* less problematic (and faster and smaller :-) ) AFAIK on powerpc even static binaries use the vDSO, otherwise signals don't work. Christophe
Re: [PATCH] random: vDSO: Redefine PAGE_SIZE and PAGE_MASK
Hi Vincenzo, Le 29/08/2024 à 14:01, Vincenzo Frascino a écrit : Hi Christophe, On 27/08/2024 18:14, Christophe Leroy wrote: Le 27/08/2024 à 18:05, Vincenzo Frascino a écrit : Hi Christophe, On 27/08/2024 11:49, Christophe Leroy wrote: ... ... Could you please clarify where minmax is needed? I tried to build Jason's master tree for x86, commenting the header and it seems building fine. I might be missing something. Without it: VDSO32C arch/powerpc/kernel/vdso/vgetrandom-32.o In file included from /home/chleroy/linux-powerpc/lib/vdso/getrandom.c:11, from : ... Same for ARRAY_SIZE(->reserved) by the way, easy to do opencode, we also have it only once I have a similar issue to figure out why linux/array_size.h and uapi/linux/random.h are needed. It seems that I can build the object without them. Could you please explain? Without linux/array_size.h: VDSO32C arch/powerpc/kernel/vdso/vgetrandom-32.o In file included from : /home/chleroy/linux-powerpc/lib/vdso/getrandom.c: In function '__cvdso_getrandom_data': /home/chleroy/linux-powerpc/lib/vdso/getrandom.c:89:40: error: implicit If this is the case, those headers should be defined for the powerpc implementation only. The generic implementation should be interpreted as the minimum common denominator in between all the architectures for what concerns the headers. Sorry, I disagree. You can't rely on necessary headers being included indirectly by other arch specific headers. getrandom.c uses ARRAY_SIZE(), it must include the header that defines ARRAY_SIZE(). At the moment, on x86 you get linux/array.h by change through the following chain, that the reason why the build doesn't break: In file included from ./include/linux/kernel.h:16, from ./include/linux/cpumask.h:11, from ./arch/x86/include/asm/cpumask.h:5, from ./arch/x86/include/asm/msr.h:11, from ./arch/x86/include/asm/vdso/gettimeofday.h:19, from ./include/vdso/datapage.h:164, from arch/x86/entry/vdso/../../../../lib/vdso/getrandom.c:9, From my point of view you can't expect such a chain from each architecture. Christophe
Re: [PATCH net-next 5/6] net: ethernet: fs_enet: fcc: use macros for speed and duplex values
Le 28/08/2024 à 11:51, Maxime Chevallier a écrit : The PHY speed and duplex should be manipulated using the SPEED_XXX and DUPLEX_XXX macros available. Use it in the fcc, fec and scc MAC for fs_enet. Signed-off-by: Maxime Chevallier Reviewed-by: Christophe Leroy --- drivers/net/ethernet/freescale/fs_enet/mac-fcc.c | 4 ++-- drivers/net/ethernet/freescale/fs_enet/mac-fec.c | 2 +- drivers/net/ethernet/freescale/fs_enet/mac-scc.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/net/ethernet/freescale/fs_enet/mac-fcc.c b/drivers/net/ethernet/freescale/fs_enet/mac-fcc.c index add062928d99..056909156b4f 100644 --- a/drivers/net/ethernet/freescale/fs_enet/mac-fcc.c +++ b/drivers/net/ethernet/freescale/fs_enet/mac-fcc.c @@ -361,7 +361,7 @@ static void restart(struct net_device *dev) /* adjust to speed (for RMII mode) */ if (fpi->use_rmii) { - if (dev->phydev->speed == 100) + if (dev->phydev->speed == SPEED_100) C8(fcccp, fcc_gfemr, 0x20); else S8(fcccp, fcc_gfemr, 0x20); @@ -387,7 +387,7 @@ static void restart(struct net_device *dev) S32(fccp, fcc_fpsmr, FCC_PSMR_RMII); /* adjust to duplex mode */ - if (dev->phydev->duplex) + if (dev->phydev->duplex == DUPLEX_FULL) S32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB); else C32(fccp, fcc_fpsmr, FCC_PSMR_FDE | FCC_PSMR_LPB); diff --git a/drivers/net/ethernet/freescale/fs_enet/mac-fec.c b/drivers/net/ethernet/freescale/fs_enet/mac-fec.c index f75acb3b358f..855ee9e3f042 100644 --- a/drivers/net/ethernet/freescale/fs_enet/mac-fec.c +++ b/drivers/net/ethernet/freescale/fs_enet/mac-fec.c @@ -309,7 +309,7 @@ static void restart(struct net_device *dev) /* * adjust to duplex mode */ - if (dev->phydev->duplex) { + if (dev->phydev->duplex == DUPLEX_FULL) { FC(fecp, r_cntrl, FEC_RCNTRL_DRT); FS(fecp, x_cntrl, FEC_TCNTRL_FDEN); /* FD enable */ } else { diff --git a/drivers/net/ethernet/freescale/fs_enet/mac-scc.c b/drivers/net/ethernet/freescale/fs_enet/mac-scc.c index 29ba0048396b..9e5e29312c27 100644 --- a/drivers/net/ethernet/freescale/fs_enet/mac-scc.c +++ b/drivers/net/ethernet/freescale/fs_enet/mac-scc.c @@ -338,7 +338,7 @@ static void restart(struct net_device *dev) W16(sccp, scc_psmr, SCC_PSMR_ENCRC | SCC_PSMR_NIB22); /* Set full duplex mode if needed */ - if (dev->phydev->duplex) + if (dev->phydev->duplex == DUPLEX_FULL) S16(sccp, scc_psmr, SCC_PSMR_LPB | SCC_PSMR_FDE); /* Restore multicast and promiscuous settings */
Re: [PATCH net-next 4/6] net: ethernet: fs_enet: drop unused phy_info and mii_if_info
Le 28/08/2024 à 11:51, Maxime Chevallier a écrit : There's no user of the struct phy_info, the 'phy' field and the mii_if_info in the fs_enet driver, probably dating back when phylib wasn't as widely used. Drop these from the driver code. Seems like they haven't been used since commit 5b4b8454344a ("[PATCH] FS_ENET: use PAL for mii management") Reviewed-by: Christophe Leroy Signed-off-by: Maxime Chevallier --- drivers/net/ethernet/freescale/fs_enet/fs_enet.h | 11 --- 1 file changed, 11 deletions(-) diff --git a/drivers/net/ethernet/freescale/fs_enet/fs_enet.h b/drivers/net/ethernet/freescale/fs_enet/fs_enet.h index abe4dc97e52a..781f506c933c 100644 --- a/drivers/net/ethernet/freescale/fs_enet/fs_enet.h +++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet.h @@ -92,14 +92,6 @@ struct fs_ops { void (*tx_restart)(struct net_device *dev); }; -struct phy_info { - unsigned int id; - const char *name; - void (*startup) (struct net_device * dev); - void (*shutdown) (struct net_device * dev); - void (*ack_int) (struct net_device * dev); -}; - /* The FEC stores dest/src/type, data, and checksum for receive packets. */ #define MAX_MTU 1508 /* Allow fullsized pppoe packets over VLAN */ @@ -153,10 +145,7 @@ struct fs_enet_private { cbd_t __iomem *cur_rx; cbd_t __iomem *cur_tx; int tx_free; - const struct phy_info *phy; u32 msg_enable; - struct mii_if_info mii_if; - unsigned int last_mii_status; int interrupt; int oldduplex, oldspeed, oldlink; /* current settings */
Re: [PATCH net-next 3/6] net: ethernet: fs_enet: drop the .adjust_link custom fs_ops
Le 28/08/2024 à 11:50, Maxime Chevallier a écrit : There's no in-tree user for the fs_ops .adjust_link() function, so we can always use the generic one in fe_enet-main. Signed-off-by: Maxime Chevallier Reviewed-by: Christophe Leroy --- drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c | 7 +-- drivers/net/ethernet/freescale/fs_enet/fs_enet.h | 1 - 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c index 2b48a2a5e32d..caca81b3ccb6 100644 --- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c @@ -649,12 +649,7 @@ static void fs_adjust_link(struct net_device *dev) unsigned long flags; spin_lock_irqsave(&fep->lock, flags); - - if (fep->ops->adjust_link) - fep->ops->adjust_link(dev); - else - generic_adjust_link(dev); - + generic_adjust_link(dev); spin_unlock_irqrestore(&fep->lock, flags); } diff --git a/drivers/net/ethernet/freescale/fs_enet/fs_enet.h b/drivers/net/ethernet/freescale/fs_enet/fs_enet.h index 21c07ac05225..abe4dc97e52a 100644 --- a/drivers/net/ethernet/freescale/fs_enet/fs_enet.h +++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet.h @@ -77,7 +77,6 @@ struct fs_ops { void (*free_bd)(struct net_device *dev); void (*cleanup_data)(struct net_device *dev); void (*set_multicast_list)(struct net_device *dev); - void (*adjust_link)(struct net_device *dev); void (*restart)(struct net_device *dev); void (*stop)(struct net_device *dev); void (*napi_clear_event)(struct net_device *dev);
Re: [PATCH net-next 2/6] net: ethernet: fs_enet: cosmetic cleanups
Le 28/08/2024 à 11:50, Maxime Chevallier a écrit : Due to the age of the driver and the slow recent activity on it, the code has taken some layers of dust. Clean the main driver file up so that it passes checkpatch and also conforms with the net coding style. Changes include : - Re-ordering of the variable declarations for RCT - Fixing the comment styles to either one-line comments, or net-style comments - Adding braces around single-statement 'else' clauses - Aligning function/macro parameters on the opening parenthesis - Simplifying checks for NULL pointers - Splitting cascaded assignments into individual assignments - Fixing some typos - Fixing whitespace issues This is a cosmetic change and doesn't introduce any change in behaviour. Signed-off-by: Maxime Chevallier Reviewed-by: Christophe Leroy --- .../ethernet/freescale/fs_enet/fs_enet-main.c | 220 +++--- 1 file changed, 89 insertions(+), 131 deletions(-) diff --git a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c index 5bfdd43ffdeb..2b48a2a5e32d 100644 --- a/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c +++ b/drivers/net/ethernet/freescale/fs_enet/fs_enet-main.c @@ -81,15 +81,14 @@ static void skb_align(struct sk_buff *skb, int align) static int fs_enet_napi(struct napi_struct *napi, int budget) { struct fs_enet_private *fep = container_of(napi, struct fs_enet_private, napi); - struct net_device *dev = fep->ndev; const struct fs_platform_info *fpi = fep->fpi; - cbd_t __iomem *bdp; + struct net_device *dev = fep->ndev; + int curidx, dirtyidx, received = 0; + int do_wake = 0, do_restart = 0; + int tx_left = TX_RING_SIZE; struct sk_buff *skb, *skbn; - int received = 0; + cbd_t __iomem *bdp; u16 pkt_len, sc; - int curidx; - int dirtyidx, do_wake, do_restart; - int tx_left = TX_RING_SIZE; spin_lock(&fep->tx_lock); bdp = fep->dirty_tx; @@ -97,7 +96,6 @@ static int fs_enet_napi(struct napi_struct *napi, int budget) /* clear status bits for napi*/ (*fep->ops->napi_clear_event)(dev); - do_wake = do_restart = 0; while (((sc = CBDR_SC(bdp)) & BD_ENET_TX_READY) == 0 && tx_left) { dirtyidx = bdp - fep->tx_bd_base; @@ -106,12 +104,9 @@ static int fs_enet_napi(struct napi_struct *napi, int budget) skb = fep->tx_skbuff[dirtyidx]; - /* -* Check for errors. -*/ +/* Check for errors. */ if (sc & (BD_ENET_TX_HB | BD_ENET_TX_LC | BD_ENET_TX_RL | BD_ENET_TX_UN | BD_ENET_TX_CSL)) { - if (sc & BD_ENET_TX_HB) /* No heartbeat */ dev->stats.tx_heartbeat_errors++; if (sc & BD_ENET_TX_LC) /* Late collision */ @@ -127,16 +122,16 @@ static int fs_enet_napi(struct napi_struct *napi, int budget) dev->stats.tx_errors++; do_restart = 1; } - } else + } else { dev->stats.tx_packets++; + } if (sc & BD_ENET_TX_READY) { dev_warn(fep->dev, "HEY! Enet xmit interrupt and TX_READY.\n"); } - /* -* Deferred means some collisions occurred during transmit, + /* Deferred means some collisions occurred during transmit, * but we eventually sent the packet OK. */ if (sc & BD_ENET_TX_DEF) @@ -150,25 +145,20 @@ static int fs_enet_napi(struct napi_struct *napi, int budget) dma_unmap_single(fep->dev, CBDR_BUFADDR(bdp), CBDR_DATLEN(bdp), DMA_TO_DEVICE); - /* -* Free the sk buffer associated with this last transmit. -*/ + /* Free the sk buffer associated with this last transmit. */ if (skb) { dev_kfree_skb(skb); fep->tx_skbuff[dirtyidx] = NULL; } - /* -* Update pointer to next buffer descriptor to be transmitted. + /* Update pointer to next buffer descriptor to be transmitted. */ if ((sc & BD_ENET_TX_WRAP) == 0) bdp++; else bdp = fep->tx_bd_base; - /* -* Since we have freed up a buffer, the ring is no longer -* full. + /* Since we have freed up a buffer, the ring is no longer full. */ if (++fep-&