From patchwork Thu Aug 22 07:13:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christophe Leroy X-Patchwork-Id: 13772811 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53248C3DA4A for ; Thu, 22 Aug 2024 07:13:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id C9F1F6B00FA; Thu, 22 Aug 2024 03:13:27 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id C4D9A6B00FB; Thu, 22 Aug 2024 03:13:27 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AEEC76B01A5; Thu, 22 Aug 2024 03:13:27 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 8CA4D6B00FA for ; Thu, 22 Aug 2024 03:13:27 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 47B3E1613A2 for ; Thu, 22 Aug 2024 07:13:27 +0000 (UTC) X-FDA: 82479015654.13.A52EB81 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) by imf09.hostedemail.com (Postfix) with ESMTP id 10AE9140017 for ; Thu, 22 Aug 2024 07:13:24 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=csgroup.eu; spf=pass (imf09.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.235.10 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1724310725; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-transfer-encoding:content-transfer-encoding: in-reply-to:references; bh=6KxvZSjWsi08QEiOqNxaYL9tEzpEvqv+OknjgJPO4zg=; b=IFLrRp/eIYt9Md6OoLLsxbaGXIXtO3I56u84XXqEFUT0nVsCiLvuup4FJ/Ys/bgI9Icx4W PdHnHxq6Djr/ujVowmdypdz5VK+lVDXU2ueO5bf5H+b+vvSvqUoNc2Pf4FiB7KHTNMDUGE n1LcgnOZ0jold/lkdppFcrca4bWiK4Y= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1724310725; a=rsa-sha256; cv=none; b=OqHiqSpNnpY99pjCrBWgU8UW9BohiTywseiIAqt2MmgSWq3yuGX+XPkiF3h581uIeGJBOi kJ50pdj+zkXAjnHIYxe/ca/umpWVnPr4iLMMBR58ULdio9V7xeba0XSkoBoJKwYfHQXoiV MBMxdYLW1DmBiYJS3A8SMimAVJRyRLk= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=csgroup.eu; spf=pass (imf09.hostedemail.com: domain of christophe.leroy@csgroup.eu designates 93.17.235.10 as permitted sender) smtp.mailfrom=christophe.leroy@csgroup.eu Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4WqDv65R16z9sSK; Thu, 22 Aug 2024 09:13:22 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0-VRwaKzoNbn; Thu, 22 Aug 2024 09:13:22 +0200 (CEST) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4WqDv64Pbrz9sSH; Thu, 22 Aug 2024 09:13:22 +0200 (CEST) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 84A608B77E; Thu, 22 Aug 2024 09:13:22 +0200 (CEST) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id 27TFRoaI4C9O; Thu, 22 Aug 2024 09:13:22 +0200 (CEST) Received: from PO20335.idsi0.si.c-s.fr (PO16920.IDSI0.si.c-s.fr [192.168.232.181]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 6C3F08B763; Thu, 22 Aug 2024 09:13:21 +0200 (CEST) From: Christophe Leroy To: Michael Ellerman , Nicholas Piggin , Christophe Leroy , Naveen N Rao , Andy Lutomirski , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , "Theodore Ts'o" , "Jason A. Donenfeld" , Arnd Bergmann , Andrew Morton , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Vincenzo Frascino , Shuah Khan Cc: linuxppc-dev@lists.ozlabs.org, linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-trace-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org Subject: [PATCH v2 00/17] Wire up getrandom() vDSO implementation on powerpc Date: Thu, 22 Aug 2024 09:13:08 +0200 Message-ID: X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Developer-Signature: v=1; a=ed25519-sha256; t=1724310793; l=4901; i=christophe.leroy@csgroup.eu; s=20211009; h=from:subject:message-id; bh=LDTg0Yi2fhuFH1uAWm1BFhSE+R7SP2TBN1LukDLSwAc=; b=dv3IJ6HgpSk062fA80pC3beOaGyDkub2uRhJOU7nq6upvK1O1zJTzR6G/vOqsb7Bf92j66uNp R/+usMEBgmRBPUzWE5rLVkIDoO79FdFlAYqzoQmRCjL2crIMNd9IRbK X-Developer-Key: i=christophe.leroy@csgroup.eu; a=ed25519; pk=HIzTzUj91asvincQGOFx6+ZF5AoUuP9GdOtQChs7Mm0= X-Rspamd-Queue-Id: 10AE9140017 X-Stat-Signature: 7mdwf1x4qdypnfjb5jkatjys5qwohb74 X-Rspamd-Server: rspam09 X-Rspam-User: X-HE-Tag: 1724310804-297090 X-HE-Meta: U2FsdGVkX1+Wz50FXR+6iSZVDGawvaBYuGV+98Ppi0qKvZH/rCbduZbGFn34311OeEOzBcSXcu1LVwZgjJrEUstC3/Dk/ZS9w6SN0ksp7vUAoO8narvTdrjkDfDkno9kYi15knENRBlUyIOcge3pUEUpelBy30kHptp/xitDuRBin3hi0qeew7JluRviMFHr+aIqqcGjClBGxKyCZSjlo+NCicocuQF5MZ69JSgsCoaCgy/Ho7xd/pHh9FNM8fxXhaXRPc68OjcE8GhLpsrtkrG9eVLUxjd0ZwrdKfQRqQdKQaExZKTAPxELLLpajRZ31xtUwPe9euiZ6p7P4H8zvHuf5aBrtmrZJ80al1EygcbcMQIdc1VEf4+5pZTZ5XX7sT3xxqlG4VfIcp9OkG3Lh0B7b50MYsuL7Kqysg2YZMHmobgbvHlG3d3i1KgL4SBHcTFfFN2VwNWIQEtyyTrR37Q58qlAb6kwiU2H6B+mcMG8RjG5fz/DuF2eWjb7YYe6D1kGvJ8Ryo9+TbFC2hPXWzADRwIFkkAgXZXsC92lo0Joo6jHvQG2ExMXC27vOSZEamOP8x+yfSb6vu+33IxTTUnwStgfVbNoyYGMiwjcUdi3URoO+3nQcXHUG/+Pocp7dmSyuvLZCNxIjS2iuZ0FeMw9HLlHaDnaZ+kfiPG5WHrxWudIMC9EdJ8DffOoBYYkp5sHdmASsy+Kenn4vX1vySiYkfyrXvitj4EJpMTp4y5lgDkb4ycW+E6Warthz1/tJlb8mcT6eyfp+wixZ0qWpPwSQlSNUwCceb9dzoGsfz0W2q5bCKZQXW55fRxdwoacTJzuT7tRl3GLqQDb579NsGh4lMIl/XDFHnL4mPNX1VK+/pS4KNJcp2Mb+a09PnFq3PicQlJdTccUUnkBtzhqc555pn0DX8tELOqbp/xxukzdPClvjr6ypMRWZodAfmI2tUDVUyOmdRvX5zjmxfL IfOOBHkd eQFXGPODEkkdGHMF0+w8pCSVUe/pe03s1UJHS9utryDOeLgTZKshdPj5zZ2R53XYGAzCM X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: This series wires up getrandom() vDSO implementation on powerpc. Tested on PPC32. Performance on powerpc 885 (using kernel selftest): ~# ./vdso_test_getrandom bench-single vdso: 2500000 times in 7.897495392 seconds libc: 2500000 times in 56.091632232 seconds syscall: 2500000 times in 55.704851989 seconds Performance on powerpc 8321 (using kernel selftest): ~# ./vdso_test_getrandom bench-single vdso: 2500000 times in 2.017183250 seconds libc: 2500000 times in 13.088533630 seconds syscall: 2500000 times in 12.952458068 seconds Only build tested on PPC64. There is a problem with vdso_test_getrandom selftest, it doesn't find vDSO symbol __kernel_getrandom. There is the same problem with vdso_test_gettimeofday so it is not related to getrandom. On strange things to be clarified, there is the format of the key passed to __arch_chacha20_blocks_nostack(). In struct vgetrandom_state it is declared as a table of u32, but in reality it seems it is a flat storage that needs to be loaded in reversed byte order, so it should either be defined as a table of bytes, or as a table of __le32 but not a table of u32. But this has no impact and can be clarified later and fixed in a follow-up patch. 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 (17): asm-generic/unaligned.h: Extract common header for vDSO vdso: Clean header inclusion in getrandom vdso: Add __arch_get_k_vdso_rng_data() vdso: Add missing c-getrandom-y in Makefile vdso: Avoid call to memset() by getrandom vdso: Change getrandom's generation to unsigned long mm: Define VM_DROPPABLE for powerpc/32 powerpc: Add little endian variants of LWZX_BE and STWX_BE powerpc/vdso32: Add crtsavres powerpc/vdso: Refactor CFLAGS for CVDSO build powerpc/vdso: Wire up getrandom() vDSO implementation selftests: vdso: Fix powerpc64 vdso_config selftests: vdso: Don't hard-code location of vDSO sources selftests: vdso: Make test_vdso_getrandom look for the right vDSO function selftests: vdso: Fix build of test_vdso_chacha selftests: vdso: Make VDSO function call more generic selftests: vdso: Add support for vdso_test_random for powerpc 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 | 67 ++++ 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 | 45 ++- 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 | 297 ++++++++++++++++++ arch/powerpc/kernel/vdso/vgetrandom.c | 14 + arch/x86/entry/vdso/vma.c | 3 + arch/x86/include/asm/pvclock.h | 1 + arch/x86/include/asm/vdso/vsyscall.h | 10 +- drivers/char/random.c | 5 +- fs/proc/task_mmu.c | 4 +- include/asm-generic/unaligned.h | 11 +- include/linux/mm.h | 4 +- include/trace/events/mmflags.h | 4 +- include/vdso/datapage.h | 2 +- include/vdso/getrandom.h | 2 +- include/vdso/helpers.h | 1 + include/vdso/unaligned.h | 15 + lib/vdso/Makefile | 1 + lib/vdso/getrandom.c | 30 +- tools/arch/powerpc/vdso | 1 + tools/arch/x86/vdso | 1 + tools/include/linux/linkage.h | 4 + tools/testing/selftests/vDSO/Makefile | 12 +- tools/testing/selftests/vDSO/vdso_call.h | 52 +++ tools/testing/selftests/vDSO/vdso_config.h | 14 +- .../selftests/vDSO/vdso_test_getrandom.c | 11 +- 35 files changed, 628 insertions(+), 76 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 100644 include/vdso/unaligned.h create mode 120000 tools/arch/powerpc/vdso create mode 120000 tools/arch/x86/vdso create mode 100644 tools/testing/selftests/vDSO/vdso_call.h