From patchwork Mon Feb 12 02:55:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 199570 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:50ea:b0:106:860b:bbdd with SMTP id r10csp2204394dyd; Sun, 11 Feb 2024 18:57:49 -0800 (PST) X-Google-Smtp-Source: AGHT+IH83RmCXsvaEkNKJA+9kBPPTKXMMbxH4LT1SKSIfSPPkzKgDq+zjHXwBcubNDCLAm6+fDM6 X-Received: by 2002:a05:6870:3a13:b0:219:b381:2483 with SMTP id du19-20020a0568703a1300b00219b3812483mr5875628oab.48.1707706669482; Sun, 11 Feb 2024 18:57:49 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707706669; cv=pass; d=google.com; s=arc-20160816; b=TDzBfcW2y31uhxntD9JdMUjT48Xs6LWRFkuGQK3wzE8kfYOsazzvwHf9TuPYeswaE1 eo8zDzZi8QEB/cQMGD2WB1+HxAJi+fzISqvI8EoxzNn/hk20ydhDLGDc+yd15XD/aaPV F1BGHO432jGUvpWLp6QCJ/fXWfr/U5qCg3XwThh7BpqjPfDO1cC34MABClAlG/TjW4lm 0gqi7fc6tGOYKdU5ydRMXyXhIQpgBs5k38E5hYL3qm2j3pUKZBRnNjJ/aUnYWMvE0oOk yQFwcwFgEVzFO823irBi9B7b+aIrxILEZt1IXXSqzRSOCgL5Cif1x+L0b5onQuBFjDaM qKXA== 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=E0Jh0YU6jz1auF8Zs4MfYzdAQn02NLjy744Gj0byF9E=; b=pJHGYuSdGd90mtxMmoNUdFFI71QvPVDu0CNx9fVWLq2dPzBEfgBSUAI7W4o3oxpvHE Zaw1KU2YIO2nLAKRY49zZEUd7vx2xaE34ZGGgTN9HK6SYrYraE7Wmxk/9uhBc5EwUuH4 c7B6i8LvnXPxT+Btiw+wX8QC2EUGw4GTccKmmebmYkwuBwEJc2qG84FHVhoCW/HcP8qK GgR8KNLi4DoJCP3T+zoNyE9NoP8piHbLU3fcJlK+3Q+uptyNw5YMO4ySffOO/tR7hNLa 1T3gAa5dHnSsUUncd+lkl7GnaiMMsCcp4zRNqOAYjEwSHEwNhC87reS8aN3y7UQbJsIJ ijQg==; 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-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61075-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=sifive.com X-Forwarded-Encrypted: i=2; AJvYcCUrgxBNC7X3lirOAzB27tRCxfTXJQpSSKDBh2cF7hQqg7hgjdxs/AbJwzwb4YkYX4iArWAMeM97hNcATT+/ckUOZeEQUQ== Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l26-20020a63ba5a000000b005dc491389a5si5901522pgu.812.2024.02.11.18.57.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 11 Feb 2024 18:57:49 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-61075-ouuuleilei=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-ouuuleilei=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-61075-ouuuleilei=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 A8CE5288B47 for ; Mon, 12 Feb 2024 02:56:30 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 0634610782; Mon, 12 Feb 2024 02:55:38 +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 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1790660228249594385 X-GMAIL-MSGID: 1790660228249594385 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 Reviewed-by: Björn Töpel --- 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;