From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) (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 560AC340DB8 for ; Thu, 16 Apr 2026 22:35:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.48 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776378950; cv=none; b=Eu6jawZAffh/VRXlr7Bm4AexliT5hDAqQLvkZmUYXQSnsBivEqCotl7kcArFyLI+ntrYhTnNbLzwjystAe84uRs+LC71/CkiwkV9lNmS9cJfyZmIIZjGaScpqCZsXwREqBZu3KRxz3meKAK8B1wSkEPPJCPsCzmT+l3+pZRie8c= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1776378950; c=relaxed/simple; bh=QWfrlipXQsOy06lz6vFBWissQz/4ZX9aVwggQjyoGYU=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=U0UgfNA9U3zJbglvLCVqlELLrN7ncH0MvYy+bHK9ZiQfLXNoGMVpcyh6Jk9umFM39lGuaN+4kPAbBiNspOD8KpsxVgr7aq1ZvK2sAZ2HWDdGDsKFs/O9pkxHB1ZG7zKD4IeKdunoI6RjPvvED5gzJNr6vmuNZ0cArvy4+HU6oFA= 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=EMSqe8sS; arc=none smtp.client-ip=209.85.128.48 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="EMSqe8sS" Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4887f49ec5aso647175e9.1 for ; Thu, 16 Apr 2026 15:35:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1776378947; x=1776983747; darn=vger.kernel.org; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:from:to :cc:subject:date:message-id:reply-to; bh=LQR71K9y6cyOEBCESH0pgQ7cpkLOqqoQKhR9kTbYgkg=; b=EMSqe8sS/fCwSglUHKoycTUsUERTMzxPdUCdrTlBpX2ZNTWMwnGGRxCTQnr8N5T+PG AIFq2ATqNubyRAanxIhGS8mHra8x6jy/aKQMq1YMh6C9UGv0kFz4tQHcS6dojTCr1vlt b9sGvBDGl1Wspe1kEhFpyWTFa6IpoyRcIBIpfuE+HpT46s/9wvsih7OQeCOm6s9bna/e JCu9xOJJUL+HqF7/KmQlU4Fun6rJkUQZRDfZTXGfCbNm4XcQHtnzkjxjVUyscBW75sA1 DMxrX+Cgk5H3fOEITxWsS03y6hVDNYblCI5sdgjMgEY+g3liJueAdznqLuSZEUMO/73T +Lug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1776378947; x=1776983747; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:references:message-id:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=LQR71K9y6cyOEBCESH0pgQ7cpkLOqqoQKhR9kTbYgkg=; b=TPiW/vj1DNmp1RpRkTqeqp0+QZBfnvBkICgi7WlLPqTX89yoIA4VcUrFuvICD9xlkq 0oxcpLS1CIfYjMgRd3L+gU90JHSUOGu8bB5PQk45Esg8/63zBvcA5JFsyotx5enXtuX2 wNrCCmQ2S/I4Z9NY82bHdsKpFMYzwnBp2hpUrxvc0Htbs79D2C8vRVOoT9TjmJ97JPIX vd8iGIervAqmXPBnVzBN4+ItCzA7xdQF9hdPPb81VyOt471HBCui/Bq4Pd/ECDBhwXzu CWWrvTsRPtT4IKOT4O9W/hbOT16IZHdkDXiKgSFNclNxVH6G36YBzDe3rthuxGTcczbQ T6YA== X-Forwarded-Encrypted: i=1; AFNElJ9UcklYUuRXTZIcVVWHaHx+xOm/08SRaTdJM1+SwZly0toczWMyp9YQsPN2byf2iigOy5IBYrzj/q/Sxuo=@vger.kernel.org X-Gm-Message-State: AOJu0Yz9aIbPAL0I+SjQVKBmk22OlH1vdruYDjixr+mr/Z9dT5NCujMw 282idzmXt2488acYIKSlLiG+G5YNbbXIbi1yyuvnv/KnQM4b2xDwbtCR X-Gm-Gg: AeBDieuZDpAqcoDxUDFI0HZK0BxtC7MyP8T53oCnRcC1ytzwxja++3F58IAkCKZKTdq /yIj9uGlp7H3Dp2nvcM5KX1KFVfbshEJgNringnQ5n4NKMnltrYj9wBkXVA4pFsR54yXhT6EipP OrOVmCU8Z+SPS8dxK8JMTQM8g//HhOiWoI5Kvdkktn2Q+phl/1OS7VA/Ss1zZGrsfl3o00TW724 SnC0SCdljM/sAgNqdN/L/lbilOWxKGGh7MgwtXYyykOPxb/UZqqn51KoEEly20ft6H/CA0NKp1q ukB655vIjan6cNJQY1X3WM9TANUigPd8HtvAVbEy6iS5rmfX9I0jndYW7lGhiX9A3xtwUye//qL XK5Ggp9NhefcA7/L80t9dPc74TNVMfRREcoajYcTP0chSOq0JZ/vMbkXpmA1ZRf8mgy25qSSFMP kBJyN5RNjbtIsIB3rQYWH6N44LE+AaFOJTSFMEtLoW6JmvIZJHv9D4WhtNzzjovD+FiaGlhzDRG IMdcvkew9+KC86g1QwSLB5pGG1G8SJ17so2z+xuGsmT1ZORKakFp8Q5C051qSvgeGqrOA6e+so8 wf58InsBLjttXGMh5JQoUdat+ZBJhQzJ9jkPpTfjm2r+IFdE0ggtKA== X-Received: by 2002:a05:600c:a309:b0:488:dfbc:490c with SMTP id 5b1f17b1804b1-488fb765df6mr3363695e9.16.1776378946564; Thu, 16 Apr 2026 15:35:46 -0700 (PDT) Received: from mail.gmail.com (2a01cb0889497e0092ca608f43e4326a.ipv6.abo.wanadoo.fr. [2a01:cb08:8949:7e00:92ca:608f:43e4:326a]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-488f581d836sm79610725e9.7.2026.04.16.15.35.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Apr 2026 15:35:45 -0700 (PDT) Date: Fri, 17 Apr 2026 00:35:44 +0200 From: Paul Chaignon To: Yihan Ding Cc: bpf@vger.kernel.org, ast@kernel.org, daniel@iogearbox.net, andrii@kernel.org, shuah@kernel.org, alan.maguire@oracle.com, linux-kernel@vger.kernel.org Subject: Re: [PATCH bpf v3 2/2] selftests/bpf: cover UTF-8 trace_printk output Message-ID: References: <20260416120142.1420646-1-dingyihan@uniontech.com> <20260416120142.1420646-3-dingyihan@uniontech.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20260416120142.1420646-3-dingyihan@uniontech.com> On Thu, Apr 16, 2026 at 08:01:42PM +0800, Yihan Ding wrote: > Extend trace_printk coverage to verify that UTF-8 literal text is > emitted successfully and that '%' parsing still rejects non-ASCII > bytes once format parsing starts. > > Use an explicitly invalid format string for the negative case so the > ASCII-only parser expectation is visible from the test code itself. > > Signed-off-by: Yihan Ding The test makes sense and I verified it fails as expected without the fix. Acked-by: Paul Chaignon > --- > .../selftests/bpf/prog_tests/trace_printk.c | 28 +++++++++++++++---- > .../selftests/bpf/progs/trace_printk.c | 10 +++++++ > 2 files changed, 32 insertions(+), 6 deletions(-) > > diff --git a/tools/testing/selftests/bpf/prog_tests/trace_printk.c b/tools/testing/selftests/bpf/prog_tests/trace_printk.c > index e56e88596d64..a5a8104c1ddd 100644 > --- a/tools/testing/selftests/bpf/prog_tests/trace_printk.c > +++ b/tools/testing/selftests/bpf/prog_tests/trace_printk.c > @@ -6,18 +6,21 @@ > #include "trace_printk.lskel.h" > > #define SEARCHMSG "testing,testing" > +#define SEARCHMSG_UTF8 "中文,测试" > > static void trace_pipe_cb(const char *str, void *data) > { > if (strstr(str, SEARCHMSG) != NULL) > - (*(int *)data)++; > + ((int *)data)[0]++; > + if (strstr(str, SEARCHMSG_UTF8)) > + ((int *)data)[1]++; > } > > void serial_test_trace_printk(void) > { > struct trace_printk_lskel__bss *bss; > struct trace_printk_lskel *skel; > - int err = 0, found = 0; > + int err = 0, found[2] = {}; > > skel = trace_printk_lskel__open(); > if (!ASSERT_OK_PTR(skel, "trace_printk__open")) > @@ -46,11 +49,24 @@ void serial_test_trace_printk(void) > if (!ASSERT_GT(bss->trace_printk_ret, 0, "bss->trace_printk_ret")) > goto cleanup; > > - /* verify our search string is in the trace buffer */ > - ASSERT_OK(read_trace_pipe_iter(trace_pipe_cb, &found, 1000), > - "read_trace_pipe_iter"); > + if (!ASSERT_GT(bss->trace_printk_utf8_ran, 0, "bss->trace_printk_utf8_ran")) > + goto cleanup; > + > + if (!ASSERT_GT(bss->trace_printk_utf8_ret, 0, "bss->trace_printk_utf8_ret")) > + goto cleanup; > + > + if (!ASSERT_LT(bss->trace_printk_invalid_spec_ret, 0, > + "bss->trace_printk_invalid_spec_ret")) > + goto cleanup; > + > + /* verify our search strings are in the trace buffer */ > + ASSERT_OK(read_trace_pipe_iter(trace_pipe_cb, found, 1000), > + "read_trace_pipe_iter"); > + > + if (!ASSERT_EQ(found[0], bss->trace_printk_ran, "found")) > + goto cleanup; > > - if (!ASSERT_EQ(found, bss->trace_printk_ran, "found")) > + if (!ASSERT_EQ(found[1], bss->trace_printk_utf8_ran, "found_utf8")) > goto cleanup; > > cleanup: > diff --git a/tools/testing/selftests/bpf/progs/trace_printk.c b/tools/testing/selftests/bpf/progs/trace_printk.c > index 6695478c2b25..f4c538ec3ebd 100644 > --- a/tools/testing/selftests/bpf/progs/trace_printk.c > +++ b/tools/testing/selftests/bpf/progs/trace_printk.c > @@ -10,13 +10,23 @@ char _license[] SEC("license") = "GPL"; > > int trace_printk_ret = 0; > int trace_printk_ran = 0; > +int trace_printk_invalid_spec_ret = 0; > +int trace_printk_utf8_ret = 0; > +int trace_printk_utf8_ran = 0; > > const char fmt[] = "Testing,testing %d\n"; > +static const char utf8_fmt[] = "中文,测试 %d\n"; > +/* Non-ASCII bytes after '%' must still be rejected. */ > +static const char invalid_spec_fmt[] = "%\x80\n"; > > SEC("fentry/" SYS_PREFIX "sys_nanosleep") > int sys_enter(void *ctx) > { > trace_printk_ret = bpf_trace_printk(fmt, sizeof(fmt), > ++trace_printk_ran); > + trace_printk_utf8_ret = bpf_trace_printk(utf8_fmt, sizeof(utf8_fmt), > + ++trace_printk_utf8_ran); > + trace_printk_invalid_spec_ret = bpf_trace_printk(invalid_spec_fmt, > + sizeof(invalid_spec_fmt)); > return 0; > } > -- > 2.20.1 >