From patchwork Fri Nov 26 03:22:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1559941 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=j89VpPiO; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J0g7D3cBMz9t2p for ; Fri, 26 Nov 2021 14:23:19 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4J0g7670y2z2xXd for ; Fri, 26 Nov 2021 14:23:14 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=j89VpPiO; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::1032; helo=mail-pj1-x1032.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=j89VpPiO; dkim-atps=neutral Received: from mail-pj1-x1032.google.com (mail-pj1-x1032.google.com [IPv6:2607:f8b0:4864:20::1032]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4J0g6s18ZNz2x9g for ; Fri, 26 Nov 2021 14:22:59 +1100 (AEDT) Received: by mail-pj1-x1032.google.com with SMTP id nh10-20020a17090b364a00b001a69adad5ebso7057297pjb.2 for ; Thu, 25 Nov 2021 19:22:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=GUaUmTr1C3qa9qMGfGDtZO3hUTUW9SwzE/2YoH0XipE=; b=j89VpPiOLuLWVjFMpUdPKb0pDBpUjRwbRR4qI377GR6bkwB51re4Ar52eVMQMupTOd YS3Xj3gqMgjoZYe7JsFstT0oehD3W3JK2ipP4IgCZQ07nNtzPcsbcrR7cdZQdT1vTCnm VI+8FV35jeFKvCtOReAfs6U4YQHNWhGBxrAaLWlQElpzalrc0ARJGgnV3EbQYIXiZ3Gf AzbHZY6T6U17T523GI9Oyw07P+gmUZKMdKKVs4g+JtNAIvn2tc9E4JDcdVxQKlSKWk29 vaNcLJIS7kR9wX/dVDLTuUdLQvPjN72FYFc5FCE+nN5y50RxdwC1IEJyFag9k5Lt5ncE qfdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=GUaUmTr1C3qa9qMGfGDtZO3hUTUW9SwzE/2YoH0XipE=; b=VrQTS2DfxUgnE7IpugGaSQSutUL4o8Ty4b+lftIlpr0OsPfCLHkY5ba10eDjWXf/tD XHjXpJfKOnpFvBPWbGLUcwHueDSUWIdAZMTIg8cxqippk66hOgYL9g58E+Omhk6ztdA2 X/+h/upB3+segIOAT0HIS/VNPb/HWKT3MYYNiLAAiYV6PtFDXNWohDVmaDZxe6n7GVCt r88zCfV3HKorW/LSoKHVXmXItBcO3P7EaSTlT/7Id8X4y9l8T6vP4iPm2YGZ0GqeT2/4 HT9uaTFLUyupo3cztm58UxWbQ63TIjAQHF1oKxpUXzi+pSQ8TS3SaulBqiEeUxykOhPo zONg== X-Gm-Message-State: AOAM532qEmPVTr983a3xFIsAW1JeEc1zxr7AwtD/4eaby62HdZRcrlji g/ONQpwF+up8Om8r8H5d/Vingdivg1s= X-Google-Smtp-Source: ABdhPJyq9vtgQ1WWEjdpXY/r7Of5mLpG89C3zPAC5Rc3CzOd/2f2wPfSnRb9V/dG4X1x44i0qZ5PdA== X-Received: by 2002:a17:90a:3e09:: with SMTP id j9mr12682511pjc.24.1637896976099; Thu, 25 Nov 2021 19:22:56 -0800 (PST) Received: from bobo.ozlabs.ibm.com (115-64-213-93.static.tpgi.com.au. [115.64.213.93]) by smtp.gmail.com with ESMTPSA id l4sm5143386pfc.121.2021.11.25.19.22.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Nov 2021 19:22:55 -0800 (PST) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 1/3] powerpc/code-patching: work around code patching verification in patching tests Date: Fri, 26 Nov 2021 13:22:47 +1000 Message-Id: <20211126032249.1652080-1-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Code patching tests patch the stack and (non-module) vmalloc space now, which falls afoul of the new address check. The stack patching can easily be fixed, but the vmalloc patching is more difficult. For now, add an ugly workaround to skip the check while the test code is running. Fixes: 8b8a8f0ab3f55 ("powerpc/code-patching: Improve verification of patchability") Signed-off-by: Nicholas Piggin --- arch/powerpc/lib/code-patching.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c index 5e2fe133639e..57e160963ab7 100644 --- a/arch/powerpc/lib/code-patching.c +++ b/arch/powerpc/lib/code-patching.c @@ -187,10 +187,12 @@ static int do_patch_instruction(u32 *addr, struct ppc_inst instr) #endif /* CONFIG_STRICT_KERNEL_RWX */ +static bool skip_addr_verif = false; + int patch_instruction(u32 *addr, struct ppc_inst instr) { /* Make sure we aren't patching a freed init section */ - if (!kernel_text_address((unsigned long)addr)) + if (!skip_addr_verif && !kernel_text_address((unsigned long)addr)) return 0; return do_patch_instruction(addr, instr); @@ -738,11 +740,13 @@ static int __init test_code_patching(void) { printk(KERN_DEBUG "Running code patching self-tests ...\n"); + skip_addr_verif = true; test_branch_iform(); test_branch_bform(); test_create_function_call(); test_translate_branch(); test_prefixed_patching(); + skip_addr_verif = false; return 0; } From patchwork Fri Nov 26 03:22:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1559942 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=ZKoNWSV+; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J0g7r3rjHz9t2p for ; Fri, 26 Nov 2021 14:23:52 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4J0g7r20RSz3c8m for ; Fri, 26 Nov 2021 14:23:52 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=ZKoNWSV+; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::535; helo=mail-pg1-x535.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=ZKoNWSV+; dkim-atps=neutral Received: from mail-pg1-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4J0g6s1QTWz2yPT for ; Fri, 26 Nov 2021 14:23:00 +1100 (AEDT) Received: by mail-pg1-x535.google.com with SMTP id 28so6893595pgq.8 for ; Thu, 25 Nov 2021 19:23:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DO433WuqOGDgpk9jbl8imWfj3x0wA3HT2dbvjJ6E+tc=; b=ZKoNWSV+Etv3ZtRJdkMmpxGg2nJYkM5tqgMm2tq/5YMNiQRaU9UtcustlAFq3pnLMR pbujUWFVGNZvnuQK5xC0q7my02rjsOcmukNozGvD+cmYDlzCmUpdO5ocljxkuD5kWK7L l5mDMfQMW25sJc/9cdLp7THrNlvRJsJojTu5dPcW+lIlgkHk+fx3p7zxsIyvFSzrG2Xo Ni1GhMEJq532HSHQ8+OLiLfUj5/V5ly3oJt19d2rdUZ9O7M8BG63F8l0R4MK1eFqRhJI OjndlRQkQNTIKoUCtq959QxzOEz+9GEhfjCXxMUn5FThq7lPNoi95K/ma0T44Y88tY10 1cXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DO433WuqOGDgpk9jbl8imWfj3x0wA3HT2dbvjJ6E+tc=; b=LkZ7P5m6Y3WqPbWx7I3By5kYJFTHtmU4SslupdasJ1a/OJeFmXE3oWL7Z9ZOd4KymC 5gWVDZEutaEaYiLUB5QrqJf0VdgCYJTdwpEIlj5yepYjFmX19iZ3x0GoqjRWDNq9pbTY cIWEud+4YcsH4EL1gmCD+iguF3PMtgnPi629Mrjcn/r/BTZYMqLGSoWVoJor//fZD1tF XDznnUZ8fa2N801HeZN9XA8qmls0VQLBfhpKcWhay/vqS8n2Rgh88QgCBMtipnmieO6S Vq3rxe4smMjpe0N6D3mUg65BZZ6g9PDF1ODTr17YVxX0vt+j8IgHIL7065kZFPqv3p18 osYQ== X-Gm-Message-State: AOAM530X//u8j8i91fETPZFbqYKQDrpSMw7kTkcsy/cxqpMfkrS2n0tO gfbXQDg+1MNAMflWwajYi+PhL25yXR0= X-Google-Smtp-Source: ABdhPJz0Dqfj4hOHB0clyKD5ZP44o6u46wokJujnHUXl6V/8RsXgzFE6zcM4bOe2AdVqFO3+aW3DKw== X-Received: by 2002:a62:e907:0:b0:4a0:3a71:9712 with SMTP id j7-20020a62e907000000b004a03a719712mr19029749pfh.73.1637896978550; Thu, 25 Nov 2021 19:22:58 -0800 (PST) Received: from bobo.ozlabs.ibm.com (115-64-213-93.static.tpgi.com.au. [115.64.213.93]) by smtp.gmail.com with ESMTPSA id l4sm5143386pfc.121.2021.11.25.19.22.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Nov 2021 19:22:58 -0800 (PST) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 2/3] powerpc/code-patching: warn on code patching failure Date: Fri, 26 Nov 2021 13:22:48 +1000 Message-Id: <20211126032249.1652080-2-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20211126032249.1652080-1-npiggin@gmail.com> References: <20211126032249.1652080-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Callers are supposed to handle this, but it is possible that they don't or they do but don't make much noise about it. A failure is probably an indication of a bigger problem somewhere so it is good to warn once about it. Signed-off-by: Nicholas Piggin --- arch/powerpc/lib/code-patching.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c index 57e160963ab7..70247fc58b6e 100644 --- a/arch/powerpc/lib/code-patching.c +++ b/arch/powerpc/lib/code-patching.c @@ -161,6 +161,7 @@ static int do_patch_instruction(u32 *addr, struct ppc_inst instr) text_poke_addr = (unsigned long)__this_cpu_read(text_poke_area)->addr; if (map_patch_area(addr, text_poke_addr)) { + WARN_ON_ONCE(1); err = -1; goto out; } @@ -192,8 +193,10 @@ static bool skip_addr_verif = false; int patch_instruction(u32 *addr, struct ppc_inst instr) { /* Make sure we aren't patching a freed init section */ - if (!skip_addr_verif && !kernel_text_address((unsigned long)addr)) + if (!skip_addr_verif && !kernel_text_address((unsigned long)addr)) { + WARN_ON_ONCE(1); return 0; + } return do_patch_instruction(addr, instr); } From patchwork Fri Nov 26 03:22:49 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1559943 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=BfmN6JwU; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=2404:9400:2:0:216:3eff:fee1:b9f1; helo=lists.ozlabs.org; envelope-from=linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2404:9400:2:0:216:3eff:fee1:b9f1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J0g8Y2qBMz9t2p for ; Fri, 26 Nov 2021 14:24:29 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4J0g8X5h7lz3cNK for ; Fri, 26 Nov 2021 14:24:28 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=BfmN6JwU; dkim-atps=neutral X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::1029; helo=mail-pj1-x1029.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=BfmN6JwU; dkim-atps=neutral Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4J0g6t5tCyz2x9g for ; Fri, 26 Nov 2021 14:23:02 +1100 (AEDT) Received: by mail-pj1-x1029.google.com with SMTP id y14-20020a17090a2b4e00b001a5824f4918so8949273pjc.4 for ; Thu, 25 Nov 2021 19:23:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=siIOxxyhAn1KZ3ftKBh1iR9TL35DhB2z4dfXYlVCeX4=; b=BfmN6JwUaQ87LPPB/UXQORvjNTwJeGwm40XvON8jwo15PNFOhOxALRNxzRtCk91uZ/ 3znhZXB9PhpU42bJGTVk5H6cIVpRA3YgIagIuQ/Ad7ED4+PrPypyJexGnefLo6ImHTL2 w7n9/EIoArk2j4kvOBvmXYr2oQWzBhSgRp3Vk05wIwvtek7BHH6iUJ3LKkpwCf3F/U2R aZ6jWcuHujvSywHn/wu3rzkoxRDhQ9RXb3YRK0EXLNN3xK7fLuT3Yg8CDx5Nm50KkYB1 l8ScUalpG557y18f0+66OQRNnQS5hkeCXYtYey8nBeqhHsFjdZhzmtnbmtb6mUAObRpj Nwcg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=siIOxxyhAn1KZ3ftKBh1iR9TL35DhB2z4dfXYlVCeX4=; b=zMpOS21oaikVKXP1K5mXlneB5T0fyvXLAClwO1czsFv9oHdOGm9x1qK6JjFcqxsa8Q Je6OVnVE/wuMnvabhd6XrHEzKJ+bvB5CYNicTSMgNxOpCLdFI7CgoS9tHut4vpMmcMsq 4IJdWwz5Y+2Gv3Y+NL8qma+G7tUmI5U1/DmwE6sgcTdqhHqE8hWvS7ghEnqcX887UYac slTJOVka6oYhxzcGAsb72yk7agUBcGhkc1qfXnepCiaWmYtGiNag+rWiEEnITbOUnIjr hR0bFydgm9y2pbxtooy3aKB+gDG6+GdTu7rcWyxZpvP/haI5wK0wl/tKCUF8r20jXs3M RrPA== X-Gm-Message-State: AOAM530UG7vUP7kk9GGcqbTwra8OFsEHVVwH8gN3dmMoKvBNonu2GGrX IqdAzaIyJVcdhIgG8wM3H9Doz76utRk= X-Google-Smtp-Source: ABdhPJxdo6kqr0cmfu8gwRMlMtg9s+d7kBXHpeR8rWZYBxttPMq4XIV+H7n8HzqzKxAOzkfJyHAF8w== X-Received: by 2002:a17:90a:9294:: with SMTP id n20mr12289803pjo.69.1637896980953; Thu, 25 Nov 2021 19:23:00 -0800 (PST) Received: from bobo.ozlabs.ibm.com (115-64-213-93.static.tpgi.com.au. [115.64.213.93]) by smtp.gmail.com with ESMTPSA id l4sm5143386pfc.121.2021.11.25.19.22.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 25 Nov 2021 19:23:00 -0800 (PST) From: Nicholas Piggin To: linuxppc-dev@lists.ozlabs.org Subject: [PATCH 3/3] powerpc/code-patching: don't use the stack for code patching tests Date: Fri, 26 Nov 2021 13:22:49 +1000 Message-Id: <20211126032249.1652080-3-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20211126032249.1652080-1-npiggin@gmail.com> References: <20211126032249.1652080-1-npiggin@gmail.com> MIME-Version: 1.0 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Nicholas Piggin Errors-To: linuxppc-dev-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" Use the existing test function for code patching tests instead of writing to the stack. This means the address verification does not have to be bypassed for these tests. Signed-off-by: Nicholas Piggin --- arch/powerpc/lib/code-patching.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/arch/powerpc/lib/code-patching.c b/arch/powerpc/lib/code-patching.c index 70247fc58b6e..babf6b22adef 100644 --- a/arch/powerpc/lib/code-patching.c +++ b/arch/powerpc/lib/code-patching.c @@ -422,9 +422,11 @@ static void __init test_branch_iform(void) { int err; struct ppc_inst instr; - u32 tmp[2]; - u32 *iptr = tmp; - unsigned long addr = (unsigned long)tmp; + u32 *iptr; + unsigned long addr; + + iptr = (u32 *)ppc_function_entry(test_trampoline); + addr = (unsigned long)iptr; /* The simplest case, branch to self, no flags */ check(instr_is_branch_iform(ppc_inst(0x48000000))); @@ -516,12 +518,12 @@ static void __init test_create_function_call(void) static void __init test_branch_bform(void) { int err; - unsigned long addr; struct ppc_inst instr; - u32 tmp[2]; - u32 *iptr = tmp; + u32 *iptr; + unsigned long addr; unsigned int flags; + iptr = (u32 *)ppc_function_entry(test_trampoline); addr = (unsigned long)iptr; /* The simplest case, branch to self, no flags */ @@ -603,6 +605,12 @@ static void __init test_translate_branch(void) if (!buf) return; + /* + * Have to disable the address bounds check for patch_instruction + * because we are patching vmalloc space here. + */ + skip_addr_verif = true; + /* Simple case, branch to self moved a little */ p = buf; addr = (unsigned long)p; @@ -715,6 +723,8 @@ static void __init test_translate_branch(void) check(instr_is_branch_to_addr(p, addr)); check(instr_is_branch_to_addr(q, addr)); + skip_addr_verif = false; + /* Free the buffer we were using */ vfree(buf); } @@ -743,13 +753,11 @@ static int __init test_code_patching(void) { printk(KERN_DEBUG "Running code patching self-tests ...\n"); - skip_addr_verif = true; test_branch_iform(); test_branch_bform(); test_create_function_call(); test_translate_branch(); test_prefixed_patching(); - skip_addr_verif = false; return 0; }