Received: by 2002:a05:7412:3b8b:b0:fc:a2b0:25d7 with SMTP id nd11csp2231819rdb; Sun, 11 Feb 2024 18:57:21 -0800 (PST) X-Google-Smtp-Source: AGHT+IHH81ETZppv8j2ncjwa/fobuvpzyvnXA2W9KeShVDih13885XI4RYhl/sMIrkevJg8abp4j X-Received: by 2002:a05:620a:26a4:b0:785:c04a:7980 with SMTP id c36-20020a05620a26a400b00785c04a7980mr7649581qkp.3.1707706641085; Sun, 11 Feb 2024 18:57:21 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707706641; cv=pass; d=google.com; s=arc-20160816; b=JtT0AP64f2u1Htvnt4Eao1Ew89YDUbZlLKqRpLCr89W6fjO9rGQeWGG+wigjCVOh+v tCcsEO0XuzJF/SVN6seMX/T4ZQzIgwGfvRWJbbw1eo005MI/LxSgG900Hwy3NuFfU1qe fGxtOJr4dhnjKLN4DZPhJeTLQvuoZxYGa0sj7HFySk64Q25U6tjjbHWpoRDdvgMCajMD Qjw5yAEL1HMqSNU22Uy7HeeltOdPubI+BnjSKpIr9UwdONCS+UtZrDmRlNJRFmlVJTla S823kvvxX10QWsoo+KWbWe8MhslmBC9WrTmPvGpu1dvWGtaJ8OKCcHkNdR3DldzsNC7D LGzg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=v3jsL0pNyfGhwaczyVRVtmiz/UJ7sxnmY3C1nRyOzZg=; fh=nQwdqD5DVOT3Au4ODISrbZalbXY9CxeGxOgNhG1aZAg=; b=BpKaWcVasWActx+ROYvLM8s041FRpKvf6OktPBx0ivRSPQBS7sLss/Saoau/kFZjum KuzaP79qJyqqJF55T+bFm3W38Ig+qipoGQK9GoNsPPwcFYaE1LIwSYBLg4d12p2iFIJf vsnQB44DTagn+FTTgA179eGpPLKE3czKpSUcj8JNhRNlnwWCI/4qbrdBjxVXlb6C+RtX oPKr59j4CXW5tVZ8/t0NwRC6itmKMZ8AKl5hSzs+vK84ApA2q8MbWfVJYJnjxjqmG5wd 2cNE01jkhC/OUTloxIzJLt8Yc2FVeDi0+a//WsJSnhaJs0mAqHa/Ncj2or+Tu973yIEo buiA==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=d6e9FAYj; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-61075-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61075-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com X-Forwarded-Encrypted: i=2; AJvYcCWLviIz4UC7j7jcOzy9Q5TK96cPx5CHiasY0oRq7Toy+JP8FBatcUgJH9OrB19DDch5R4UEH25/ymxZNinUdJ5ob8hYrwF69AebP1Fmqw== Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id f8-20020a17090274c800b001d724cd0d18si5347263plt.323.2024.02.11.18.57.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 18:57:21 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61075-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=d6e9FAYj; arc=pass (i=1 spf=pass spfdomain=sifive.com dkim=pass dkdomain=sifive.com dmarc=pass fromdomain=sifive.com); spf=pass (google.com: domain of linux-kernel+bounces-61075-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61075-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 990AA28843C for ; Mon, 12 Feb 2024 02:55:56 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id A326FC12F; Mon, 12 Feb 2024 02:55:35 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="d6e9FAYj" Received: from mail-qk1-f172.google.com (mail-qk1-f172.google.com [209.85.222.172]) (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 F385B747F for ; Mon, 12 Feb 2024 02:55:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.222.172 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707706534; cv=none; b=apjWj3RpqXZ2VjkjBcMvVofWcpGHjIxYTn00Mmd8sXMqlsD+13oAeOdCutoHZh7o4Lbt9iXh8SB6hn6bYmuJdQ/OF1xhsUnyl8P1J6iT65md6mPESyI7QMKQC0UeKkujXXUliPfxX2kHFTvQe5rESdGmP/Bwp54/nVsbVoWTlP0= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707706534; c=relaxed/simple; bh=7b51flB5NoWMAjsCNRFa3fvRfjAAoQvzjuCZ5CXigcc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=jGxLsZoqQprgymTqV0pTHGuo8GvqC4XVE0VwnQfzee0w7l0Uaee3k8P4TPKr7yKCedNEPzmD3OpP5/okpQSwIobQgmdA9zuCE8e0ijtDlyudVn994+sB0VOdmKRe6/y+sO6MV77YCWjwmae9cO3yMd83AvMxq5iUZ4EYeiF1Ess= 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=d6e9FAYj; arc=none smtp.client-ip=209.85.222.172 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 Received: by mail-qk1-f172.google.com with SMTP id af79cd13be357-785d5e6c87cso46968685a.2 for ; Sun, 11 Feb 2024 18:55:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1707706532; x=1708311332; 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=v3jsL0pNyfGhwaczyVRVtmiz/UJ7sxnmY3C1nRyOzZg=; b=d6e9FAYj70r6vTzZCrdhlUuY6UyjH6pzaAbExIMCgaMLRCT+odisfpv2YZQ423K8lF X04tg6VB+4+ccMOYOQn/idjcJagiwONzKpi0qpQjEbNgFtbhnhY9u2urs+WdYA0POuUS T9K/hLU9erlZTfTw+D9cgzPtBuBDBbAg2J+37tuPss9RbZ1o0o6YehYP8PxQwJNS04uh TifzPUc4awNFXT/8dSpbpHZLWcGMzi4lzcHV6H1MPGIHtHvKx6u+MqSZPmaebby0xlrb /qu3IJtmhRc+o638Or/VClSSSRcsCVLXo/f3MkvwMeP16ix5soE9nTtCQUEAOEc4klPl YbBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707706532; x=1708311332; 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=v3jsL0pNyfGhwaczyVRVtmiz/UJ7sxnmY3C1nRyOzZg=; b=ke9NhIpd+2xqgvm133PA4JisPDFubFSuBP+RsYK5Y/R3KOnMbKCU/WHEluxtOTmIF3 n/Y3APMBetrBgt8VRStBS8L2UYxt/bB1Anon4JanoBllUrxyZjAJvAoW2kiickJeoGmh W9wffhZNn5iGn9caG22wxip/WR+PzuTsHZvfD+zAkXwmIr1fLb2Ym4+mwbzKx1ONB15T o4voUw6mzBlgKcYOCxGrDlr3TUdTMPBlyxJWjfgAqNuvG8WdkyIAOKIG0S+Vy0N7iqLK wyig4VBijkiQUzwS4q4UryW8raOp3Xc6gXV9cpKL01NMDLFzcj1KTAo6P3xYsNXxQ2GC yFtg== X-Gm-Message-State: AOJu0YzJdNv2IkKhuEHuNwycer9aUIn6MInqJ2QgntYp5nTDif02gRMg Cwp10KVWNL0oQkTUIIJp3rfwYkdw3FTBwSVriuii802irtcQpc3PVYfj5vH1jvI= X-Received: by 2002:ae9:e905:0:b0:785:cb7c:8554 with SMTP id x5-20020ae9e905000000b00785cb7c8554mr5700867qkf.14.1707706531837; Sun, 11 Feb 2024 18:55:31 -0800 (PST) X-Forwarded-Encrypted: i=1; AJvYcCWy6qXPXNq8zE7X4aCqdUsGkzZSwcuXpP36Aqhia9FpyMYlSA46fzz3fov1YRllNfE3l79P88bKmGeSWd+kTI+Bsjos0Hy63ENvtL9y4gwO8qWroxFx2r63uA7nX8YAmOUoULqR8j1rZ9/GKNNLLoqSM22Fxp4u5cvUscnfQytng3hHRougX121AExZPirXPuRcnFvb3QyZVPOBI1Wlvt4AwcFcltkbtfd46crhuW1wpeiDCtayROslVQJRF68X9aZUTc6/tizcK4QUVA== Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id lb3-20020a170902fa4300b001d9af77893esm4906443plb.58.2024.02.11.18.55.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 18:55:31 -0800 (PST) From: Samuel Holland To: Palmer Dabbelt Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, Samuel Holland , Ard Biesheuvel , Jason Baron , Josh Poimboeuf , Peter Zijlstra , Steven Rostedt Subject: [PATCH 1/7] riscv: jump_label: Batch icache maintenance Date: Sun, 11 Feb 2024 18:55:12 -0800 Message-ID: <20240212025529.1971876-2-samuel.holland@sifive.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240212025529.1971876-1-samuel.holland@sifive.com> References: <20240212025529.1971876-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: 8bit Switch to the batched version of the jump label update functions so instruction cache maintenance is deferred until the end of the update. Signed-off-by: Samuel Holland --- arch/riscv/include/asm/jump_label.h | 2 ++ arch/riscv/include/asm/patch.h | 1 + arch/riscv/kernel/jump_label.c | 16 ++++++++++++---- arch/riscv/kernel/patch.c | 2 +- 4 files changed, 16 insertions(+), 5 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/include/asm/patch.h b/arch/riscv/include/asm/patch.h index e88b52d39eac..9f5d6e14c405 100644 --- a/arch/riscv/include/asm/patch.h +++ b/arch/riscv/include/asm/patch.h @@ -6,6 +6,7 @@ #ifndef _ASM_RISCV_PATCH_H #define _ASM_RISCV_PATCH_H +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); 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(); } diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c index 37e87fdcf6a0..bccd9ed04a05 100644 --- a/arch/riscv/kernel/patch.c +++ b/arch/riscv/kernel/patch.c @@ -188,7 +188,7 @@ int patch_text_set_nosync(void *addr, u8 c, size_t len) } NOKPROBE_SYMBOL(patch_text_set_nosync); -static int patch_insn_write(void *addr, const void *insn, size_t len) +int patch_insn_write(void *addr, const void *insn, size_t len) { size_t patched = 0; size_t size; -- 2.43.0