From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=74.125.82.198 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796344509; b=LVOC7B4A4Tgc2b75lxwUrKx/vhz2EXsc6RGdR+DwNUNEyR+BKaYcMl1lH0WiIDXu2mZZ 2lKahoYrupyOaeB4j+Y2PyP4ZWQ4+al3cWMdFfNEtAkRVQRweu/nCutdm++dkpQHpKGtt 8mK+o4+fomb0a9HFybqM/HSDKDD3ju+SmTYnGSdOeCubp3A9OMQuUTUAi4DL8TtKY+6zY 5e3Kp8QyJ8peS7G73C7HWbFgUDS9N2UzKkS9G0PhoihlCK9ZLQbCOf6w0BmBbQaZDWiv0 /511G1CNqwyuNX7rkkMPiK4/WOtin/YLJZMlgW3pewDxutr6WJYonIO78Drh/b9SUsQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796344509; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Received:Date:Mime-Version: X-Mailer:Message-ID:Subject:From:To:Cc:Content-Type; bh=Mrq3BlMmBnCP/MyqatlGA2Ou1rbErp1DEUmILY5Sctg=; b=EjAFV9ObzfBMsAvLU2GXEZqDRjiM5AmkwK6rjAqBohH5SZEQaOmhE5+Bpxmg8p0Sp5fo meXktlt1A2L+ii/fqRHR3VrFYK87yCeEpMO/sZO/hnDHKUmue9f9rSmP59oR6i8ipTsLr r3s6C6/K8lWajvSndZoUTd5yDV1lLbb2TrI3FvJkBaCJkq8pKlWnhGvSJtxMEhYHZjtZG 7tGT/faLwcvjLb6VRTKIKEsDEFk+kCk8RVYV7LAy6BF1eHmU8CaT6cmiK3US5+5/NM9tx sRQAgFzAVFvhc740T8b7y5ev7thPvlliox/jy3SXSu9qYp4wEtfeerPG+n9NG5Kk6NQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=google.com; spf=pass smtp.mailfrom=flex--chuyee.bounces.google.com; dkim=pass header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=VCwl0hu1; arc=none smtp.remote-ip=74.125.82.198 Received: from mail-dy1-f198.google.com (mail-dy1-f198.google.com [74.125.82.198]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 391BA606A336 for ; Fri, 4 Dec 2026 00:35:09 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 391BA606A336 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--chuyee.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20260707 header.b=VCwl0hu1 Received: by mail-dy1-f198.google.com with SMTP id 5a478bee46e88-386c3309469so609335eec.0 for ; Thu, 03 Dec 2026 16:35:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20260707; t=1796344508; x=1796949308; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:mime-version:date:from :to:cc:subject:date:message-id:reply-to:content-type; bh=Mrq3BlMmBnCP/MyqatlGA2Ou1rbErp1DEUmILY5Sctg=; b=VCwl0hu1LtP4p69X4JUl4PfUSv4u71V2uc8Nxa+ZHKz+5pt7+2Ci3MMV3NaWkJhmTC AMnn2XQiqwerBuX7TvwvwCCSc0oXD6NCXk046pTwZJE0HnOBrZmwjn2X6oN+LH6F7byt eICMtF6qFjX3F5I2XdsWUjROhLIGTd7ynkvaFvyLB1dxntdgc3A1+KKYr+DxYgOYudw4 wkU4q5pYAQZxF+wF7J/Vpc9VaKREsZNvKAILcVvS+HZGJAx0+Z1ByqJ4zYzv3+QN9VTV TCyijWTrRfwjMD5V5dk0S79icoUp/nMiU8BSzPtlbesHZhZhANHEydXSSSHlnauF8A+8 eTAw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796344508; x=1796949308; h=content-type:cc:to:from:subject:message-id:mime-version:date :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=Mrq3BlMmBnCP/MyqatlGA2Ou1rbErp1DEUmILY5Sctg=; b=T+us0shnw4VXF+9ITjHG/PUYyJaHxeX1K/jvPEwNLEuPC0tZrmQ6PKciYeao47G8Hp sN4vaac39g5gxMtMT4tMm8+tfg2zOgx7ZV2M1QTkCKUXdpONMfafOPpulGR6VnYmwN2M mhA7w3KWwn8e8BG4S0JaEfN+/wvynYtUrewb6/JAOhx1nNqRhy/GTMrk2a+/oqVwcROo QOAJiHs/42T9jMve/HnXaD98qPud2dwfpxJlppTJPuYhIKXkbOw6xNK7CC2UfM93zDpv AYk7KRktQFV2ImORtkouGXyuokwiO+qmVrfYS9P9fvzjVyixxC//Ig4Wq+4PxyjvScV7 XdRA== X-Forwarded-Encrypted: i=1; AL+hErHvJZrm77YAsBWzMahn/9GPjsps+niL2aJ3wUK2tKqKSZxK/ZUBe1CQV8JTTo/X3RlrC6qu6ebFi9pYvpw=@vger.kernel.org X-Gm-Message-State: APuU4Z9jaMKdqF0d2gKPf7S1AcYYD+kaiCqTgI+7BqqKd4Ov93kBE1oZ OTUPIJMszbv7WqCPaM47lWKBcmoBEBHF6b849jBZB1B3bt6UqUr69tY6X5V/xN0skC6uLNTeRDO otXfihQ== X-Received: from dylq9.prod.google.com ([2002:a05:7300:5989:b0:387:4468:72c7]) (user=chuyee job=prod-delivery.src-stubby-dispatcher) by 2002:a05:7301:1a83:b0:387:4916:5f2c with SMTP id 5a478bee46e88-38752153968mr439380eec.31.1796344507930; Thu, 03 Dec 2026 16:35:07 -0800 (PST) Date: Fri, 4 Dec 2026 00:35:05 +0000 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Mime-Version: 1.0 X-Mailer: git-send-email 2.56.1.987.g2ec0ab4260-goog Message-ID: Subject: [PATCH 0/2] livepatch: make the transition stack check scale with patch size From: "Zhu, Yi" To: Josh Poimboeuf , Miroslav Benes , Petr Mladek , Joe Lawrence , Song Liu , Wilson Felipe Pereira , Dylan Hatch Cc: live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" During a patching transition, every task's stack is checked against every patched function. Two things make that expensive for large cumulative livepatches: - klp_check_stack_func() calls klp_find_ops(), a walk of a global list with one entry per patched function, for every patched function. The per-task check is therefore O(N^2) in the number of patched functions N. - Even without that lookup, each task repeats the same O(N * D) scan (D = stack depth), although the forbidden address ranges are the same for all tasks. The first transition pass runs under read_lock(&tasklist_lock), so on large patches this stalls fork() and exit() machine-wide for seconds to minutes. Patch 1 keys klp_ops on the patched function in an RCU hash table. Patch 2 builds a sorted, RCU-published table of the patched address ranges once per transition state change, and looks up each stack entry with bsearch(). The per-task cost drops to O(D log N). If the table can't be built, the existing per-function check is used. Testing, on livepatching/for-next (2c3787447317) with and without the series, in a 32-vCPU QEMU/KVM guest (Intel Xeon @ 2.60GHz host, CONFIG_PREEMPT_LAZY): - livepatch kselftests, with lockdep, PROVE_RCU and DEBUG_LIST: 39 passed, 4 skipped (legacy replace attribute not present), 0 failed on both kernels; no lockdep, RCU or WARN splats. - A synthetic target module with N noinline functions and a livepatch replacing all of them; idle threads added to reach the task counts below. The first klp_try_complete_transition() pass, timed with a kprobe, and the time from insmod until the transition completes: first pass insmod -> patched N tasks base patched base patched 100 ~1.9k 19.6 ms 1.7 ms 1.9 s 1.9 s 1,000 ~1.9k 3.41 s 1.9 ms 4.9 s 2.9 s 2,000 ~1.9k 14.5 s 1.7 ms 17.9 s 4.8 s 3,000 ~1.9k 30.7 s 2.2 ms 36.1 s 6.9 s 5,000 ~1.9k 156 s 1.8 ms 167 s 11.8 s 10,000 ~1.9k 1,069 s 1.8 ms 1,096 s 27.2 s 2,000 ~3.4k 25.9 s 3.0 ms 29.3 s 5.0 s 2,000 ~50.4k - 35.5 ms - 5.5 s 10,000 ~50.4k - 37.5 ms - 27.8 s On base, the first pass triggers soft lockups from 3,000 functions on; with ~3.4k tasks, udev-worker tasks on other CPUs report soft lockups too. The patched kernel shows no soft lockups or RCU stalls in any run. Its remaining insmod time is module loading, symbol resolution and ftrace registration, which this series does not change. Disabling a large patch has a separate cost: two synchronize_rcu() calls per function in the ftrace unregister path. That will be addressed separately. Zhu, Yi (2): livepatch: look up klp_ops in a hash table livepatch: check task stacks against a sorted range table kernel/livepatch/core.c | 10 ++ kernel/livepatch/patch.c | 38 ++++--- kernel/livepatch/patch.h | 8 +- kernel/livepatch/transition.c | 190 +++++++++++++++++++++++++++++++--- kernel/livepatch/transition.h | 1 + 5 files changed, 221 insertions(+), 26 deletions(-) base-commit: 2c37874473176739f4107c70739a930501d619c8 -- 2.56.1.987.g2ec0ab4260-goog