From nobody Tue Apr 7 14:04:19 2026 Received: from mail-ot1-f41.google.com (mail-ot1-f41.google.com [209.85.210.41]) (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 D181E31AF31 for ; Fri, 3 Apr 2026 14:24:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775226253; cv=none; b=uFgcbNNxroe2renZLsln0CqBAkYfHBJgvwlR8V75UMLS0XzeVUsDcaAfAhfDKQ/x88Q/dEa4/Sn7+F2zpD91f4Iz80jokpr8BHKNqWRS7wSggG9QBx13sD1AzJlfbL5z1JldM7jrLqNEf7gi7V1zeWTl5MmBP0L1Fa07r/k2GpA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775226253; c=relaxed/simple; bh=FOLvAW/2MDBWDNIX2ItmusLKTznPVoyS8kB8SIYc0YY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ncxo/Zt5kpdCjwuHE7MFphCqm126dF+YdRwxrDx4WlEbVXNv20w+LmmENZYOb61qIJEwAJ6jsyhPYe3haaltbM6Wke4t3GPdRvMd8O+Q6aGjT+qLWe4e+87SQSswry0AaW60N1B8rsB4G184T3zoKy7MQxvAl1ADz2hZo2/QYIA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=iSlAk2Qv; arc=none smtp.client-ip=209.85.210.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="iSlAk2Qv" Received: by mail-ot1-f41.google.com with SMTP id 46e09a7af769-7d55b97f358so1304439a34.3 for ; Fri, 03 Apr 2026 07:24:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775226250; x=1775831050; 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=97ZO5vwgea/5I8mCoklLcrJeYS/yYQVoVQGULeyvPBY=; b=iSlAk2Qv4WxNC46wXfszeXKLVu4cfW/Omz6tgEVNHauIi3RekcuuwdOLk1coCTZbhf T2zLGqM/nRev12JgvG0Oa3hU50Xt/s+ykuTaQgH2JziGwaTgYXYpA/9CS09pkxjEHJd/ ipOKq5JBj65OLFgEMwVM645F35img57ql5FbGV8KDKouJbbgWbZ+GAimgPrxQeelRhgr bYzyLAiteYNYbM5qxwwqnfizy8VyKDPwbA8SVxq0Sp1JxVx8HgbH8OSdKTwfsNA52TTV 6ZXeuw/hDQwDyLbecIobLxy8T2+4T9BduEQDBPcz8tchQo1j73K6/V8S63jDlEIZ+1FP 4k7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775226250; x=1775831050; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=97ZO5vwgea/5I8mCoklLcrJeYS/yYQVoVQGULeyvPBY=; b=WK3iO3HXw+9stAAVx7kIr48OpDI+qPZi3necDSHNOiOoUjVE7wd3ehRWuJsEKq+n7T HssKa5Xc2AQiiq3EN0naR+PfK0oYRPPJtkS2tgN8kAk28O6Iap0XFZWjoRzNZF5PpkbI rSnW4RaaGUNlf/c2O7eFNjXEyBH49zLE5nLl5wgiMybAGWoRlh7PA1llDjORkho9ipUf yu9mp+isdyHU2YDyQtaVabR0kNmYSlNxzgeCLa7YE8oJ8Hw0KhNIixlL6WnF0G8IlvDa igsi4sPBMe5RoCopJvqcUUxwWLhYtCLp0oazNRrfN00Z4PEH8s2c2KBLlqmrtM0d0E3l e7bA== X-Forwarded-Encrypted: i=1; AJvYcCWpi7Sn0HZxWclkPxkhdFJp2JkTPLca9ZgnEWeJRSseRmlKZBjS0lcTJ+HFBrBFdzBcl0N/lLxgazJUgr8=@vger.kernel.org X-Gm-Message-State: AOJu0Yw0hgxc4twd/8Fpg24ee6E4z91FShITwX9o+IfUfH5XgEj9yTL4 laCx3M0885puPv8OiP1zok2002Sr68hiQJOtAggXgoCjRWLj7lMiUIqu X-Gm-Gg: ATEYQzx1CplrTCQSDs915B7dD16t69yGxUvl9Uj2pPfB3w2vuP65lN6EwpgqCX+HitN wkUvWzSr03sduAfw/yD+8mmtWC/rkD+kZnUZNgi26ywhYX3oUgfsxTXk+xttPJ+wUsS1hsrCosG olV6Naby2D2Nsy/4L69+1+MgKbbfDFr8Ljvnl6+phXYP1fGgpqRi6AXbWO5hypse57VIkLsbdY7 nm+VRVxEy49zxpn8M3Mzy2IBlRoTx5tBZ1k+15dmZQRUd/Jznw+maiwjhrMvRW7uqMFYWOn6RNq qte75axJJoEln657LGvqpRw4SyXyF982Nzl77NHz+c8Eh3hSfVuA5Tx/778qaqd+CH8qVil0MyI jgkS4IOUfmpDw2ImeJZZ0wzHnaSR7eyoTS/ceeM2kegJEsq1kktwEXXZiTJllS4PKNtdXL9Tfww 9hGjBBydLatjQwy5TX9yE7CBQhBzQI5FiNtcr5loNxDzy8vbeGy0iKx2HW+lixDr2AWUWBKKLis g37nhBF5kzYDg== X-Received: by 2002:a05:6830:6285:b0:7d7:f15b:e399 with SMTP id 46e09a7af769-7dbb712a397mr2332148a34.16.1775226249693; Fri, 03 Apr 2026 07:24:09 -0700 (PDT) Received: from frodo.raven-morpho.ts.net (c-98-38-17-99.hsd1.co.comcast.net. [98.38.17.99]) by smtp.googlemail.com with ESMTPSA id 46e09a7af769-7dbb7c3a0c8sm1806671a34.12.2026.04.03.07.24.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Apr 2026 07:24:09 -0700 (PDT) From: Jim Cromie To: peterz@infradead.org, gregkh@linuxfoundation.org Cc: jpoimboe@kernel.org, jbaron@akamai.com, aliceryhl@google.com, rostedt@goodmis.org, ardb@kernel.org, x86@kernel.org, linux-kernel@vger.kernel.org, Jim Cromie Subject: [PATCH 2/5] x86/alternative.c: sort text-pokes before flushing the queue Date: Fri, 3 Apr 2026 08:23:58 -0600 Message-ID: <20260403142401.1387033-3-jim.cromie@gmail.com> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260403142401.1387033-1-jim.cromie@gmail.com> References: <20260403142401.1387033-1-jim.cromie@gmail.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" Until now, x86 can queue jump_label text-pokes as long as the poke-addr is monotonically increasing, but flushes the queue when a new poke-addr is less than the previous. Dynamic-debug now uses the queued static-key API, but the advantage is limited; we see a ~2x reduction in IPIs. Although the pr_debug descriptors are ordered, the patch-address in them are not; about 1/2 violate the ordering constraint. So this patch drops that requirement, and sorts the text-pokes by their address before applying them. Doing so lets us fill the queue before sorting then flushing, giving a dramatic ~125x reduction in IPIs over the traditional single IPI per pr_debug. Other arches don't need a queue, and so have nothing to sort. #> dd_ipis [ 23.100381] dyndbg: query 0: "module !virtio* +p " mod:* [ 23.103432] dyndbg: query 1: "-p" mod:* Delta-CAL (IPI): 242 Signed-off-by: Jim Cromie --- arch/x86/kernel/alternative.c | 42 ++++++++++++++++------------------- lib/dynamic_debug.c | 1 + 2 files changed, 20 insertions(+), 23 deletions(-) diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c index e87da25d1236..92987954b8aa 100644 --- a/arch/x86/kernel/alternative.c +++ b/arch/x86/kernel/alternative.c @@ -2,6 +2,7 @@ #define pr_fmt(fmt) "SMP alternatives: " fmt =20 #include +#include #include #include #include @@ -2823,6 +2824,18 @@ static __always_inline int patch_cmp(const void *tpl= _a, const void *tpl_b) return 0; } =20 +static int text_poke_loc_cmp(const void *a, const void *b) +{ + const struct smp_text_poke_loc *tpl_a =3D a; + const struct smp_text_poke_loc *tpl_b =3D b; + + if (tpl_a->rel_addr < tpl_b->rel_addr) + return -1; + if (tpl_a->rel_addr > tpl_b->rel_addr) + return 1; + return 0; +} + noinstr int smp_text_poke_int3_handler(struct pt_regs *regs) { struct smp_text_poke_loc *tpl; @@ -2935,6 +2948,10 @@ void smp_text_poke_batch_finish(void) if (!text_poke_array.nr_entries) return; =20 + if (text_poke_array.nr_entries > 1) + sort(text_poke_array.vec, text_poke_array.nr_entries, + sizeof(struct smp_text_poke_loc), text_poke_loc_cmp, NULL); + lockdep_assert_held(&text_mutex); =20 /* @@ -3151,28 +3168,6 @@ static void __smp_text_poke_batch_add(void *addr, co= nst void *opcode, size_t len } } =20 -/* - * We hard rely on the text_poke_array.vec being ordered; ensure this is s= o by flushing - * early if needed. - */ -static bool text_poke_addr_ordered(void *addr) -{ - WARN_ON_ONCE(!addr); - - if (!text_poke_array.nr_entries) - return true; - - /* - * If the last current entry's address is higher than the - * new entry's address we'd like to add, then ordering - * is violated and we must first flush all pending patching - * requests: - */ - if (text_poke_addr(text_poke_array.vec + text_poke_array.nr_entries-1) > = addr) - return false; - - return true; -} =20 /** * smp_text_poke_batch_add() -- update instruction on live kernel on SMP, = batched @@ -3189,8 +3184,9 @@ static bool text_poke_addr_ordered(void *addr) */ void __ref smp_text_poke_batch_add(void *addr, const void *opcode, size_t = len, const void *emulate) { - if (text_poke_array.nr_entries =3D=3D TEXT_POKE_ARRAY_MAX || !text_poke_a= ddr_ordered(addr)) + if (text_poke_array.nr_entries =3D=3D TEXT_POKE_ARRAY_MAX) smp_text_poke_batch_finish(); + __smp_text_poke_batch_add(addr, opcode, len, emulate); } =20 diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c index 18a71a9108d3..b5060749464e 100644 --- a/lib/dynamic_debug.c +++ b/lib/dynamic_debug.c @@ -264,6 +264,7 @@ static int ddebug_change(const struct ddebug_query *que= ry, } } mutex_unlock(&ddebug_lock); + v2pr_info("applied %d queued updates to sites in total\n", nfound); =20 if (!nfound && verbose) pr_info("no matches for query\n"); --=20 2.53.0