From nobody Sun Feb 8 14:13:02 2026 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 BE08827FB1E for ; Sun, 1 Feb 2026 03:16:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769915787; cv=none; b=r70a1XGBriVrFcrXpjsC/jVCvx5p33YaCwVJdQ1pwMxl1tCw4Wf9omYQ+27lfCP2zQcC5CHj9oetITQ02BeXSBsYmWi5mylD7X/yJXfNQE2ZKrNBj+fAnAmKzWjkwC2K3wXvuVU0GFmpEKJZKeuKa3dwTI9z2TUd0arBV5B6NLA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1769915787; c=relaxed/simple; bh=sWh4qRJW5wuJPUJ9xDpga/kqSm/hNDUxwTBOVpO7yLY=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NRyzqVZDWSYy4rkLk3bOLimAafJJbW2b5MxuNJ0dgmwOiRZJdw5jeKx7aLgXaujRATMqpBIGl3hkg/Ew/KfC1pQySinrsqNuHZv7YApVf9pdezkkiK6hIi40oZaeK2x2VohPtrYGxzs4mF06el/qphEV+1CQkX5bNtk0y85jIpo= 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=N7DkMk6E; arc=none smtp.client-ip=209.85.210.171 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="N7DkMk6E" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-81f4f4d4822so1699821b3a.3 for ; Sat, 31 Jan 2026 19:16:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1769915785; x=1770520585; 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=sMhSx+6lEu+8jKPgVw5bypgKSiK+gEAAE/MS9cV7FQc=; b=N7DkMk6Ei4jyLUgmG6n4QOYCluCj0s+R/Nr2YWcnnY3vh1hxplcbdFbu9mVpYEZcpp 0iXEh/pxQtbjuTbSGveiPAiDosmTnHPezV7NsCit9tXsdBGsQ24WYx+1PulETCJYA10q n3xUzzsUMaLzookq8VLiW6dOM7/+uMRINJ+Z08fSY7RTrt08Dw5p05PekVlszlVeI1Jn ifGYaKi/oh4x4iT3cRTZuxLFaVjkjUn+FV62khlbzf09d05hM0LGG36va2roehK62vkx y3VMSXwpdcRuxZFnsIzj/+vCcyCSeb6m02n+HUN+k5ryuefgniZxzwQOnioLG0M3k/Mk 2pow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1769915785; x=1770520585; 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=sMhSx+6lEu+8jKPgVw5bypgKSiK+gEAAE/MS9cV7FQc=; b=qCB0ukM7qMqzqI2vSPgP7Ujnh34vcqGK9ioUVjetaPUb52X7pfHgmiUtnRtXYqlW4a Q2yyMRJ+YbWDwSlxIqhPkZMbBMGxQY39WlNvJ1l9QrtDBNFCk5HRrDEwp79yqPGSlJtj Mg9PYuROXKFmoigAYU4Z7H/IB5d//puQmPEWq8KeSQ+FAkJGTNgQLXOl+ilpCtYP+7xj zUopwFqH2SVhLglqn3k68HbdwKSWGMVqPcZxjq9OwuQSYyQCkRpUkw4+7hvy7tlrGAv+ pJDpJXWkka6SEnvhtSVCSqivYA9Owz82Uxiv908yFi1Hxpt6rPB5JX3+vYL84c+0D09F +paQ== X-Gm-Message-State: AOJu0Yzgz6Pj9QNLiRsYteI9VgqqogQVTAE0ammXY8B7A9lQH1tKTfNv psglY6u7kAfca2176qhCaDcyXVi9QCAH3hK5vtLyX5JYLapLkKrqcfqy X-Gm-Gg: AZuq6aI5e1n6+KpCYAW5KIAsalXcPGaomP2SHaFV2bF49sU/q0nJtn1lP3X09sVSB93 TOjTEvsWfOYbitkAhkJ+o1xi8BpZ4B/WnIuMrCydXUTsWMECDEnWwNGs48OPqT3y//x2F1S0LoE VSZUUHT3ZdIYo+DwHY3vx8qqErK2eBZxPL9FlnWYlI8yTLJKb11gRwQ9zi+tYV6iL3r32Kuky8I 1Fd48tZFd8AMyJg5Awang8AEbyg3UPEODW1uiuX6KTjIvhpc2nFYpr5kEwXnnwjgQkkoUa6fKAm neg7ha8SveWeY232a31gweU2JShokgdapWGMH5tC21AM8oaP/RYDt8BgkoDO95LmRI3EpoxQ7J0 tTtxyJO/5WnfeJFsW3+sfat/QOXraz6t8DXL+jsSuyP2F6BeL4vJyJQf0gnkEHqFC3gqgUxuFoi 4awgl5wmgqyoh2tyAOwGPumKITRHN7pX4FB/cQRbVhxw== X-Received: by 2002:a05:6a00:a21a:b0:821:85a4:3f75 with SMTP id d2e1a72fcca58-823aa67f131mr7379254b3a.12.1769915784990; Sat, 31 Jan 2026 19:16:24 -0800 (PST) Received: from localhost.localdomain ([113.218.252.120]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82379b6b2bdsm11810818b3a.30.2026.01.31.19.16.20 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Sat, 31 Jan 2026 19:16:24 -0800 (PST) From: chengkaitao To: ast@kernel.org, daniel@iogearbox.net, john.fastabend@gmail.com, andrii@kernel.org, martin.lau@linux.dev, eddyz87@gmail.com, song@kernel.org, yonghong.song@linux.dev, kpsingh@kernel.org, sdf@fomichev.me, haoluo@google.com, jolsa@kernel.org, shuah@kernel.org, yangfeng@kylinos.cn Cc: linux-kernel@vger.kernel.org, bpf@vger.kernel.org, linux-kselftest@vger.kernel.org, Chengkaitao Subject: [PATCH v2 2/3] bpf/verifier: allow using bpf_kptr_xchg even if the NON_OWN_REF flag is set Date: Sun, 1 Feb 2026 11:16:06 +0800 Message-ID: <20260201031607.32940-3-pilgrimtao@gmail.com> X-Mailer: git-send-email 2.50.1 In-Reply-To: <20260201031607.32940-1-pilgrimtao@gmail.com> References: <20260201031607.32940-1-pilgrimtao@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" From: Chengkaitao When traversing an rbtree using bpf_rbtree_left/right, if bpf_kptr_xchg is used to access the __kptr pointer contained in a node, it currently requires first removing the node with bpf_rbtree_remove and clearing the NON_OWN_REF flag, then re-adding the node to the original rbtree with bpf_rbtree_add after usage. This process significantly degrades rbtree traversal performance. The patch enables accessing __kptr pointers with the NON_OWN_REF flag set while holding the lock, eliminating the need for this remove-read-readd sequence. Signed-off-by: Chengkaitao Signed-off-by: Feng Yang --- kernel/bpf/verifier.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c index 05a6a6606b6c..bb3ff4bbb3a2 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -9260,7 +9260,8 @@ static const struct bpf_reg_types timer_types =3D { .= types =3D { PTR_TO_MAP_VALUE } static const struct bpf_reg_types kptr_xchg_dest_types =3D { .types =3D { PTR_TO_MAP_VALUE, - PTR_TO_BTF_ID | MEM_ALLOC + PTR_TO_BTF_ID | MEM_ALLOC, + PTR_TO_BTF_ID | MEM_ALLOC | NON_OWN_REF } }; static const struct bpf_reg_types dynptr_types =3D { @@ -9420,6 +9421,7 @@ static int check_reg_type(struct bpf_verifier_env *en= v, u32 regno, } case PTR_TO_BTF_ID | MEM_ALLOC: case PTR_TO_BTF_ID | MEM_PERCPU | MEM_ALLOC: + case PTR_TO_BTF_ID | MEM_ALLOC | NON_OWN_REF: if (meta->func_id !=3D BPF_FUNC_spin_lock && meta->func_id !=3D BPF_FUNC= _spin_unlock && meta->func_id !=3D BPF_FUNC_kptr_xchg) { verifier_bug(env, "unimplemented handling of MEM_ALLOC"); --=20 2.50.1 (Apple Git-155)