From nobody Sun Feb 8 22:21:39 2026 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id ADA3312D762 for ; Wed, 27 Mar 2024 16:05:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711555526; cv=none; b=lB0yq3CVPVXkuXFlCEiinO1TTCfKpSArFJIy6lKLGwI4H8jWjB7pCyUre2mw+gSJX9fWB+F52qHb+3jYh75UcOjAnnx69GvpzT2Vn6ikaU3F99y9KxYP7K0qR9cRZmrYKSkoEBpS3S48vk20eZelsh+Iva3bbScuLXVYEvI49yw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711555526; c=relaxed/simple; bh=c8cFzSPVDl3tMmEcmOn7avM7k4+aPkxahkvikC132Q8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=o0Ciqo2SPzU1u16qhVIqbKZT3jCrTBbKHYaJKnSRM6rrka03CShEyXaen3X0I3O0UAHgbdCJwTxatMw3oqcLObTJqhC/SmUeDlbIP8Po8SwoFn1SUQK76P16ngl9xjfXBc8Bx2p/5nXLsqYDIjJ6pQJ3NgYy5sGOc4Cq0uYZxQc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=SlnXUMS7; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="SlnXUMS7" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1e0f3052145so19390245ad.2 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=vger.kernel.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=SlnXUMS7S82qLJrmBGLMzRMX/hG3CBkPZbPQmZ9t7pvpCSUWqLNfKfxWVA9DITdGnR bkCDxhmeqzvMzhHFHGfYedQPpA6YgVd8t+I9rp/DC35tRR7PzvDec2t4dp1c1xeTZzGI hOGUcBaEA/Fn/YtjHHl8HpI6MwYLRJEnyE45fhvbQ1+qFYTGt43tdqOfgkB/BfBnHw1n 7tbEV74PJvWCzVfWUugmiqipIR61BA7IluSTQ7/m07yN1YJlFlySsuRpXseWsTvbzkJ4 ewb1ZkD75Bn+s+XGvG3uvADAhUC+kUCSFOybI8kdOQacB2haw7OJtouY6OJwWLK+o6S/ 3E6Q== 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=IwgcrT/EnQ8eQzEOmrwwllwc8XTPVnbLQ7FbDWKx/s8IGC1eAm4Y3CjjqMEljoilSZ W5960Y/6VMDr0xQIFXz71Iv4z8B0YOUxctb5dpuWO4mrmY5l7DonO16Ev9HX+3aweKbR 4bFupJYzwElj1WJhjMc4BRGpnfMhEUSIZ0piMviITMSBm3H5rRAUoiWp+ctpANnAdR4G BS9EURyB4RJkYZA9J71tDI9r6Uf1IUJ4thfr240ie4c9o+CByZ6gK5HGttlkGUpknhVE nkqfpgtQ+nCaRBpAZdEK/E199laXiGakViUbtYXDYzS7BMUmZwChod7lN+R7ljVyt9rz Am8A== X-Forwarded-Encrypted: i=1; AJvYcCUGnonJWLSz8yXld4rMv1LUvXgCFBopUnMh6fjEWFUwSb7OFTUiXCkaO7iyOUVcpH9Rnw4+qBMGRCBduodkvdp6cSg8VK0QrN5tIwqK X-Gm-Message-State: AOJu0YyXxNsVSSf6J7oHQ+zsr5IHwljxjWGu/q96Q1yBsb/CuBEhpVuv tnHHPaPKAXm18IWkffOGtOGUWG/n7nvEZ0xXpbKHqPk9c9nFiyQkDDs9r1bnYsgk8V9GF/Z6TFn u 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?q?Bj=C3=B6rn=20T=C3=B6pel?= , 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=C3=B6rn T=C3=B6pel 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/j= ump_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 =20 +#define HAVE_JUMP_LABEL_BATCH + #define JUMP_LABEL_NOP_SIZE 4 =20 static __always_inline bool arch_static_branch(struct static_key * const k= ey, 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 =20 #define RISCV_INSN_NOP 0x00000013U #define RISCV_INSN_JAL 0x0000006fU =20 -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 =3D (void *)jump_entry_code(entry); u32 insn; @@ -24,7 +25,7 @@ void arch_jump_label_transform(struct jump_entry *entry, long offset =3D jump_entry_target(entry) - jump_entry_code(entry); =20 if (WARN_ON(offset & 1 || offset < -524288 || offset >=3D 524288)) - return; + return true; =20 insn =3D RISCV_INSN_JAL | (((u32)offset & GENMASK(19, 12)) << (12 - 12)) | @@ -36,6 +37,13 @@ void arch_jump_label_transform(struct jump_entry *entry, } =20 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(); } --=20 2.43.1 From nobody Sun Feb 8 22:21:39 2026 Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1BC22131BBE for ; Wed, 27 Mar 2024 16:05:26 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711555528; cv=none; b=Wh3vuoo7SWyqvv9HGcye9ZufThwnx6gS0vRu995xkI6alE92Mf+lxye24jzXabm9lXvRkpZb//+jVE4DSSnkPKK572hXci7igG4/DuUi3Gzp8BMUfcNGOnpVb8V8KBCR/RXxCVTXQ62Cf6zxqKGVzmgjgsxKkEzrQ8zWa/AjLKA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711555528; c=relaxed/simple; bh=nUhuCGNSiNI8gPbLKFAtjEYWXvNX2ZVdrT7VP/q7XhE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=P+2QKxEa0/VOcbU2Oy+j8fhS3Y/A08mGxOcrTXOiZHLjQPBQh1TrRXZbuky3u7KzgYE2J7ATYcuWSnxDH+7FqZOH6GkW0A3DgHvYDus/2yq7tioHitndYwHc/Bj2RypBUrMV2hbXyJq2AxVFXcrww5LmCnPI72oX9HFOkpi7HP4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=Fr9t+Afm; arc=none smtp.client-ip=209.85.214.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="Fr9t+Afm" Received: by mail-pl1-f182.google.com with SMTP id d9443c01a7336-1e0bfc42783so28555ad.0 for ; Wed, 27 Mar 2024 09:05:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711555526; x=1712160326; darn=vger.kernel.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=Fr9t+AfmlG6Q/cPuLHlr/H6B5R/g3BFftQxabip1LAY0W4+cYdyQo4lbTNlMFeXbE+ fKQnctiDya+iqeWcfnjxf3pI2X9PFPJzf0YUhvmRJxOOyrMp3DKHRqPVMXb+z3TgzyQF EDkY8MpA1qpDUZ1EMmx6tNMMIwxSsoqgkDtHYEHRSmBYSz0yxIEGO8WNduUyWEPNBWgs FFRTzFhF6No7WLnebq7zLmeBLxUUQOAitfMZCoWAKQCxRQPgwqDm+ndlrHGGv1nqgXT6 bB7CSg+zPVcwG95hdfOmMTnsrxSgxSFHIW6bHwcCj6dW18sUdFC3kRayCnUhTdT2KV0M y7Gw== 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=DG3/V/oUxjd3+GC0nmn9o5hjYga3lIRO+pjKVmfUcKFA3VP/EZ2KSDKLoDNqLw+5WV WFk9sh90FwLfwhr8Zp9UkeugOHOLEUvpfA5B5wF5QtGiykNMPOvy57K5dYEiN0lLq1sk 3lTcc0QrqVSxNObrtvCp6cFgRvwU36abZyd62X1P2xk41jRtrbKt2lU0Nk255+++Z/8v lCx4jGjEgr5IjEN135hN2Qeg9LsqH7+qCGuoGsgwBGYv0gdhLHWRP2V5MhBEZzeUNB6S m58XYSIOvlCFXq3rDHTKbtgvK1ovP90w4Y9MMRCW6LOtWIxj3Brg65GKfYJ3mQ3oqK3N 1iUw== X-Forwarded-Encrypted: i=1; AJvYcCVzowEZjEMgE5noTKp86puT/1QF07mh4+r1dcZrRNukHRVQ6W39jqt9DRr0mIB0xiJ8qsJztoOYwR0prlanWJxMCrIqUQqvHhHKv0MY X-Gm-Message-State: AOJu0Yy0A5MB63TdnYX6/e/yU71dW+BwoB6TI9WYJFe/gIxotXEqSCl8 RRE6x0FNNPpsqIGH5zVJdjIWE7cIQm5j5QAkVk1ciKBPLpHbKhzcG2O51x58SvA= 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?q?Bj=C3=B6rn=20T=C3=B6pel?= , 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable The idiomatic way to write "jal zero" is "j". Reviewed-by: Bj=C3=B6rn T=C3=B6pel 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/j= ump_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(struc= t 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" --=20 2.43.1 From nobody Sun Feb 8 22:21:39 2026 Received: from mail-pl1-f181.google.com (mail-pl1-f181.google.com [209.85.214.181]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 44DFA131BC8 for ; Wed, 27 Mar 2024 16:05:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.181 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711555528; cv=none; b=bct0kPLXuEPW+iXZo+yAUXQOnqTuAlzgj9vFtHP/yRIUHjroJgUk3NS0dpOJqCDMEp0hk0JJDgUF1w7dTlbVgQXvW1UhxiP7AjwBlJ8NlrJ2k+hQ4yX+wwXy1RQQMAjt1dYjndMawHpJWIhzjIEuSQFYJky5hQ57jJcVewOqGHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711555528; c=relaxed/simple; bh=kMyE2qfY2RjUoUPj35JPV4OFISD0zpAHsEoL+e/lyNg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=hzkeg7M9KjuFRelDE5BevpmvZLdLLdWHQKXom3O6SJMbFLmjVAxhGgyPg85Nw1yovfqshp2cZS+GmwLy/qmvKoraoFaeacJAk/LO9VoS9YIL5mr0J1UeaNVFvoPJQnpBmebAP2j4bZW/tSj8+SiDytICybjdMh/2Xb1szWGieR8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=Bl9KrRRE; arc=none smtp.client-ip=209.85.214.181 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="Bl9KrRRE" Received: by mail-pl1-f181.google.com with SMTP id d9443c01a7336-1dddbe47ac1so7327845ad.1 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=vger.kernel.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=Bl9KrRREn8UPdOIYObq3a3vzzg1bW5T5GLanhacs/4bcFsP4dN3/Tzst0UdtnMC8sA bQm7bf+F323PDBdjAl0QPyr9iYO7X4tHIx5qQgGB40FeAna8OGeKuU5ZfZsjqFEuQrn8 qm2taHbhuLuyo4Kg8Uc2TPSBCvdokWfgMdFmPtUVk7zm/cAhCNP+ci26XWoyEP5kZ1CB 8fDaRFyH1M1SSegzIVTSgpk2V0FiQr0nyPhkpLU2CLA5iaVlG1m08R21FGp4yKfUfKDU ne4pIPWDZxtfE8iiV48FopT8M+a0f3UqtHCIFEJokPV1vjumrofTUCBDVzzF0MHJz/9t xkjw== 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=DMGLWzLZlG9NKgx95SnVXwnMet5qpiq5dIOO0+IPRrTxHGto/q1XYCoxtV64SkN9Dv 94nf8j2MURA2KXXgnkbNM9ZJI9p8H6dpJhYrCG38jzGDYuNIEpBjJqtDqDqVY6LemTBb rnxmKunRnCxxkOB5MSDDTZ3mOUfWDWRprfOcR/imJzevKXo9JexIxukaEky3Rpxxum+0 utcBnHMo8C91eKtqJW95CqtAJzsRGEoDMCNb3WQMyt1vAiC3MXpxRXd9zuzsHx+vZ4Dd 94TLF+o3UpsGkRC3eh/+Lqe/S5cZicREoaHHouLBtamuJbyyNmdAxpG86n4A4aP8fFTz 8rHQ== X-Forwarded-Encrypted: i=1; AJvYcCX4aVFeuQwdc5CqGvKlkjw1HyMXUdY/u/BQJJYwhZ5wnk9Eg081hnmGbLuUjBJXSTVh23vc1Krl9znVeEg/EaoNi/c7Ufhdy0k8/CEJ X-Gm-Message-State: AOJu0YyqzzqQL3GlWN3G8zhQ+y8wG4Moz3IAOE9tZgqtrKUlqRWdBHQT UUHUPPSoMa5lbEmhSzHODj4znXxjYUZRZr60DpXF+nY24FCVR23V47dFv5f0UdM= 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?q?Bj=C3=B6rn=20T=C3=B6pel?= , 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=C3=B6rn T=C3=B6pel 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) =20 p->ainsn.api.restore =3D (unsigned long)p->addr + offset; =20 - 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); } =20 static void __kprobes arch_prepare_simulate(struct kprobe *p) --=20 2.43.1 From nobody Sun Feb 8 22:21:39 2026 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 471C4131E27 for ; Wed, 27 Mar 2024 16:05:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711555529; cv=none; b=j6AfsrC3QfMi58btga7HEk6Whz8jKfsXbcJ8cRaADamzuiQpQ0IjL8e9AFy4cOVl5toeWDVKSBkEkgSKpz218+8QUOmYmrdhVlWWo6mpYVQ+2Dj9dvV2unwuAi3B2iqR5+/C19EVDgXtYzRAuBqOcsjypmkYKlrktE5KspToNBM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711555529; c=relaxed/simple; bh=r89XNv4WfgUD7lamaOlWbD2n2mjunEetZGP7bb3T1KU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=BpNHGJpTQAcP2k+pequdC3AsFtzIFhQ2X2UFPuSdOLsJAFguICXAFIs5/2jLSEPuIoZEo2s0B+pPj7jriCe6k67zL2omtAG7J360qYBGkH5IGGyX+WvCylS1NBjiFTlY4roADhKKGypz0c3fI1vwMZE2cuwPsKhH4ezl2nneDbI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=IwIiEzgn; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="IwIiEzgn" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1def59b537cso46637045ad.2 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=1711555527; x=1712160327; darn=vger.kernel.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=IwIiEzgnc6qnAAt5G7fRO88YvBd1Un4Wsm0oxdxPSwsbNSQVrKbS3RH9vprTsVi7X1 0IaxRHqWciemuna7fhWh29cMmt2EKYaiU6crZ8C/oEcBtakWk7FyGFBOWlHTwflfX4/W 4AFJaRcvHUIzlq5VK1uANZ4jXuqJKgxPgvwpRrEZN5OxMnflEMDCZOl0emAj/KCJdrU6 024bE31naaByDUDJTc67w/qqD1tFcKz0SRqDCTpwoBwVfTyAWGcPMgTY5L0HsoHcoCbt qwqAXMIYIjzjdy2tWvDs0NxdjOVzgz4bwCh2Q+gujnZR+fBwWfo0Vccj9faRwefKmldG 0uag== 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=XzWwzNdP1Tfjaqq7jHZ96p7c0Eez2jjQrYyimmHsIeV4Rvj+2XBrJgLfqXO+DpVOKK u9IiSjKOpu2xYKSvwGBBwycr/JGtUpH7At24w36eWGcBIiHJGk42kE7jNANsX+UWo3dw iUGcmdmLCx1EjgXnN9CWpQxOrb41/AoaUomBHhzcUXJzr8GV0b2jkaUGRGveE6AmuN19 EjsVi0smxTjhF0qwG08Q2Q3zH24y6QuBxvxiHxRS/iv4X1hlmbIvrLSklv5PWd1Y6B8c P0Ab5V9w6WkgVPJNjP+6GcBSaIEmZx+kb+AuyAaNhQ+vr804RysPU0AqrVzGGD1tvUXn Xv3Q== X-Forwarded-Encrypted: i=1; AJvYcCUrxgTvHOSOn9YYqUJoCiP+vsHvN/1+IghmnNa3oqA1gKbC/nhvAYuwarlOzsDJeQbv6RWA48xvAGwfFC0o0Ww6i+RvWjvjHVTSE4+T X-Gm-Message-State: AOJu0YywK7hXCc8v9VlBXLIpdZbUD1ulFp2ibaFRikDZKYnw6wihPp9i H+wAt7MEDaYeBYpsE8QYATw5qIdfvXfPlFzPOBk7ji99g/i47++i02mlDkRaQ4O6lW1Lr9UHbaD R 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?q?Bj=C3=B6rn=20T=C3=B6pel?= , 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" This reduces the number of variables and makes the code easier to parse. Signed-off-by: Samuel Holland Reviewed-by: Bj=C3=B6rn T=C3=B6pel 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); =20 static int patch_insn_set(void *addr, u8 c, size_t len) { - size_t patched =3D 0; size_t size; - int ret =3D 0; + int ret; =20 /* * __patch_insn_set() can only work on 2 pages at a time so call it in a * loop with len <=3D 2 * PAGE_SIZE. */ - while (patched < len && !ret) { - size =3D min_t(size_t, PAGE_SIZE * 2 - offset_in_page(addr + patched), l= en - patched); - ret =3D __patch_insn_set(addr + patched, c, size); - - patched +=3D size; + while (len) { + size =3D min(len, PAGE_SIZE * 2 - offset_in_page(addr)); + ret =3D __patch_insn_set(addr, c, size); + if (ret) + return ret; + + addr +=3D size; + len -=3D size; } =20 - return ret; + return 0; } NOKPROBE_SYMBOL(patch_insn_set); =20 @@ -190,22 +192,25 @@ NOKPROBE_SYMBOL(patch_text_set_nosync); =20 int patch_insn_write(void *addr, const void *insn, size_t len) { - size_t patched =3D 0; size_t size; - int ret =3D 0; + int ret; =20 /* * Copy the instructions to the destination address, two pages at a time * because __patch_insn_write() can only handle len <=3D 2 * PAGE_SIZE. */ - while (patched < len && !ret) { - size =3D min_t(size_t, PAGE_SIZE * 2 - offset_in_page(addr + patched), l= en - patched); - ret =3D __patch_insn_write(addr + patched, insn + patched, size); - - patched +=3D size; + while (len) { + size =3D min(len, PAGE_SIZE * 2 - offset_in_page(addr)); + ret =3D __patch_insn_write(addr, insn, size); + if (ret) + return ret; + + addr +=3D size; + insn +=3D size; + len -=3D size; } =20 - return ret; + return 0; } NOKPROBE_SYMBOL(patch_insn_write); =20 --=20 2.43.1 From nobody Sun Feb 8 22:21:39 2026 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 046431350C6 for ; Wed, 27 Mar 2024 16:05:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.180 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711555531; cv=none; b=QcgXalp8YkyooE8v+PFK6XIqpDAlWSqBPYeKb7vCAN2kHAc4B/kU2HF0yKEmJNXwPUbNUamWjZFMZZSjUiyg3b6+O94Plh1SvTo0zd4ftEAji4nbiQhlh4EHO3o35uOfIGvv3X7bS5bVE3TbtSpjUoM7HayQslbVs7uXhf0Ti8w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711555531; c=relaxed/simple; bh=ol909hSea5gZlRMw9dyO0W3BdlyVbedYBdR8GBFMpq4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=oTK51cDOY7guTaRNy8xNSZARPXG3qI0n89Yq+SSMjyg2s2lI+x6XU0JfS2E/WXzBbCdVvSmFjyjl2Bw9OzaMvRSpgmnRW68GTgLYorU5N4tndhz6S2nhmSW1QUW40cFAfsb3Sur/TQmEQpn8aR2hnIgm9YwVaokyIgxwgG5uf1c= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=Gi+ErREN; arc=none smtp.client-ip=209.85.214.180 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="Gi+ErREN" Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-1dffa5e3f2dso46214725ad.2 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=1711555529; x=1712160329; darn=vger.kernel.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=Gi+ErREN0UCS19uzmg1o+E8din1IxVVtJf1VZhfYXZ1HsipdhcyUcWy9U50cC+E6ZV t5CCngRlactnq7YLMCx0JVHYtCsbyFMYK8kBECoqmRrLzl0UYrK/6ftFgIZneclQOTlo TB72IEQX4/a+jCg8nuK77YEcBfaMZUVVgvRL/8puG11n/2gpGZx1X5tb8KWbrZdpDzzT HWfk3LE6fbGB+ABRFHth+fJtkxkGE6Ki1sxzCMtUFrx/w2+yPiZCl63M7rrLkxH/Vy9G MRa7BpXJ1DRiDv4Vel2oiqLgXfUFh5sWeMF+5f1bsBg/5GVYkkNVqNeg3RCFvm2604QW XdBQ== 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=GDOfeoGgJonZQpoXP3GoadK4fsDboUj6BuF8nia8cCJYFBQSfIgqQ+wQZ+Kg/yNQAf nJQ006tyLU46gwHl0sl1+s6IKCR9Ic43z+B6EXxID497jWE9gojVtEoPN0dmNjumqrYS n0tgOvSbUlyc+JztPyhsvndvtrYG5ahfIQiNJiDaSRaZ7UcZrEho+0JgnG/L1lFgofsj ozGEkDZJzHqYcow+a2O5ybC5QjxWp2LPV71/P5T6kWG5Bpe7/atFzPJESmDL9Rt3hTpK ZU25WRd1gD8ppcvSaN79adaFxeUkHREvFyY4TQ/X+b5Wt66eWwA5ph+sKTzu6tka1Hnp +45Q== X-Forwarded-Encrypted: i=1; AJvYcCV1q7RNN/FwT220/u4Haiuk4KMW/Qtooh4oLdK1FTP08cWh8KETTjuvae0GeriCAPyv5I8bB47jkqTOhBH3HRxg1TZsR2cmsVCocEua X-Gm-Message-State: AOJu0YzruUyomKtdQPFheNvLJAyISijjC7axB9AZswKjWyKky6T7zHWR PwldfHvA0AxTT35GxTwEPi1RC4RF9cFObfL4DZPU3Ye3XjbDmRa6AGEkYveHRQA= 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?q?Bj=C3=B6rn=20T=C3=B6pel?= , 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable 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=C3=B6rn T=C3=B6pel 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); =20 extern int riscv_patch_in_stop_machine; =20 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; }; =20 @@ -231,14 +231,10 @@ NOKPROBE_SYMBOL(patch_text_nosync); static int patch_text_cb(void *data) { struct patch_insn *patch =3D data; - unsigned long len; - int i, ret =3D 0; + int ret =3D 0; =20 if (atomic_inc_return(&patch->cpu_count) =3D=3D num_online_cpus()) { - for (i =3D 0; ret =3D=3D 0 && i < patch->ninsns; i++) { - len =3D GET_INSN_LENGTH(patch->insns[i]); - ret =3D patch_insn_write(patch->addr + i * len, &patch->insns[i], len); - } + ret =3D 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); =20 -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 =3D { .addr =3D addr, .insns =3D insns, - .ninsns =3D ninsns, + .len =3D len, .cpu_count =3D ATOMIC_INIT(0), }; =20 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_ctlb= lk *, struct pt_regs *); =20 static void __kprobes arch_prepare_ss_slot(struct kprobe *p) { + size_t len =3D GET_INSN_LENGTH(p->opcode); u32 insn =3D __BUG_INSN_32; - unsigned long offset =3D GET_INSN_LENGTH(p->opcode); =20 - p->ainsn.api.restore =3D (unsigned long)p->addr + offset; + p->ainsn.api.restore =3D (unsigned long)p->addr + len; =20 - 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)); } =20 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 =3D (p->opcode & __INSN_LENGTH_MASK) =3D=3D __INSN_LENGTH_32 ? - __BUG_INSN_32 : __BUG_INSN_16; + size_t len =3D GET_INSN_LENGTH(p->opcode); + u32 insn =3D len =3D=3D 4 ? __BUG_INSN_32 : __BUG_INSN_16; =20 - patch_text(p->addr, &insn, 1); + patch_text(p->addr, &insn, len); } =20 /* remove breakpoint from text */ void __kprobes arch_disarm_kprobe(struct kprobe *p) { - patch_text(p->addr, &p->opcode, 1); + size_t len =3D GET_INSN_LENGTH(p->opcode); + + patch_text(p->addr, &p->opcode, len); } =20 void __kprobes arch_remove_kprobe(struct kprobe *p) diff --git a/arch/riscv/net/bpf_jit_comp64.c b/arch/riscv/net/bpf_jit_comp6= 4.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" =20 #define RV_FENTRY_NINSNS 2 +#define RV_FENTRY_NBYTES (RV_FENTRY_NINSNS * 4) =20 #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_typ= e poke_type, if (ret) return ret; =20 - if (memcmp(ip, old_insns, RV_FENTRY_NINSNS * 4)) + if (memcmp(ip, old_insns, RV_FENTRY_NBYTES)) return -EFAULT; =20 ret =3D 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_typ= e poke_type, =20 cpus_read_lock(); mutex_lock(&text_mutex); - if (memcmp(ip, new_insns, RV_FENTRY_NINSNS * 4)) - ret =3D patch_text(ip, new_insns, RV_FENTRY_NINSNS); + if (memcmp(ip, new_insns, RV_FENTRY_NBYTES)) + ret =3D patch_text(ip, new_insns, RV_FENTRY_NBYTES); mutex_unlock(&text_mutex); cpus_read_unlock(); =20 --=20 2.43.1 From nobody Sun Feb 8 22:21:39 2026 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6BBCB137907 for ; Wed, 27 Mar 2024 16:05:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711555532; cv=none; b=Z0ha+ZRhQXrNrHXyB8GtrZugBmYnYefv8Doiviq9TFn0NptwjDHRTuK2sj3Z4vCTHdUse6BRUlY492EZTMv7CiZz0MDumiKbXcUZEq/dsOh/codUy9Bi1ZcZnMUUGe7cbiua2dn6Z2pEWRPqx8j44rSM/ejzfKoFRa1xaZOtyNA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711555532; c=relaxed/simple; bh=vl4qO9v5O5u/rqOA308hFsVWnPwODsir1st6pltlE7E=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Zmk8xebOQ0srFPyIPbTtSORL/NtGSlgjVgJqCFUty8Kvwc97DsSVLttZbKq5XidPKtZLv3bzXVfJt9/GFrYDe0WXJfaXVs9vp7DI+2KZN2Le8I2Hi7319OJ7qUWZOTkRJWGcgQrde0un8Y6Sw5p8aF8Pv3WURVNWvuK6Q4lzR80= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=gr8GI7Uo; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="gr8GI7Uo" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-1df01161b39so56943175ad.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=vger.kernel.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=gr8GI7Uob3kH3JMEbNyw4J5Q8VP9rKqluc1BEsH4DKz/jnsqf3C2QtHnyX9u3E804k 6H4LHP/8mq+nt+7Bof7eqdfczXjPbQaIE+tcccxzj3ek973WKqNpAq2Afpn8H2tH3zz3 Wn0Dtf7QLFbP4BXDQt5NeIVpQlnLqNSLPlOIo87BZOgT+d4Ct0A4O9AflVF3cqsr5k8y z7fxLUfkp26QoVIMW0lx/pVv0iYXsqAvCKG+m+wuEh2VFGBtjveKxmh8qTwIj/0mQXes RPwU5tQnp9CEtmcxv7pcFRk9pSzaTQoBNSJX4lCzFvoMR8XGZFckWarVf9qjfLvUOQ2I 8uLg== 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=C7w+wkkZOB8KidR4a5X0x6a/D8nLEuieidCL3FF7TcpWJ6GMT8MQQFKmkSfpspHmrV M2fi0LDQTz/3ITtotnidCZRi0rMBafrs7MTh0Qa9fjybr2PDmzhiWOt/qlw5EQe1WYxv QV9bnqsompZcuLhqyTtnqmn9qTARF/a2Ei9iN9mJoCzTmbR8uKztlzIlGI7mQRDSorUA aZFMmZzjd1loO2nR9vPijLoc1yvtp11nNpgujzei6LkYMIUZHemB3in2LekmDrSg5pL+ hPmDdy2PObojP+157enmzAfPLFZambEP8w6mzq0aEW0N0KuuiLKtqfw9GwFuIjyt2+FG xYOw== X-Forwarded-Encrypted: i=1; AJvYcCWNicICmvVaHSMsBOGVNl0I0vw5znnLv7toywlbOPs5jJgg0hidb3hfeerHXL7OZONtZmS52OoYI7TsWAsMHSyfWoanNn+ycgHRy27B X-Gm-Message-State: AOJu0YzN6BuKMwZHWJDvvsO0ViYtffwOTwrqD/YPjNwefr/XbPoL3wOo D5TVqBBDlnK7YNBjhdE7Y+7twL610vBe07QCCS5CX7cmOYZkuDtyGI0yRMkU78I= 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?q?Bj=C3=B6rn=20T=C3=B6pel?= , 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable This is a bit easier to parse than the equivalent bit manipulation. Reviewed-by: Bj=C3=B6rn T=C3=B6pel 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); =20 return (void *)set_fixmap_offset(fixmap, page_to_phys(page) + - (uintaddr & ~PAGE_MASK)); + offset_in_page(addr)); } =20 static void patch_unmap(int fixmap) @@ -65,8 +65,8 @@ NOKPROBE_SYMBOL(patch_unmap); =20 static int __patch_insn_set(void *addr, u8 c, size_t len) { + bool across_pages =3D (offset_in_page(addr) + len) > PAGE_SIZE; void *waddr =3D addr; - bool across_pages =3D (((uintptr_t)addr & ~PAGE_MASK) + len) > PAGE_SIZE; =20 /* * Only two pages can be mapped at a time for writing. @@ -98,8 +98,8 @@ NOKPROBE_SYMBOL(__patch_insn_set); =20 static int __patch_insn_write(void *addr, const void *insn, size_t len) { + bool across_pages =3D (offset_in_page(addr) + len) > PAGE_SIZE; void *waddr =3D addr; - bool across_pages =3D (((uintptr_t) addr & ~PAGE_MASK) + len) > PAGE_SIZE; int ret; =20 /* --=20 2.43.1 From nobody Sun Feb 8 22:21:39 2026 Received: from mail-pl1-f173.google.com (mail-pl1-f173.google.com [209.85.214.173]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6E021145B17 for ; Wed, 27 Mar 2024 16:05:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711555533; cv=none; b=gD5dmM4qS2/1TEIgFpJfrRZ9zsM6UyjAbhFQM2RxLhgFOkP6jNpWU41GrkYbAFDTz658hHi6FHIU/HcN3RaIh5tTiRIH2uQKloHy4MjSKTv4r0WlITdbnH7FJOWYO6jKD7ANLEiGDjkrIrp4YbiEONQFCCMuJsfPGFEEYI1651g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711555533; c=relaxed/simple; bh=WGczTXzBuFo89DltnnNjNAEWyViw0TD0N06kRz7Rv6o=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=Fn+ThMSrmC5e+LQQL78sFxzIaDkjv6UmJvsq6fRnfioKFDXz6GXAZ1fgGGmulx81iN0STo4XfstFk+L3l2xs2WAdt0pYNWex9IapH3GU6WdhEiF0TrM/oF6cjxWjg5e/uBI1EK9+h/yxUXuWPUiLVU4zTN3n6TqsxVEKB3MTdRY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=G9/7BIXL; arc=none smtp.client-ip=209.85.214.173 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="G9/7BIXL" Received: by mail-pl1-f173.google.com with SMTP id d9443c01a7336-1e0189323b4so54072135ad.1 for ; Wed, 27 Mar 2024 09:05:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1711555532; x=1712160332; darn=vger.kernel.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=G9/7BIXLMqxoyF54WYlCSiyyPLwjkaS44JUzhwo8nb6AgeIrL/fk5/54izSa0WIz/6 dj+y1r6sI1j/L7axOkxF7nlTDwnIuzmIKpbW3qxd8YkSBhgBtXfrmrI1/m59Ghxcmqpa ph2Juxo/04NAIjvwJm9s4VShyYeVdxlns04n45z09o6uRwH+P8JPn9j2c+bcP3LZFg+z PQWGZSeiNd3Pj1mh089ARSZi4niKGVc6Ykc+o9pA4Z4bDWorRs3WVW/SGSlVRHB8g/a9 yjfTsCYzvP/cUGPR+9ts95Ld4I9fjuxvAhXUbk8v/yRpPco0aO7Q2C9Sg6QGDUq8wA2f CJdw== 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=ezyPeh+7VDtK7YbyDiYYaUELmlykbq+H9fdwOs0qtQifRpYYRIobNCxWxM/us9EAK3 BAXhaOjqSj1WOgSMp34JGSxm3UvbhPKM0zWCgfQQImw91r+u4/13KXiouINRLep9Djea 070DEX/+KWWTZSGnJlE6QTtAo7aM0kF6mCj8tV83yK7EADqflA0X4FX9NVmED9Byix/N a0IkkaJDVkJ4WpqPsCKX0LRzfw4WAJcftdiqQ9IG2Oavt2vc5X9QEC6psIlbpDw8Msnm g0x0Zlns3SNVzsIBqY2nNXm3Buo4TpQCwW4gtH5huXriXL8BPBxNhmBVcIDxaGJXnPVb xdog== X-Forwarded-Encrypted: i=1; AJvYcCXEws0zb2ZROo72GRutZxM3nxDGCDsUHUXkVzh96Hm56kEHc1TACQSSvFVy8IBjd4eNrVJrxTH3xMQl2SgLL/9BSDNKXczGs9CP9zZq X-Gm-Message-State: AOJu0YzIYsnbDUMFnMYgNajVW/heYr1/18vAbPfHmD1lY9sjHZcF7jn5 ur0RpHRmfPwv7fqKwkxJrWgMIlk1PrXvtTgJ3EhJNJQcFsMCCRH8thVXfkehiSHj5z91B/GbMhh 8 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?q?Bj=C3=B6rn=20T=C3=B6pel?= , 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable This cast is superfluous, and is incorrect anyway if compressed instructions may be present. Reviewed-by: Bj=C3=B6rn T=C3=B6pel 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); =20 int patch_text_set_nosync(void *addr, u8 c, size_t len) { - u32 *tp =3D addr; int ret; =20 - ret =3D patch_insn_set(tp, c, len); - + ret =3D 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); =20 return ret; } @@ -216,13 +214,11 @@ NOKPROBE_SYMBOL(patch_insn_write); =20 int patch_text_nosync(void *addr, const void *insns, size_t len) { - u32 *tp =3D addr; int ret; =20 - ret =3D patch_insn_write(tp, insns, len); - + ret =3D 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); =20 return ret; } --=20 2.43.1