From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f174.google.com (mail-pf1-f174.google.com [209.85.210.174]) (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 4A9AE34BA44 for ; Thu, 9 Oct 2025 15:15:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.174 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760022948; cv=none; b=aaRyM6moPfcyl7XwTu7ZMQ6OI8JrXzJbH8Joj5IdGr6kDfWFLTvy6ZW+fLvMC/PApM8ciKcfva3iSOqFMTJF2erY2dBWsVDTZKaoUBfdRuV3qHmo23X9IsvVETkbCQQ1kzLvtaFJO5SDDLmQi977OfceqsoiCIu8OpxqpNfXekU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1760022948; c=relaxed/simple; bh=qshWedy9zOFfj4S/MRqOfZgJWqZsXgvtsuKhKKMr4zs=; h=Message-ID:Date:MIME-Version:Subject:From:To:Cc:References: In-Reply-To:Content-Type; b=fGWreNAxlSpBLR3NrVLFnbEp7heGN8gyuSw7GXcv/XbMbIl61LFr6fc2g873grgsSkKr1tGrdgCiSGeW9Lg4eJTuGBSRz4WceiD5hXosA1Ikpi1whi8FYxjADAE+16umhhMOjGyiVgi3yZ34LaE3LeNfEqDKy5DAxEhrS4yEtH0= 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=JySqrzpB; arc=none smtp.client-ip=209.85.210.174 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="JySqrzpB" Received: by mail-pf1-f174.google.com with SMTP id d2e1a72fcca58-781997d195aso777137b3a.3 for ; Thu, 09 Oct 2025 08:15:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1760022947; x=1760627747; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id:from:to :cc:subject:date:message-id:reply-to; bh=QW3441uRfgKwaWkCvF0+xgoQHEkKkpXbASbo2YsQ298=; b=JySqrzpBKWSQvVdv4mP/Ji3WoJcaqqnP7i8wF1hAogeKz7ra+/+RSMJzFKDblZLoxm kFjQsIeKsyV5envbsisrA4QatiWY+AaCTwSloE4YVAXGRGncre8Et2UZfNdS5YA90Xb4 GL7168efjd+JP9hduygeWil2mox4I9CMvQ2jYH5jf7T7FREgcXotIoSzJIrkWLFW/y/y XIeOUsmEbm3IW8bMM6BEf+N16Wp91W4I+DAohQZE90vswMnoDHvYbahSCrDT1Hq7egwe QU7ucfTRnyDMWwJSIswRY0rnimQPj5vOOS+CdtP6PSff2vHJR+YG36V0iDVUv042h4Zk 8GoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760022947; x=1760627747; h=content-transfer-encoding:in-reply-to:content-language:references :cc:to:from:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=QW3441uRfgKwaWkCvF0+xgoQHEkKkpXbASbo2YsQ298=; b=cIDScmZVSae+6HcbE22RchimmyaFYNHFC2K5iGLcRhJdkjkV4bAaoB0UCfwu/YlAcN K7Bve4shIIBE2F4vmoMPXi3/YO/WLnjVVXvQ0Hw3B+XOudUwwbeHlVkzybVnVq+YHih2 8vbYgs0LsyoSePwtVbtdvBKTc80vxu5ysswmjzYPTGJiAUNUp54GMFPdK9FUXjun0FEk eSFDuKPWmLKVqEiSudqhulJnBGnMkcPlaGbZsrltIFq6EqjEKc7I3+uOoYc923rtLZ20 irTwmKs8fRgzWu0NiXyYt6KMTcmAB2AuG9GBSEzOKKMdJGhXD81uld3fUSsYKGVTlzij w2RQ== X-Forwarded-Encrypted: i=1; AJvYcCUlDePL0wfC838ygrBsDAZFay2+t4//i0DHYZ9y9KfSsmaaqY6QszBK5MrhlmSC/n9N0YS3heqBEwGPbHdNaiyfcAA=@vger.kernel.org X-Gm-Message-State: AOJu0YxMQVS1iMyhGb/h3mSqCAHYGR5BuVU8A3rjw+Ji7AzsTfjx1q/i ZR3fWC/pq66uhBAoP/7BqYLWv6in7ohcQnnJ9jFI5/ujvGvQHOZsALRs X-Gm-Gg: ASbGncsB1i0cXjXCTAg0PREII/sPdw8JSLU4MPojigJUpOGCsV7gu5VV7FAQor+Wfe2 dPcu+MGM5wyAL/zuwa4U4oY/HnY2/VFyBPDQYM0/t5jXUmUyyyX9+bo8WH9iOFMJdHUUwHrOw12 JmRbHO2tKKfMfsGqeT3vpzFqMNn0Ubciy6XLyUhY+HSXl/VTsmHxAYGzo9dzDAyhkLvmfdAMdAt oYZzLbSgh2hQPpaqRebJkdLvw09yxXtS6vg+TMBDs0fST+RDNRD2NK8WikD82zIAF8vZJ/nNggZ vlDvxEjQkoQBBiVKd/Nzgaz8YLr50aI5ErZXmnk0ZXkJMwJcFJ2ho94O7m37y1OhQmDKIDawvzE 0f94o9s9TJgOpGjeRPWYhgOnLTU/REO2Im6zNEYc6YG4gnIcgXiO+MQs6TSWPw4n4fFShrg== X-Google-Smtp-Source: AGHT+IGzWj2f7GE9unACisTFXTIm/6m0yZrlPKrykcpQ5kEtz/hxMKqimFAb0PWKVC9eCmlcr6WDoA== X-Received: by 2002:a05:6a00:464f:b0:781:15b0:bed9 with SMTP id d2e1a72fcca58-79387052040mr11267934b3a.17.1760022946316; Thu, 09 Oct 2025 08:15:46 -0700 (PDT) Received: from [172.20.10.4] ([117.20.154.54]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7992d09a87asm2637b3a.46.2025.10.09.08.15.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 09 Oct 2025 08:15:45 -0700 (PDT) Message-ID: <6485d7de-2af6-48d6-b427-66d3697ec2b2@gmail.com> Date: Thu, 9 Oct 2025 23:15:40 +0800 Precedence: bulk X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: bpf_errno. Was: [PATCH RFC bpf-next 1/3] bpf: report probe fault to BPF stderr From: Leon Hwang To: Kumar Kartikeya Dwivedi , Eduard Zingerman Cc: Alexei Starovoitov , Andrii Nakryiko , Menglong Dong , Menglong Dong , Alexei Starovoitov , bpf , LKML , linux-trace-kernel , jiang.biao@linux.dev References: <20250927061210.194502-1-menglong.dong@linux.dev> <20250927061210.194502-2-menglong.dong@linux.dev> <3571660.QJadu78ljV@7950hx> <7f28937c-121a-4ea8-b66a-9da3be8bccad@gmail.com> <0adc5d8a299483004f4796a418420fe1c69f24bc.camel@gmail.com> <5766a834-3b21-47b0-8793-2673c25ab6b0@gmail.com> Content-Language: en-US In-Reply-To: <5766a834-3b21-47b0-8793-2673c25ab6b0@gmail.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit >> >> Since we're piling on ideas, one of the other things that I think >> could be useful in general (and maybe should be done orthogonally to >> bpf_errno) >> is making some empty nop function and making it not traceable reliably >> across arches and invoke it in the bpf exception handler. > > No new traceable function is needed, since ex_handler_bpf itself can > already be traced via fentry. > > If users really want to detect whether a fault occurred, they could > attach a program to ex_handler_bpf and record fault events into a map. > However, this approach would be too heavyweight just to check for a > simple fault condition. > As ex_handler_bpf can already be traced using fentry, a potential approach without modifying the kernel would be: 1. In the fentry program: int is_fault SEC(".percpu.fault"); SEC("fentry/ex_handler_bpf") int BPF_PROG(f__ex, const struct exception_table_entry *x, struct pt_regs *regs) { is_fault = 1; return 0; } 2. In the main program: int is_fault SEC(".percpu.fault"); is_fault = 0; /* probe read */ if (is_fault) /* handle fault */; The main idea is that both programs share the same ".percpu.fault" map, so the variable 'is_fault' can be accessed from both sides. Here, ".percpu.fault" represents a percpu_array map section, which is expected to be supported in the future. In the meantime, it can simply be replaced with a regular percpu_array map. Finally, this approach is conceptually similar to the idea of using a global errno. Thanks, Leon