From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.214.180 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796097214; b=DeeTWfD1f8ernxoHiTTYeRz8/WR5chDqlE4775DKQO8R0I4G/399mJPYgGaKLnNObLaE bPR+gC6xPwPPnnoKOIjyYFHq/5Q0KUWjlCLpqHsraVnI84F5lz7uDLcxPDRbuvAR4lld+ zD3MWyxEW3p87HMA4RSzE5u2S//YaUTMvijlDu8n0U+c4FyghRueB33JpxUAVdhDxiqzJ 4z8whdatllCrwXdyGDX6kngp6V8t0/fp1TjOUQdCoH72+Tx7Cj4b4ox/IV1vGvc/lhPaQ HxEeEe+B4SYUS0Q3RFz+R+I0XguxISTYAXGuDGwj4Dov4do4OOjNVXAzr6OW0wxcnCg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796097214; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Content-Type:Date:Message-Id:Cc:Subject:From:To:In-Reply-To: References:Content-Transfer-Encoding:MIME-Version; bh=cSP7oQmsSgVjpKTxLGuxzoCT6AiQFLalcssrbiu5ttE=; b=xPtMDbKT04+OgK9XEYnlCxc9wM/WT0y3xnB5nzpj6z/Wufd852zNaE0HguvNtGJDZaFZ LpwiNNZ9RTSkNXSIhlQ+gXYS1Xg2qoojZ3KsxAtoc27fs2pVcPcDUMZ/Pw17Jw9K4xUzQ aWfA8eyYwcCGoUSTaJKS/xt5jv/v8gCKQ3G4PIh3XtG9JSXRjKiPFS3isjph9zq8zKwRX 2cTglcpyKTNAjqp8bfAK6p3rFf826aPK335bJnu9E+vG9mFGtoD9NL1mouiEcSul4XeGo FTnM1ERpX6FFWot3GESgv2s00b70BNkO/BCiMKtR3YqdbtwSGwotkSseTW1e5bamvww== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20260707 header.b="ed/93Fgj"; arc=none smtp.remote-ip=209.85.214.180 Received: from mail-pl1-f180.google.com (mail-pl1-f180.google.com [209.85.214.180]) (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 73E88606A325 for ; Tue, 1 Dec 2026 03:53:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 73E88606A325 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.a=rsa-sha256 header.s=20260707 header.b=ed/93Fgj Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-2f0414c1062so67109965ad.2 for ; Mon, 30 Nov 2026 19:53:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20260707; t=1796097214; x=1796702014; darn=vger.kernel.org; h=mime-version:content-transfer-encoding:references:in-reply-to:to :from:subject:cc:message-id:date:content-type:from:to:cc:subject :date:message-id:reply-to:content-type; bh=cSP7oQmsSgVjpKTxLGuxzoCT6AiQFLalcssrbiu5ttE=; b=ed/93FgjAzfMD8wXBg1WYLVfLIj9jzRs16rBjTdotcVtEVFFTMwitpMwcgg8DUNZi0 N2eBrlwGkvWbjnQz67E8KPVwZU1DX5wmoTJfmHfKwCR4E5HpEpgMHNHtDNMx0yo3fU3I aapKRt1KmuyyF3b44wkkHHedZh7sDCzLKWZJWyQEYs4rytBOFiWo1zVsLEap6M01+5ZB RgUakNhygG7aZ9BhQKJnz2oML+MUSoAoluWOPw2+C3lfuUxRHAZiBmhoqXxoCxoq3PpD 0l6c6FHyB4Snh95WlAi9D35AMmXE5dL92zKbSNEv5pIGU7E9pgWZmmbIC3Cgd9s0S4+n D9vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796097214; x=1796702014; h=mime-version:content-transfer-encoding:references:in-reply-to:to :from:subject:cc:message-id:date:content-type:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=cSP7oQmsSgVjpKTxLGuxzoCT6AiQFLalcssrbiu5ttE=; b=QSVN1TQ84vuXb/irr+NDccH48mM622MCwEY1UQFw2fvi5aKjVsyWZbVx7USKrEgzZT wC/Dszf9g+ZF0NvCorrZE48Wi6O/lR5A5dkdMJZG8lZKV1pRgvU7+spsclGiWP46t3o3 VDLdMGxFWz68MlU66Vxjz9QrdHsy9BOMoebdUSm6GmnfaBxp0LJOzcrdORWPySsDWkYW 6xSD/se+no4IEXnj0Pw1krozPMaKMMKxFkVCeG2ggkRRSdxugKchZqc2wDYLw6PvPa4T QCD0SQoSMylFjaYqi1O5HM+8Abiqv9dm16mdJQ8zRY+a34aLl8k/f+Ie6ND/DczgWnl5 tHEQ== X-Forwarded-Encrypted: i=1; AL+hErF7MPjqC1xqpypay+kbUSvDCVJ0+lCieeLe7wEdPqmMFd+JPtauOANbJGra1dqjjUva4RPca4IvwR6lQpY=@vger.kernel.org X-Gm-Message-State: APuU4Z+4OFX6dzi2yKlYuhUhoc3E6kTihjS820voIIFQurH3Iz1PDo/4 Do3Erk60bgnnH9F9CsBHzn1t9XGhgaqni6zgQFdZQ9Brh1UlgMfWGUD1 X-Gm-Gg: AZFdTZe3hPzhJg5Swxpvs0caA5XADfVLEJ18ngktPGItVlFu45KyXjDZJ6k5fwhmu5F Omn3TTWAEs2AsrLss7S0pUJnYHvMUPK9fmJSViAwL64y4JudWVaI8MQLFxCwq10sH14/csHwOoe 5UCbgFCRLTVuqsRnCLTxZ6xz4a4djZZkGBDHkSHbye4do5iR5jx+XdguhKoLqB1nRCzGfXzMKOK NTR1kZkpLqoRikSCSpsJ3xL4y1aW0yaMhJsCWnKB9PYxRL89CelynuPZQD4wcl2JNd3vSIeQLOo y38M4Hd3EapveC1WQDxkg5AxNAJcvyb82bHck4tnDOo2BY6wMmr2iXypWl5LVr49qp1WiKzDo3x MCyFRyR8CyOqY/wY0M4CINsL0UfWcn99RXbC4oc/aVVYbD5YQPv8WKLjfwspqS0P5w8qB8cgNit vQDBcNY6HyFb864gSY4XLq/FOB4tG/RbtHE6pZDXc1aNrzSJAWhuI4ZWtHnPZszRR9/pR64Ps+V 8IZ/hxcX1+CNDQlZei6Q7FL/EkFYcaqk/uihjdKpe4QTyjAi1wbFlMUqQiFZPg2Orcd7QxaVz4K 5DGeZHqgPuvvKxUJCdV8/Qu0Qx5WlPEcvA7wqbees4YmobHowME1iML1vu9h65RV7XQsNz5HM5e 1OQDNO14LlN8g114ySyKv6OX/Pac8YSLp4G0= X-Received: by 2002:a17:902:dacc:b0:2ea:19bc:2fe2 with SMTP id d9443c01a7336-2f03ef59bf0mr366160555ad.10.1796097213567; Mon, 30 Nov 2026 19:53:33 -0800 (PST) Received: from localhost ([153.61.198.247]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2f03f1215d7sm171093025ad.65.2026.11.30.19.53.32 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 30 Nov 2026 19:53:33 -0800 (PST) Content-Type: text/plain; charset=UTF-8 Date: Tue, 01 Dec 2026 03:53:32 +0000 Message-Id: Cc: "Martin KaFai Lau" , "Eduard Zingerman" , "Kumar Kartikeya Dwivedi" , "Song Liu" , "Yonghong Song" , "Jiri Olsa" , "John Fastabend" , "Emil Tsalapatis" , "Ihor Solodrai" , "Steven Rostedt" , "Masami Hiramatsu" , "Mathieu Desnoyers" , "JP Kobryn" , , Subject: Re: [PATCH bpf-next v4 4/6] bpf: Check program recursion per task via bpf_ctx From: "Alexei Starovoitov" To: , "Mike Bazov via B4 Relay" , , "Daniel Borkmann" , "Andrii Nakryiko" In-Reply-To: <20261130-bpf-preempt-v2-r2-v4-4-bd28389dfd64@sentinelone.com> References: <20261130-bpf-preempt-v2-r2-v4-0-bd28389dfd64@sentinelone.com> <20261130-bpf-preempt-v2-r2-v4-4-bd28389dfd64@sentinelone.com> Content-Transfer-Encoding: 8bit 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 On Mon, Nov 30, 2026 at 03:54 AM Mike Bazov via B4 Relay wrote: > +static inline struct bpf_run_ctx *bpf_set_run_ctx_prog(struct bpf_run_ctx *new_ctx, > + const struct bpf_prog *prog) Pls use __always_inline to avoid future headaches. > + case BPF_PROG_TYPE_TRACING: > + case BPF_PROG_TYPE_STRUCT_OPS: > + return bpf_prog_check_recur(prog); Dead code. bpf_check_attach_target() rejects these targets. Drop both helpers and check three prog types in bpf_tracing_prog_attach(). > + if (prog->type == BPF_PROG_TYPE_EXT && prog->percpu_state && > + bpf_prog_recur_per_task(tgt_prog)) { > + err = -EINVAL; A sleepable target is preemptible with or without the mark: raw_tp.s target runs attach of a marked extension --------------- ------------ ---------------------------- not marked preemptibly -EINVAL marked preemptibly ok Reject both. Also add bpf_log(). > - bpf_reset_run_ctx(run_ctx->saved_run_ctx); > + bpf_prog_exit_run_ctx(prog, &run_ctx->run_ctx); > + bpf_reset_run_ctx(run_ctx->run_ctx.saved_run_ctx); The order is wrong. Marked progs still lose events. The deferred preemption fires while the frame is linked. P is one raw_tp prog on sys_enter and sched_switch: bpf_prog_exit_run_ctx(P) preempt_enable_notrace() __schedule() trace_sched_switch() bpf_prog_enter_run_ctx(P, old_ctx) old_ctx->prog == P <- dropped, P has exited already Same for an fentry.multi prog that covers the scheduler. Unlink the frame first in all runners, like in the diff in v3 thread. In the trampoline enable preemption after update_prog_stats(). Otherwise off-cpu time goes into run_time_ns. Nothing reads the run_ctx argument. Drop it. pw-bot: cr