From patchwork Wed Mar 27 16:04:40 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13607029 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 3A763CD1280 for ; Wed, 27 Mar 2024 16:05:52 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=tnIPWjbfH7VelsH5kJfay0krWFCQmbS45VlcI74N+rs=; b=hvd/NCauQH4aTo nU+CmYMBq0h0Yia5o0if8a2zjCFHIeb1mMISFtWxLSS6EB0iXQL/kp1/HVJ/sKpAUUj1CPICUfvQD /XpQGrnHzI0zlm8ZBp3kynVqq7eriJa4BgOSi/88WZz3TOevvedk2E60LMORYqhpQudjzxn5q1zD1 j14nQwJfCXIm9PTIOxg+c5Uuq8BTQu61TmN2FSUpZxzcQYsZVs/SVYhmexm3yQZwsahgJ7sFLGCCo VRRiTXKcDjOfQ72bmAwq1nFJuBv8P9z4BWP4bPFFXGHjmah/kELymyT7Kct8f8Geo3FGmcH5ODLoh NcsBAeqdkqTDz9Sd1bgg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpVme-00000009zIA-0Sr0; Wed, 27 Mar 2024 16:05:48 +0000 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpVmI-00000009z6q-0QP6 for linux-riscv@lists.infradead.org; Wed, 27 Mar 2024 16:05:33 +0000 Received: by mail-pl1-x632.google.com with SMTP id d9443c01a7336-1e0d82d441bso24232865ad.3 for ; Wed, 27 Mar 2024 09:05:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711555524; x=1712160324; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=VuDNJ40vLIezNFuUe/xAQeUguFHfIodkK1lC+Qglvxs=; b=WEqTBJqeK2LLW0yXJw8eiacYWZa5+72h2ptbd3UI5gA8Ez6LNgUzai9eN/NkqTKxly Kqz+AhboQFNPkGoeSLxraljxMCwmoovA8aZMuXJOwfBdCPFVoY+5EBdCEBpBolKtG8Pt bqV7BbRQuhUITZ48YRfuR6qHVYa4H76O19l6tjer+59rHJU8Rl2+crzwaljRSEUUdtox MB2OpNkbLmVaSEZ1Otn5dQ2Ac2M3D42lE7JWpVFSi1fwlDXRUdt9FtDTwp6RyWEAvO4/ lSrcZQEJ5oRyrA4O8aH0GBiSdDPRPwNvV5n7SsjMy+5/hRFahSkzarRJi0kk35R15HIa QV6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711555524; x=1712160324; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=VuDNJ40vLIezNFuUe/xAQeUguFHfIodkK1lC+Qglvxs=; b=TCTWzeGWkXrvtq+atX26B3PKXAvEs6qxUj/4TqbRPBFJOlpm1f28K2ci87CUTyJiwe aGOr88ma9uqdwe2mVUKFSJgFfueM7/15cIlLswUGp07Jfhu9UINqKMpwY7FNJZl8emH8 9tYrAn7eDFXeec0V22Ak199jWOYbtPaUkJb57nuZkJzmDD5xMGyO8/3PEK2nPpYvU1Un fdY4PeCmu7hbpfuVKAe/m8fj6jzynBTFoYgg52IunO5EQPEVKujWsAhk6+6b2a10XYRf AxzuqHLE3pAmQRFDdB/5GNhg3JgLfeHIJYApCtJ3yYkTy5Py1INq/pPcZ5uxRVvor9mo 1DEg== X-Forwarded-Encrypted: i=1; AJvYcCWy0QpcAtEJCBu4n7OGGxSZdL5TmS77/49YBaZ0W07tbsdO1Rm/RpKEqXjamFe4yji7QHakIsWCAvOWdJ3q2HBWmmjZBcubhvdwmZpz7STL X-Gm-Message-State: AOJu0YxqmRjDzOdANKZKqV9xzRth4LiFC6P2RXAqrs12LczC7uHMOBAr i1H7IuckOcyST3hnLbETJJwH7caAGagfcQNhkSV4Pd5kIjjo52NcDj+61rIwnc8= X-Google-Smtp-Source: AGHT+IFLpO6qOZi7q4RhE4GsZZhUwfq9Dw57tdLyUjstKo8gtTnO92RJN1LNXII9AjG38+eBbfsS1w== X-Received: by 2002:a17:902:784c:b0:1dd:a33f:5913 with SMTP id e12-20020a170902784c00b001dda33f5913mr139558pln.30.1711555523234; Wed, 27 Mar 2024 09:05:23 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id bf4-20020a170902b90400b001e14807f9cesm1718226plb.125.2024.03.27.09.05.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 09:05:22 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Samuel Holland , Ard Biesheuvel , Jason Baron , Josh Poimboeuf , Peter Zijlstra , Steven Rostedt Subject: [PATCH v2 1/7] riscv: jump_label: Batch icache maintenance Date: Wed, 27 Mar 2024 09:04:40 -0700 Message-ID: <20240327160520.791322-2-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240327160520.791322-1-samuel.holland@sifive.com> References: <20240327160520.791322-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240327_090527_045904_7B78212F X-CRM114-Status: GOOD ( 10.90 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org Switch to the batched version of the jump label update functions so instruction cache maintenance is deferred until the end of the update. Reviewed-by: Björn Töpel Signed-off-by: Samuel Holland --- (no changes since v1) arch/riscv/include/asm/jump_label.h | 2 ++ arch/riscv/kernel/jump_label.c | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/arch/riscv/include/asm/jump_label.h b/arch/riscv/include/asm/jump_label.h index 4a35d787c019..6290b26f4a14 100644 --- a/arch/riscv/include/asm/jump_label.h +++ b/arch/riscv/include/asm/jump_label.h @@ -12,6 +12,8 @@ #include #include +#define HAVE_JUMP_LABEL_BATCH + #define JUMP_LABEL_NOP_SIZE 4 static __always_inline bool arch_static_branch(struct static_key * const key, diff --git a/arch/riscv/kernel/jump_label.c b/arch/riscv/kernel/jump_label.c index e6694759dbd0..11ad789c60c6 100644 --- a/arch/riscv/kernel/jump_label.c +++ b/arch/riscv/kernel/jump_label.c @@ -9,13 +9,14 @@ #include #include #include +#include #include #define RISCV_INSN_NOP 0x00000013U #define RISCV_INSN_JAL 0x0000006fU -void arch_jump_label_transform(struct jump_entry *entry, - enum jump_label_type type) +bool arch_jump_label_transform_queue(struct jump_entry *entry, + enum jump_label_type type) { void *addr = (void *)jump_entry_code(entry); u32 insn; @@ -24,7 +25,7 @@ void arch_jump_label_transform(struct jump_entry *entry, long offset = jump_entry_target(entry) - jump_entry_code(entry); if (WARN_ON(offset & 1 || offset < -524288 || offset >= 524288)) - return; + return true; insn = RISCV_INSN_JAL | (((u32)offset & GENMASK(19, 12)) << (12 - 12)) | @@ -36,6 +37,13 @@ void arch_jump_label_transform(struct jump_entry *entry, } mutex_lock(&text_mutex); - patch_text_nosync(addr, &insn, sizeof(insn)); + patch_insn_write(addr, &insn, sizeof(insn)); mutex_unlock(&text_mutex); + + return true; +} + +void arch_jump_label_transform_apply(void) +{ + flush_icache_all(); } From patchwork Wed Mar 27 16:04:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13607027 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 6AA6EC54E67 for ; Wed, 27 Mar 2024 16:05:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=78ZIwFUdREo66GFqWSz93Z8Gstcr/E0KtEVc6BQOBFo=; b=b7NL3hiLFmAiMF mdRKMTwS+YoyyKjx4LQVejmVAmJn3tZiEzP2VcKpLGWfY9maJuFdsYdzIyZFRtlN/7HBtFdqewzxw FlRDz/tlxYUq76NuLkKSnS1Nwh04g9JuCQv56OJX0SkJxVaYstz9s1kId8Z24XIhJfK6/YDMR2zxN hr9pflF+n3zWYaMdDcjCFxomgg10MOR3Pk4YoNxafuvewcX9TpdwTqHbD3BcTHmxK3avTWGm0Y/+a 1rBrFT6CqIDTdhoJeU5nLwlooKO6Hg97J1ebB4VaZE4Utnal0dp5627JDQhpR74xV7Fj2MHIpPj2f o14SE8NOXdvwx+1DEqCA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpVmY-00000009zEU-3WLX; Wed, 27 Mar 2024 16:05:42 +0000 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpVmK-00000009z8O-363F for linux-riscv@lists.infradead.org; Wed, 27 Mar 2024 16:05:33 +0000 Received: by mail-pl1-x62b.google.com with SMTP id d9443c01a7336-1def2a1aafaso46050095ad.3 for ; Wed, 27 Mar 2024 09:05:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711555526; x=1712160326; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=5Xc93+JfN2S4FIXbabsoTVMgsbTEMk8Oy5ZNwdIewJ8=; b=SI89lYADumqU5M6VxoYnwd3s9RKH5fTeshCIApM1i5xUXqtf37+JLU8WvSCju2FLuH KGwvhFSQvl0TNveBaPT6KHhQ0PV0BZXiHYuWp0DJOvJX3rc7Yll0+riTYBWhcSs2oQdo WvZe8o5Z+UfcWqQYCrhOc9tcHADUzv8zmWOJOHTADeYLlnEGqGOO+/SAftVccPDtDEJv PO7qWbMfMUU16oOItLlBqkPCmRos1QWiqiVaCkVK2jprzW3m1Wg3K8QvhoW3bkbGSxrz uWJHxw4TZoH5pdOA9C0VcvN6bF+5OxS9O2XWqVunq3tDKoK30xLPN6xrtI+VEBULY6a6 46eQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711555526; x=1712160326; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=5Xc93+JfN2S4FIXbabsoTVMgsbTEMk8Oy5ZNwdIewJ8=; b=GDL5Ub1HqDKyLq3bW/s46FHuitsxthg78tvdWWUFD4lvkChZYl3ZT4/d5aMOrwCUP7 2igS73ytvxCgVOJVt5HqWiFLyyBOd5UADZaTgANZfj/DFmJctFZeuHKPtWbVnAP+T1gG iHY+EVK/0MWwtQU2AllfU9Ku2vEZ6encDSWreXoHIZSOFVW+3dTE6OUhLi0a14fT+6Ol c5NMHlwd2ocn8MhImRDZHjJ6akyAlAO0pdXxWWqkJACOGGeQN43Oaz6r0eJczx+exG4C udljjOobc1KShDTrTukla+xSAFXb4BNMRjNuBdnqwh1J/SLERP6MbGzEB5hQaQiSuTu5 rPMQ== X-Forwarded-Encrypted: i=1; AJvYcCXRxXUeVDjhFg0dHfk6Y2kl38hcdt71u1M/TnnvKfTZX6RQuC7U2E2qNZR/hHQDTFK8Sfqq45yeLM58zo7iiS6u7LGB5AhWSTX7qbKZYcL7 X-Gm-Message-State: AOJu0YxJLOaHtxFcyQVmmvrGkE3sijs8tPs94JAbVeE3U5zqnw8cOXs1 hc/VYBNTcXdU9IOh38vwTWRjRahW1YQedD/ts85sHAA3yVzYOM80TKUBxxnT26s= X-Google-Smtp-Source: AGHT+IG5UtEW/LihmnxDCmHBZwJ44J0/v8NsXjFKi7Yo3FMGF74v7Eh2hJ1dT0cL1L3h19a1fVN3hQ== X-Received: by 2002:a17:903:287:b0:1e0:c580:4972 with SMTP id j7-20020a170903028700b001e0c5804972mr102612plr.33.1711555525198; Wed, 27 Mar 2024 09:05:25 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id bf4-20020a170902b90400b001e14807f9cesm1718226plb.125.2024.03.27.09.05.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 09:05:24 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Samuel Holland Subject: [PATCH v2 2/7] riscv: jump_label: Simplify assembly syntax Date: Wed, 27 Mar 2024 09:04:41 -0700 Message-ID: <20240327160520.791322-3-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240327160520.791322-1-samuel.holland@sifive.com> References: <20240327160520.791322-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240327_090529_050622_CC3DAA7C X-CRM114-Status: UNSURE ( 9.04 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org The idiomatic way to write "jal zero" is "j". Reviewed-by: Björn Töpel Signed-off-by: Samuel Holland --- (no changes since v1) arch/riscv/include/asm/jump_label.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/include/asm/jump_label.h b/arch/riscv/include/asm/jump_label.h index 6290b26f4a14..1c768d02bd0c 100644 --- a/arch/riscv/include/asm/jump_label.h +++ b/arch/riscv/include/asm/jump_label.h @@ -46,7 +46,7 @@ static __always_inline bool arch_static_branch_jump(struct static_key * const ke " .option push \n\t" " .option norelax \n\t" " .option norvc \n\t" - "1: jal zero, %l[label] \n\t" + "1: j %l[label] \n\t" " .option pop \n\t" " .pushsection __jump_table, \"aw\" \n\t" " .align " RISCV_LGPTR " \n\t" From patchwork Wed Mar 27 16:04:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13607030 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id BECE3C47DD9 for ; Wed, 27 Mar 2024 16:06:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=rDT7TNcNnajlbG9tuSSHdW//t6PFpxXZf3+gFKbsSPQ=; b=La01an3KywPkTI RsEZlXE1K1EI0oXdJ1KbwQGX9ZxYlBV9p31q7AF72mIPXrPhjy4cD3J+sky4xb1CyP2gTpnPy2IrC JCxYlatiXBjWIgD65eGMRj4G5sYsn9656gPBG3TUxgEby+suSBGN97WpkowLfOwCOIELIo1ZdBNpz Br5225kEHDLXg9fPybxu7DIelfPaWbe3yGQuzdcrZXlAxEiS2Gr1g2xbyfT0zmNDZGEBnY7OzkbCb mdbBFAmQDER3ITy/Bcvlqy9u8FyyErbILr69tB9GKdRsrlAkquRuymHl9XpIoOUHpD0YkeTOQJF/D S4Bk6F+ztySrBoCY9PsA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpVmg-00000009zJN-2MnO; Wed, 27 Mar 2024 16:05:50 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpVmR-00000009zAx-2DvE for linux-riscv@bombadil.infradead.org; Wed, 27 Mar 2024 16:05:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=o/A8S6GwPVeRQh4mUyUZHiHi/w/+o4RQ1PPE/E2MAhE=; b=iLtlorDuIuHgNcRK8ItTt1YztN O2o/58RFRCWtonYdyQt4rwhwsaBdCzqOJ/mzDt1pn5QpPygyRU5A3GT4k5y1XlRu7c2IIM2BUQ88U hr05rtClnpWxwwl36Vt/O0gNmuR7jmqUNvb1j5+5Y5uQRI2H9yPowsIUpRHC9lqvQ8pvjgdrbjnZc 5VQD45ibl1fJK3yJMyEnsiYuzG6Vu+LJoJJtFtONwPQjJcMDgdy0DXVPVOMcCjxTbfJnvAWHjwzod JFzjrkW1PGrNYBmzhN7059cjKlzlKEIxmiUbLgrriEmlKYDkt73JqBjFz7OU/mq5qws2N8IzZozfr K7e2BHnQ==; Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpVmM-00000000MSr-1PMh for linux-riscv@lists.infradead.org; Wed, 27 Mar 2024 16:05:34 +0000 Received: by mail-pl1-x636.google.com with SMTP id d9443c01a7336-1e0f2798b47so83525ad.1 for ; Wed, 27 Mar 2024 09:05:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711555526; x=1712160326; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=o/A8S6GwPVeRQh4mUyUZHiHi/w/+o4RQ1PPE/E2MAhE=; b=BRvqOdTLK2kCzyHKepDBGUowwi9vEN3gVmgt4U3c7q/hy4ekyJVDKkxWJGtsJ1LyGm MFg0RiplUtCNFnb2RDWbp6TGJ6IO0Sa/co4sXFdKfgZPnFc7Oq+vi0Uq8OQW7rXVEsgg WpKl5iKQiNA+4O302j3mh4I04Q49tlhwh4qIBZ/Ab8UewTWv3QnHhups/fL7JTV7PIeR 8VZzZAT1/ibyC5bLtUpUtGN1iTNzNPJkstVBQR1n5cfm0xjWpGvjjPaCNnTWw+2Xg6gD RmKag8fFhAV2x4cSmCI8hbeG5NwqLIby1TAppORh10ZAKT3TSubt++KrAlLT9QRQfhgo vHrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711555526; x=1712160326; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=o/A8S6GwPVeRQh4mUyUZHiHi/w/+o4RQ1PPE/E2MAhE=; b=oPwp3JJKYHHm9PRLSHmPiq2gJZFZMPWmKCkKDkiDL1QKKA696XLYHvwCKMMEHk+Xgq ffVQ3mlDhFWNCkItAmOXnGYFUV7Og+hTjthZwOHG1LSdqZD1wxZ/ClK/+KiOR1HD134n IafArqDCPa5xSXIthlLIytkp2/rdAtmUCtXhvumHrjkNgOFnYew0dvt5i0O8pjcnmOwb cAvWgCKgucTrLkuP8B27D9XsZVPT4t0HYNnZTE5HH9bC6M0sIEhICYdGwJkw5YTOKqxw DDWNYwfXFe+6KFc3qd4TsF4UbqUYd6HsgiEaHSVpAeHMPq7nhFHk4ElGlAxjJEZBexH4 /Hjw== X-Forwarded-Encrypted: i=1; AJvYcCVVaKOKa2Rpu+5Qd0Igh7BsuQ2/7p3mTCmKPnoOhqoEocdedbAUfFXIYeBMUeeCcMiEPGjfmMQ7On3o6nxjMTuQxhKoJ4M2Zs/VoCkwcLDi X-Gm-Message-State: AOJu0YyAELLfZn7v+0sp/bibzBzWYrctyW2GwzpU/6N2KAxzvttAxcCY lRcHU55rLhVmleoQgJuefUiTeadB2LwB1/6ljDM9EbQO3ngEBCQw9nb0twhJ5vI= X-Google-Smtp-Source: AGHT+IH/cUxMi1ZJe1xxd7wZiLZTo1eYwqccL1pn+6fDaFGtQ6Q1+BMpEoTMKbn4C0h/HXhupBeb4Q== X-Received: by 2002:a17:902:cf02:b0:1e0:e8b5:3225 with SMTP id i2-20020a170902cf0200b001e0e8b53225mr41189plg.12.1711555526538; Wed, 27 Mar 2024 09:05:26 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id bf4-20020a170902b90400b001e14807f9cesm1718226plb.125.2024.03.27.09.05.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 09:05:26 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Samuel Holland Subject: [PATCH v2 3/7] riscv: kprobes: Use patch_text_nosync() for insn slots Date: Wed, 27 Mar 2024 09:04:42 -0700 Message-ID: <20240327160520.791322-4-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240327160520.791322-1-samuel.holland@sifive.com> References: <20240327160520.791322-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240327_160530_525832_3DD2C0A8 X-CRM114-Status: GOOD ( 10.57 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org These instructions are not yet visible to the rest of the system, so there is no need to do the whole stop_machine() dance. Reviewed-by: Björn Töpel Signed-off-by: Samuel Holland --- Changes in v2: - Remove unnecessary line wrapping arch/riscv/kernel/probes/kprobes.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/probes/kprobes.c b/arch/riscv/kernel/probes/kprobes.c index 2f08c14a933d..fecbbcf40ac3 100644 --- a/arch/riscv/kernel/probes/kprobes.c +++ b/arch/riscv/kernel/probes/kprobes.c @@ -28,9 +28,8 @@ static void __kprobes arch_prepare_ss_slot(struct kprobe *p) p->ainsn.api.restore = (unsigned long)p->addr + offset; - patch_text(p->ainsn.api.insn, &p->opcode, 1); - patch_text((void *)((unsigned long)(p->ainsn.api.insn) + offset), - &insn, 1); + patch_text_nosync(p->ainsn.api.insn, &p->opcode, 1); + patch_text_nosync(p->ainsn.api.insn + offset, &insn, 1); } static void __kprobes arch_prepare_simulate(struct kprobe *p) From patchwork Wed Mar 27 16:04:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13607028 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E3F28C47DD9 for ; Wed, 27 Mar 2024 16:05:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=FRWPmaCGzLrophTCHtPVgIMtEVxrsdFS2c0cJRS2A2k=; b=FzNd7EODd75X4f 5f6szG0Dwfr/HcY7kpl5Xam1ktqr4KcR7U/opsqCcm5Z+4nv6+0xTkn2pLTh0ymX9CCf6s8nlAQj/ 0+u/2FdwamR5Ep07z0BQl012ioDBToQ9Wh2oBY4G0OoU+EYz3FRHLYUrJpHRyIMwk9SrnjOO88TOv D9cVheO9Tx4gEePqHzVLg+fenrRRvuLzujblEmkeNDHcPVIg3hg2QSmbul1+EEXF/uut4D4Wt9+4r bZns/R6f3YL3U/7CBzePhq0xhfnLKcIXNtV/H0qB1SOeFzkxdCkjA8FpjW0FuUIqcENS0fnpJ0Od6 vOdJl6izL/he4796vW5w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpVma-00000009zFb-0uNE; Wed, 27 Mar 2024 16:05:44 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpVmR-00000009zAy-2DK5 for linux-riscv@bombadil.infradead.org; Wed, 27 Mar 2024 16:05:38 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:MIME-Version :References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description; bh=+4M9Lk9Z8nU8etdW0Vehxd3ZiXzPs65Q9tqt+MZAHIQ=; b=HDsrVq3Axo+rFzXr2XQ43rvZ2i 0DVMUyf+vbNDrksXuXGM+OOdf25mwPfM1eFQV1xbKCSAUuwuv20cgHGFVINASLZ7hmOvqtzT8VpGC wI6nw9HtagGy3YkZY+JLFFrpA/sd0Q9RqLnh3/FuKZLTOqz6haWH1cw0DCMISLqLSbuawkYJn2bvd F5UlOmvFpndxLoqs9fz2IxgLTvErY96e2FmNBkSa3D4B6tu45qwH9vredfOgsXaHsn05tOHz1eLxv yV18WN242CGZRrejm+YPh4TgdK02VpxyQwZqk54uSSXQtl+pU813z92UIFmt4lCOiDesANU5w/Qg9 59EAnA6Q==; Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpVmM-00000000MSu-1rj6 for linux-riscv@lists.infradead.org; Wed, 27 Mar 2024 16:05:34 +0000 Received: by mail-pl1-x62c.google.com with SMTP id d9443c01a7336-1e0bec01232so29133085ad.3 for ; Wed, 27 Mar 2024 09:05:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711555527; x=1712160327; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+4M9Lk9Z8nU8etdW0Vehxd3ZiXzPs65Q9tqt+MZAHIQ=; b=dg1RIsKuUm3RjDbfK05UgVHiRazUyBESUTazTEmNWbihuvBnnRE1ycBdZ7Ke/5DIae 7ef5Uqi/oJpcnJJnmRMsX176DqgHjeMou24WQ4XU/+d1RKus6adOje9G6qbqIO4jyWtC RLukmr8l8huWE88ZoFMXmdiPwNPvmSyL5T24etJJJ17SGdjfyvG0tb4MB0WbbsfGesDb PS5xgbEGkA3BG8rIBedJQmfpfGA+9dJvhkdsHITChMSEkUswI34j5zhy2l8TMX2GeV+8 zRzxt8Y6CoSnQ3HXfoMT7CxkGFLnfEliGcJKTJNttOENZgE2RTY1Ixj1glBuZ+0SkVxs NuyQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711555527; x=1712160327; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+4M9Lk9Z8nU8etdW0Vehxd3ZiXzPs65Q9tqt+MZAHIQ=; b=EIdgAcgLNmohQuLsNAd6aKIEDl5wLN0fuZsWB9Sr5xxaLcJor3S6pfHmTN3Nl7ICn5 69ibbly0p4iMHpnkUF0lm54MtM82JSVIhzl0mQANRmCyn9I0sriZcn/iE3VIxaynYyVU 9rPPK8y8aSdOE9P/dEf1iSO20qFK2NfGhzjWfI9d1t+AOyVolXafYBXnQrrBsWq9h8kS LVSmf00c7k7RMSL/Af33+e4yWDg5EP/mBJNi3Su+5/veHoDkzQYrFZbrvHghCx/MpPqD lPKH8LlsN9lKAL1BmEd8xFv5UNnukCGFHNGNozl54gMzJTsae/5+eal3KvurCcV9yeg7 A5cg== X-Forwarded-Encrypted: i=1; AJvYcCUua9egKPMqb4Iy+s1+0oU8kPflA2AglkzgdtGanuw0ocl5SOusrKHr/JWEzdDM/Y0LdkiDyIOYdBE4Io59eeNPU39caeuwayZ1GrDKyx+a X-Gm-Message-State: AOJu0YyjC6V6snrIo7O+otM+wSmbI5sYSsmat5ji9wipm3dyzQTxVyt5 90geFVed8Dfn4eh2L7b4R+uyVt60SVWG+aqhpmHEi1Slf26LANWD3b+h2qNSb4U= X-Google-Smtp-Source: AGHT+IHmU9bA6AvbKxQ+lqld0GtL9R2sxBrS7FKO5825OmmPZqHfmYm+9jb41eb0MCY+vR/dQnQAlw== X-Received: by 2002:a17:902:e541:b0:1e0:9122:abc4 with SMTP id n1-20020a170902e54100b001e09122abc4mr169570plf.21.1711555527635; Wed, 27 Mar 2024 09:05:27 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id bf4-20020a170902b90400b001e14807f9cesm1718226plb.125.2024.03.27.09.05.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 09:05:27 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Samuel Holland Subject: [PATCH v2 4/7] riscv: Simplify text patching loops Date: Wed, 27 Mar 2024 09:04:43 -0700 Message-ID: <20240327160520.791322-5-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240327160520.791322-1-samuel.holland@sifive.com> References: <20240327160520.791322-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240327_160530_654067_35D336CC X-CRM114-Status: GOOD ( 12.01 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org This reduces the number of variables and makes the code easier to parse. Signed-off-by: Samuel Holland Reviewed-by: Björn Töpel Reviewed-by: Conor Dooley --- Changes in v2: - Further simplify patch_insn_set()/patch_insn_write() loop conditions - Use min() instead of min_t() since both sides are unsigned long arch/riscv/kernel/patch.c | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c index 9a1bce1adf5a..0d1700d1934c 100644 --- a/arch/riscv/kernel/patch.c +++ b/arch/riscv/kernel/patch.c @@ -155,22 +155,24 @@ NOKPROBE_SYMBOL(__patch_insn_write); static int patch_insn_set(void *addr, u8 c, size_t len) { - size_t patched = 0; size_t size; - int ret = 0; + int ret; /* * __patch_insn_set() can only work on 2 pages at a time so call it in a * loop with len <= 2 * PAGE_SIZE. */ - while (patched < len && !ret) { - size = min_t(size_t, PAGE_SIZE * 2 - offset_in_page(addr + patched), len - patched); - ret = __patch_insn_set(addr + patched, c, size); - - patched += size; + while (len) { + size = min(len, PAGE_SIZE * 2 - offset_in_page(addr)); + ret = __patch_insn_set(addr, c, size); + if (ret) + return ret; + + addr += size; + len -= size; } - return ret; + return 0; } NOKPROBE_SYMBOL(patch_insn_set); @@ -190,22 +192,25 @@ NOKPROBE_SYMBOL(patch_text_set_nosync); int patch_insn_write(void *addr, const void *insn, size_t len) { - size_t patched = 0; size_t size; - int ret = 0; + int ret; /* * Copy the instructions to the destination address, two pages at a time * because __patch_insn_write() can only handle len <= 2 * PAGE_SIZE. */ - while (patched < len && !ret) { - size = min_t(size_t, PAGE_SIZE * 2 - offset_in_page(addr + patched), len - patched); - ret = __patch_insn_write(addr + patched, insn + patched, size); - - patched += size; + while (len) { + size = min(len, PAGE_SIZE * 2 - offset_in_page(addr)); + ret = __patch_insn_write(addr, insn, size); + if (ret) + return ret; + + addr += size; + insn += size; + len -= size; } - return ret; + return 0; } NOKPROBE_SYMBOL(patch_insn_write); From patchwork Wed Mar 27 16:04:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13607033 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A98DBCD1280 for ; Wed, 27 Mar 2024 16:06:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=CspQzca/+MaEIWC7SwJ1tCunEK7+fDNqICimS/xzRsI=; b=Hp4VsTAbLEksYK l9vtA3g8JvlzVWgU0/8t6c/9kHZZf2K1KUVpHPY2rL3lClmzCer/N1b7YcTonMikXwMrzU47lGWZR 9TiSGaj2Hw3PdoabaTpEc3/4Aw8zW0Yqh5WC4/yUHfewwNlgg0CPLK61K5tCH1wevWPYD8fURzlkQ lM8vAaNUHpLc06I2PRnSeXH5e+/7jsgPdZn0BUyQTFTsaBz4BGDJ+3Idw/HXQKPMbdYKykfVyWdMY UVD6903Rp6/ux4vTYEYSdyxj5K2COdcJf/fj2jlWThorZKhqJdahbYLxuQ/J/hvb8ZcCC0Jc0ADih KzvsAq1xpQKC5DcLH5MQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpVnF-00000009zbX-2isy; Wed, 27 Mar 2024 16:06:25 +0000 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpVmQ-00000009zA4-2XbB for linux-riscv@lists.infradead.org; Wed, 27 Mar 2024 16:05:45 +0000 Received: by mail-pl1-x633.google.com with SMTP id d9443c01a7336-1e0d6356ce9so25928805ad.3 for ; Wed, 27 Mar 2024 09:05:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711555529; x=1712160329; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=RSdeTCpLrbMRKKMvHtorfIir+maEw9krU8ML3vSQsXQ=; b=KEyMtn/uDLo+QcauVV8z6qAeFbkXF4mtS2LzxSw92wX2R9Ti9pjudywYapefaxTFhq pOsnz7QsGVAm92/pzwf/I3LwxsCSS/k5fcrlvhD8h3wTJBM3ht3FyYYm6uJGXMWX1LA9 gdE91JEZYo9pqpSWMNnxfqdsaevf2kAs6D2yxxCo1kUwGvHG6eT1LLd44ma2vmBrctry KMHvWCIqhyGrMTDDD6IXNxSIdQ3607lh1aFUSavIoWVqLwmu0gieZIg+LE/Fv3v+9CwY F4rVaKsCZGM4TDwvdRTFfYpiotZ4/1jeoqQwODc63VL9J8vtj9razKR35pxePQoj5kat OhWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711555529; x=1712160329; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=RSdeTCpLrbMRKKMvHtorfIir+maEw9krU8ML3vSQsXQ=; b=V5pEY31SPdrg8HQn6mNFcowP3C+jSRxF9X2bi98N36INRnnfdBgZlLO+8XD0jFoXpO JV92PkJgc4liYynvEtU8pDoaT8dxOW4/zNFxW61sR0nDxpTd3cQ4YNzLJHloZjBJNXA9 L1M/QV6pMQwfV+fpW5m21UTPL4P+1ATC/27Y0W0TjK3odiJEsH7QAiknmK2M2kkyRhvy rTsoGXYf0Zn4G1ZTQI9Ha1kPNw5aMzjzDkp3+LdQG+F1aRvzmP0uHSaOTAwk/XqoxQBt GJn3RiRldYh0YwXb2/dhLnzX9T45n2wHWxRT2jf/UHRUiu6UqwC2oddQTqkS1t6YEHmu 0vVg== X-Forwarded-Encrypted: i=1; AJvYcCUWk/X1ZuiDT6fZnGfDypazgaZ6QZ2tl5KVh1y2Maz6FtSeSsa/Sa4N5Al5elqWslYMGk3RSNcyabiOoGzrPt573G1rqzM8h7FT3dRqaFum X-Gm-Message-State: AOJu0Yw8N4sjZ6qy9zj67M+eV1bJ1NPCUjI7LHNn/kanuUWmIUv+FlGd GmMDGQYIQM8ewtqnGbRPfqhLaWdCDh/3UTAnFue75rSA8J5PsK+ccGjkPgP7K50= X-Google-Smtp-Source: AGHT+IEqRVMXpfbvhLVGnT+rNK/EL/AmWPjQNfVTk43pBb2QF8NUiJFixCdoiQv5OswSn3xtBhEfyw== X-Received: by 2002:a17:903:8cd:b0:1df:fa1a:529f with SMTP id lk13-20020a17090308cd00b001dffa1a529fmr148822plb.24.1711555529446; Wed, 27 Mar 2024 09:05:29 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id bf4-20020a170902b90400b001e14807f9cesm1718226plb.125.2024.03.27.09.05.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 09:05:28 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Samuel Holland , Daniel Borkmann , bpf@vger.kernel.org Subject: [PATCH v2 5/7] riscv: Pass patch_text() the length in bytes Date: Wed, 27 Mar 2024 09:04:44 -0700 Message-ID: <20240327160520.791322-6-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240327160520.791322-1-samuel.holland@sifive.com> References: <20240327160520.791322-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240327_090539_176514_71327441 X-CRM114-Status: GOOD ( 16.05 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org patch_text_nosync() already handles an arbitrary length of code, so this removes a superfluous loop and reduces the number of icache flushes. Reviewed-by: Björn Töpel Signed-off-by: Samuel Holland Reviewed-by: Conor Dooley --- Changes in v2: - Remove unnecessary line wrapping arch/riscv/include/asm/patch.h | 2 +- arch/riscv/kernel/patch.c | 14 +++++--------- arch/riscv/kernel/probes/kprobes.c | 18 ++++++++++-------- arch/riscv/net/bpf_jit_comp64.c | 7 ++++--- 4 files changed, 20 insertions(+), 21 deletions(-) diff --git a/arch/riscv/include/asm/patch.h b/arch/riscv/include/asm/patch.h index 9f5d6e14c405..7228e266b9a1 100644 --- a/arch/riscv/include/asm/patch.h +++ b/arch/riscv/include/asm/patch.h @@ -9,7 +9,7 @@ int patch_insn_write(void *addr, const void *insn, size_t len); int patch_text_nosync(void *addr, const void *insns, size_t len); int patch_text_set_nosync(void *addr, u8 c, size_t len); -int patch_text(void *addr, u32 *insns, int ninsns); +int patch_text(void *addr, u32 *insns, size_t len); extern int riscv_patch_in_stop_machine; diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c index 0d1700d1934c..243e1573410b 100644 --- a/arch/riscv/kernel/patch.c +++ b/arch/riscv/kernel/patch.c @@ -19,7 +19,7 @@ struct patch_insn { void *addr; u32 *insns; - int ninsns; + size_t len; atomic_t cpu_count; }; @@ -231,14 +231,10 @@ NOKPROBE_SYMBOL(patch_text_nosync); static int patch_text_cb(void *data) { struct patch_insn *patch = data; - unsigned long len; - int i, ret = 0; + int ret = 0; if (atomic_inc_return(&patch->cpu_count) == num_online_cpus()) { - for (i = 0; ret == 0 && i < patch->ninsns; i++) { - len = GET_INSN_LENGTH(patch->insns[i]); - ret = patch_insn_write(patch->addr + i * len, &patch->insns[i], len); - } + ret = patch_insn_write(patch->addr, patch->insns, patch->len); /* * Make sure the patching store is effective *before* we * increment the counter which releases all waiting CPUs @@ -258,13 +254,13 @@ static int patch_text_cb(void *data) } NOKPROBE_SYMBOL(patch_text_cb); -int patch_text(void *addr, u32 *insns, int ninsns) +int patch_text(void *addr, u32 *insns, size_t len) { int ret; struct patch_insn patch = { .addr = addr, .insns = insns, - .ninsns = ninsns, + .len = len, .cpu_count = ATOMIC_INIT(0), }; diff --git a/arch/riscv/kernel/probes/kprobes.c b/arch/riscv/kernel/probes/kprobes.c index fecbbcf40ac3..f3cbc3ec9e6a 100644 --- a/arch/riscv/kernel/probes/kprobes.c +++ b/arch/riscv/kernel/probes/kprobes.c @@ -23,13 +23,13 @@ post_kprobe_handler(struct kprobe *, struct kprobe_ctlblk *, struct pt_regs *); static void __kprobes arch_prepare_ss_slot(struct kprobe *p) { + size_t len = GET_INSN_LENGTH(p->opcode); u32 insn = __BUG_INSN_32; - unsigned long offset = GET_INSN_LENGTH(p->opcode); - p->ainsn.api.restore = (unsigned long)p->addr + offset; + p->ainsn.api.restore = (unsigned long)p->addr + len; - patch_text_nosync(p->ainsn.api.insn, &p->opcode, 1); - patch_text_nosync(p->ainsn.api.insn + offset, &insn, 1); + patch_text_nosync(p->ainsn.api.insn, &p->opcode, len); + patch_text_nosync(p->ainsn.api.insn + len, &insn, GET_INSN_LENGTH(insn)); } static void __kprobes arch_prepare_simulate(struct kprobe *p) @@ -116,16 +116,18 @@ void *alloc_insn_page(void) /* install breakpoint in text */ void __kprobes arch_arm_kprobe(struct kprobe *p) { - u32 insn = (p->opcode & __INSN_LENGTH_MASK) == __INSN_LENGTH_32 ? - __BUG_INSN_32 : __BUG_INSN_16; + size_t len = GET_INSN_LENGTH(p->opcode); + u32 insn = len == 4 ? __BUG_INSN_32 : __BUG_INSN_16; - patch_text(p->addr, &insn, 1); + patch_text(p->addr, &insn, len); } /* remove breakpoint from text */ void __kprobes arch_disarm_kprobe(struct kprobe *p) { - patch_text(p->addr, &p->opcode, 1); + size_t len = GET_INSN_LENGTH(p->opcode); + + patch_text(p->addr, &p->opcode, len); } void __kprobes arch_remove_kprobe(struct kprobe *p) diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp64.c index aac190085472..6ed4035a8136 100644 --- a/arch/riscv/net/bpf_jit_comp64.c +++ b/arch/riscv/net/bpf_jit_comp64.c @@ -15,6 +15,7 @@ #include "bpf_jit.h" #define RV_FENTRY_NINSNS 2 +#define RV_FENTRY_NBYTES (RV_FENTRY_NINSNS * 4) #define RV_REG_TCC RV_REG_A6 #define RV_REG_TCC_SAVED RV_REG_S6 /* Store A6 in S6 if program do calls */ @@ -663,7 +664,7 @@ int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type poke_type, if (ret) return ret; - if (memcmp(ip, old_insns, RV_FENTRY_NINSNS * 4)) + if (memcmp(ip, old_insns, RV_FENTRY_NBYTES)) return -EFAULT; ret = gen_jump_or_nops(new_addr, ip, new_insns, is_call); @@ -672,8 +673,8 @@ int bpf_arch_text_poke(void *ip, enum bpf_text_poke_type poke_type, cpus_read_lock(); mutex_lock(&text_mutex); - if (memcmp(ip, new_insns, RV_FENTRY_NINSNS * 4)) - ret = patch_text(ip, new_insns, RV_FENTRY_NINSNS); + if (memcmp(ip, new_insns, RV_FENTRY_NBYTES)) + ret = patch_text(ip, new_insns, RV_FENTRY_NBYTES); mutex_unlock(&text_mutex); cpus_read_unlock(); From patchwork Wed Mar 27 16:04:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13607032 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 92835C47DD9 for ; Wed, 27 Mar 2024 16:06:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9B8FeQZZ2KO5IYoSDJZrSZw+wQqGx+abyKZCqOu+4HE=; b=AaykjFT1kJ3w12 EsaRUh1c09oSANKJRTjRQFdnHOzkXzG4ruyxEdcyzcYBhNIeNCPjVs848kyz2/lV5MLKis1MTGlEy jY8PwZEX2W7BUcSgfCVTFQW5zkDZhIka0goHSlKMYSVTrcvCHL0uWCGwkvjEMyzc/Qb2Xotaeqe82 FxcZP+EX/ZaH2FpzHXBBjsddcCjIjLj58o4KOHFW8SsXgcHwrknqxrDMXftF2NbwTHdcriHey0OQ2 05/sI9+zEfJjfPI2c1g3/MeTTpAKo7zngSrWOKnz05wSQmixdNK4odEL9AgnOwZPci+C3uriHPccF S2vR9ALwlL13LbGSc8Qg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpVnC-00000009zYh-05uw; Wed, 27 Mar 2024 16:06:22 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpVmQ-00000009zAS-2XRj for linux-riscv@lists.infradead.org; Wed, 27 Mar 2024 16:05:43 +0000 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-6e6afb754fcso13475b3a.3 for ; Wed, 27 Mar 2024 09:05:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711555530; x=1712160330; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=9Kov3PdEwmxTDPnCfMLEhtVN8PjsiHGUhl+QZHrnJpM=; b=Ua7yEZjeA2Nxk1Pv35Vqhpy56/QP1ozgQqy+wVLgJI3jE6/1NOM3Cb8aKKb8gmg6Vc 0kzDalsajoHPymX9HEg5CydJ9WYnS0S8j/Cdp+S1vidrZBUx+sdseWI4Ax1QwIesZBNj FxKqwJhTJIYqaBlH2OCYeFyAws53nZooPexQB2sEdgCZRpktDyleVId/7HDOEuSP1xqE T0jsVIzdfjX0WAxvpZ2lmTuGG/coWABOTe0jqpPvmxucTSrhcaoL63YRcYiBDl8KjclH 6Jsi+ncqiYWxh7VO4PRrT9T9dZQhDG2ohhxXD3qc3EhFybXC9quSZyzuW9dAQRyho2ZE 46zQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711555530; x=1712160330; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=9Kov3PdEwmxTDPnCfMLEhtVN8PjsiHGUhl+QZHrnJpM=; b=olkvmfCJ9FH/jJMcUNhU6gBocuyfcXANnI/kgNmv3L7ah14THyOSuFiKmpbwJlqIkY 8SkolHprQbNZDmqSPaXgflA4ac+OtTjigUjYTexfrZC7+fDoINGVjk1pqbM3/Bx8pKRq EnJyyzE6GhQFJqGp2Yov8SnqdR3j8NxI3FfXzM+1IyeZyL0hYSj/gG5xaYBB60cvZyPI uGR7Xz7pgliMPFli/WLG7rkNAbkMaSO4WpioXjdr9n6DzGE7f5WgjYowpdpaqvLs1mNt jmy3bUJaQqf4PQnuF1daLwY4HatU6LLxve9jxq9+UfrKIL2jnwgyv8eiUB81mIF4iUUg pFQA== X-Forwarded-Encrypted: i=1; AJvYcCVXeipXplDGh1IUovz02L6kb4844mzMhGV82rWzfgVV/vEhZEM+4NSz1Fk+B+N6vh6jQ7U+tVBUEJGX937b+UjFQRDM9jyc0UNZgHPp/y8F X-Gm-Message-State: AOJu0YwQf8oin0ljG35+uR9u2ltcgTxM0gc87XcDCCJ9vzeSBL9Ybxci ky5axPoXp/FzFDL/pwVDb+DoyV2o84cz3oSKJFqLdR5iPxbJHeX0TLYVgPUqiqI= X-Google-Smtp-Source: AGHT+IE/3RrmK8SccBkrnois/GdB5+EKW8GlWLws9exiXDtK106qyPALy+gzO7adzUXL5RZSyOOPLw== X-Received: by 2002:a17:903:2b04:b0:1dc:ce6e:bf06 with SMTP id mc4-20020a1709032b0400b001dcce6ebf06mr184008plb.0.1711555530628; Wed, 27 Mar 2024 09:05:30 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id bf4-20020a170902b90400b001e14807f9cesm1718226plb.125.2024.03.27.09.05.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 09:05:30 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Samuel Holland Subject: [PATCH v2 6/7] riscv: Use offset_in_page() in text patching functions Date: Wed, 27 Mar 2024 09:04:45 -0700 Message-ID: <20240327160520.791322-7-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240327160520.791322-1-samuel.holland@sifive.com> References: <20240327160520.791322-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240327_090539_162619_BDF01066 X-CRM114-Status: GOOD ( 11.29 ) X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org This is a bit easier to parse than the equivalent bit manipulation. Reviewed-by: Björn Töpel Signed-off-by: Samuel Holland Reviewed-by: Conor Dooley --- (no changes since v1) arch/riscv/kernel/patch.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c index 243e1573410b..cfcb9926e722 100644 --- a/arch/riscv/kernel/patch.c +++ b/arch/riscv/kernel/patch.c @@ -54,7 +54,7 @@ static __always_inline void *patch_map(void *addr, const unsigned int fixmap) BUG_ON(!page); return (void *)set_fixmap_offset(fixmap, page_to_phys(page) + - (uintaddr & ~PAGE_MASK)); + offset_in_page(addr)); } static void patch_unmap(int fixmap) @@ -65,8 +65,8 @@ NOKPROBE_SYMBOL(patch_unmap); static int __patch_insn_set(void *addr, u8 c, size_t len) { + bool across_pages = (offset_in_page(addr) + len) > PAGE_SIZE; void *waddr = addr; - bool across_pages = (((uintptr_t)addr & ~PAGE_MASK) + len) > PAGE_SIZE; /* * Only two pages can be mapped at a time for writing. @@ -98,8 +98,8 @@ NOKPROBE_SYMBOL(__patch_insn_set); static int __patch_insn_write(void *addr, const void *insn, size_t len) { + bool across_pages = (offset_in_page(addr) + len) > PAGE_SIZE; void *waddr = addr; - bool across_pages = (((uintptr_t) addr & ~PAGE_MASK) + len) > PAGE_SIZE; int ret; /* From patchwork Wed Mar 27 16:04:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 13607031 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C31D1C54E67 for ; Wed, 27 Mar 2024 16:06:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=7Yqfw7yxNhtnPH6dNEBn+2pMGImDGM4fpxiOZ2nM1Og=; b=ZFzW9fTklcwxrU RNavPCCZMalShfX7omoQ34CqFI4usX7mpWiCpvVBrrYDRwd5Nfvgep7LZ8skGCNo4frGf1YhHVlir YSbBYKzWIKJUYfmfWBQ0h0UcvkAlXmqYCxRzHeWNKWqVdlwPO8rLi+zj64HIEeQctc6hui1TOlazF tuRW96XapOpLk5J4queTsY3Upvx89JBOiFFhhhO+edI9JwzfI5sgMxR2fep2jdFTApKTN/hK0eYpb zKxFKmwZeG5Mw5hKcaCmb+35Y3Bbb3waTsF191yQpEKhink2YzYSkAb1IFgBfLhaZxNUCYahT/FG2 TX86uj4vTthWl8geEnNQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpVml-00000009zMl-1gfZ; Wed, 27 Mar 2024 16:06:06 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpVmV-00000009zCc-3b4S for linux-riscv@bombadil.infradead.org; Wed, 27 Mar 2024 16:05:41 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Transfer-Encoding:Content-Type :MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From: Sender:Reply-To:Content-ID:Content-Description; bh=JTir40frdJeiV9LGmiUfO8UY8kCkwqA6MXq/cDxcl6E=; b=pzOnty5SSWcXWQYvVjm49bYLmZ dsqCAvS+G8Ng/Yx9ML3g7WpJgYMXAM/Bv9GSKFV8Ej5PLkL2vUHOiDJ9ZNtI3jg8RviUk5HAM2yVj C92uOq17DIh5M6Z02+e4EB1FovhXAIKNIn/YFS6RSocS2u/r9UbSx9WV+foCR0fjDK1MWXN7Oeel8 RftDNSOa4NU2i0aIBz6GpENAc7/60sXz10sNACxmeMSs3x6Dysu7eGv27AJp4h5EOu3gDbWL3YWJm aRggbNA6MXcQeLxEnadvAsmYOG0WQdfMAwoipczgagWtGsvYWlReavD6nLVQ2gatMaaqKaPZbGJci 5RVDcPsA==; Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]) by desiato.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rpVmQ-00000000MTb-3H94 for linux-riscv@lists.infradead.org; Wed, 27 Mar 2024 16:05:38 +0000 Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1dee27acf7aso49120805ad.2 for ; Wed, 27 Mar 2024 09:05:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711555532; x=1712160332; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=JTir40frdJeiV9LGmiUfO8UY8kCkwqA6MXq/cDxcl6E=; b=ZRZL4Hzm51zVNPp1okL+2TL3ReUWukhjrDglt4OkYTuVmBXYEVvOLzguY0UzAk0++E kcvDfSll2EaRdDsKv88DXbHzKATbMkSoPMXJLQWuGfeCcmATrCzN+d6xQSFiC9k5/Q9E 9yn324I34gBOB5ZtJQKSq5XZTT6nLyW+U++dHTKsxWxe3G4JqWeEj8tsgQmqCNCl1hv2 DZPr5ZMcE86SqGv05csxTr0dOdZ4GCLAl8Jy42xoyrLMjV3ZI9AZsWT2QhPGdRdBzTyW R4RidsRz291zIEqaSjM/L43+kZZmZaYGQ0k7uWazQnCt/ZzdVJxZ5J8t4AIhcuOfAzUZ 3+YQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711555532; x=1712160332; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=JTir40frdJeiV9LGmiUfO8UY8kCkwqA6MXq/cDxcl6E=; b=sr0QyTkbUSWMWjIjCmWMRjUArNh46zmYWeZ83TZKcjs3TcHSp/N8cKpEQTkOiKiYI9 5bbJg9cR3SN7Ddx0fW8HuCC2o+0st0RlSpdStf1HTINArzhju1NMMabLCK8zcRP0rQ0x 8TbwPErGECPi4/RrUmcEoW8SB3EQ691QYIi35akKEWSuVkQLDXIf8VSRrajucscfDHyP 4PSuFRwOwz7h1KBYWV+cwCLatdt1EbjIrZm/5jrOG5jBPIOmyOoueIp7VzHVUla1W46D Wm2OTpcO8Mm11HFGA4EJJVq7BZlml3IOhVeHd0g/hzCP11gDo9okw3/H9C1KOsmZbDuK /cFA== X-Forwarded-Encrypted: i=1; AJvYcCWAmaEHgyj7rGjlO7fZG8zbT9DEZPTmGvEM+CMA/SKr3OUN+5YTK9vwmrqtQtDeTHoPxjObWv1XJIYT6OYslw3DngZ93IZGDuDBKRLy9tKw X-Gm-Message-State: AOJu0YwRU93PZ3kdNX7eANpZT7y7OLbV4uRiFUl9ULA9N0m1LwjB7tNJ FQqIU3Dxa6yGqNPeLH6DEo7O/AyHJBXgRUOewsKFWw5D6XyGxRVwFlOjilqBQAs= X-Google-Smtp-Source: AGHT+IFccFF2oFHmlsLnwpVDYsHbnzwo+hSZtspn9JVTNBPSJFrTpSFKN5a3C18e5F8g5GCAcVJVZQ== X-Received: by 2002:a17:902:cecb:b0:1e0:b1af:9b with SMTP id d11-20020a170902cecb00b001e0b1af009bmr86571plg.43.1711555531737; Wed, 27 Mar 2024 09:05:31 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id bf4-20020a170902b90400b001e14807f9cesm1718226plb.125.2024.03.27.09.05.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Mar 2024 09:05:31 -0700 (PDT) From: Samuel Holland To: Palmer Dabbelt Cc: =?utf-8?b?QmrDtnJuIFTDtnBlbA==?= , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Samuel Holland Subject: [PATCH v2 7/7] riscv: Remove extra variable in patch_text_nosync() Date: Wed, 27 Mar 2024 09:04:46 -0700 Message-ID: <20240327160520.791322-8-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.1 In-Reply-To: <20240327160520.791322-1-samuel.holland@sifive.com> References: <20240327160520.791322-1-samuel.holland@sifive.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240327_160535_048669_E8643D9F X-CRM114-Status: UNSURE ( 9.05 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-riscv@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-riscv" Errors-To: linux-riscv-bounces+linux-riscv=archiver.kernel.org@lists.infradead.org This cast is superfluous, and is incorrect anyway if compressed instructions may be present. Reviewed-by: Björn Töpel Signed-off-by: Samuel Holland Reviewed-by: Conor Dooley --- (no changes since v1) arch/riscv/kernel/patch.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c index cfcb9926e722..9b8d633f6536 100644 --- a/arch/riscv/kernel/patch.c +++ b/arch/riscv/kernel/patch.c @@ -178,13 +178,11 @@ NOKPROBE_SYMBOL(patch_insn_set); int patch_text_set_nosync(void *addr, u8 c, size_t len) { - u32 *tp = addr; int ret; - ret = patch_insn_set(tp, c, len); - + ret = patch_insn_set(addr, c, len); if (!ret) - flush_icache_range((uintptr_t)tp, (uintptr_t)tp + len); + flush_icache_range((uintptr_t)addr, (uintptr_t)addr + len); return ret; } @@ -216,13 +214,11 @@ NOKPROBE_SYMBOL(patch_insn_write); int patch_text_nosync(void *addr, const void *insns, size_t len) { - u32 *tp = addr; int ret; - ret = patch_insn_write(tp, insns, len); - + ret = patch_insn_write(addr, insns, len); if (!ret) - flush_icache_range((uintptr_t) tp, (uintptr_t) tp + len); + flush_icache_range((uintptr_t)addr, (uintptr_t)addr + len); return ret; }