From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A5F1CEE49A4 for ; Mon, 21 Aug 2023 02:20:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232487AbjHUCUB (ORCPT ); Sun, 20 Aug 2023 22:20:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230271AbjHUCUB (ORCPT ); Sun, 20 Aug 2023 22:20:01 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 197059C; Sun, 20 Aug 2023 19:20:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id A402360B95; Mon, 21 Aug 2023 02:19:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 3AFF3C433C7; Mon, 21 Aug 2023 02:19:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1692584399; bh=J4aanHv8aL7g1z0TXMNl+0w14e+lIrlmCKs7x3Ij/r0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=VN3AACFBOgao56s96+LlpA/FzBfvdDMIDqOSVvVQpjQsgQHGrEtM9P69isiuz36F/ JnkbvVtvGAUjrVmbTsp/8+f8KEG5K67xkTL5pzzn7mRHEg1ri2yCeLrPFw9pVa//kF /enEupMCfDzL7gr4HMSxsBqOa+AbSVNBC8ZCO7+Ff7V/jJISCJH3jZFr34hVh3KrPR C2qnPA/cKSzF6l0crGTj06EJ8GG7nXzqlBHVViHYDR4StSTWf9sOZ86mSc2AtPOOs7 71xu+g0zJopcrshp/nRYzdZITyAktfRryD1Nq5S8DtbieXWnz8HMzTMhN8KRyYA8q0 e1Lu1MCYkRa0w== Date: Mon, 21 Aug 2023 11:19:54 +0900 From: Masami Hiramatsu (Google) To: Masami Hiramatsu (Google) Cc: Steven Rostedt , Zheng Yejian , , , Subject: Re: [PATCH v2] tracing: Introduce pipe_cpumask to avoid race on trace_pipes Message-Id: <20230821111954.8ca184e9fba62940825eb0e0@kernel.org> In-Reply-To: <20230819104257.80203c3916509cc9eb9327c1@kernel.org> References: <20230817115057.1637676-1-zhengyejian1@huawei.com> <20230818022645.1948314-1-zhengyejian1@huawei.com> <20230818140309.b0a720afa87b05a2b7b27315@kernel.org> <20230818094128.7cf1d58b@gandalf.local.home> <20230818232301.902ad9319569379ebd7df557@kernel.org> <20230818115322.3dfda470@gandalf.local.home> <20230819104257.80203c3916509cc9eb9327c1@kernel.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Precedence: bulk List-ID: X-Mailing-List: linux-trace-kernel@vger.kernel.org On Sat, 19 Aug 2023 10:42:57 +0900 Masami Hiramatsu (Google) wrote: > On Fri, 18 Aug 2023 11:53:22 -0400 > Steven Rostedt wrote: > > > On Fri, 18 Aug 2023 23:23:01 +0900 > > Masami Hiramatsu (Google) wrote: > > > > > It uses trace_pipe_raw. I guess if splice(from trace_pipe_raw to virtio-serial) > > > returns -1 and errno == EAGAIN, the trace data will be lost? > > > > It shouldn't. If it does, then there's likely a bug. The code will block > > and if an interrupt comes in it will return immediately without reading > > from the buffer. > > > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/trace/trace.c#n8262 > > > > I don't see where it would return -EINTR and consume data, but I may be > > missing something. > > Hmm, I suspect the case if the spilice_to_pipe() returns -EAGAIN. > > https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/kernel/trace/trace.c#n8491 > > It seems not handling such case. > > Anyway, I also think something wrong in virtio-serial (or misusing?), since > it can not read anything from the host sometimes. I just setup the virtio-trace > with below patch (ignore EAGAIN). > > > From 92242480285448360c9390a743ea7b3751bb3e61 Mon Sep 17 00:00:00 2001 > From: "Masami Hiramatsu (Google)" > Date: Thu, 17 Aug 2023 14:08:40 +0900 > Subject: [PATCH 1/3] tools/virtio-trace: Ignore EAGAIN error on splice() > > splice() can return EAGAIN error instead of returning 0 size read. > In that case, wait a while and try to call splice() again. > > Signed-off-by: Masami Hiramatsu (Google) > --- > tools/virtio/virtio-trace/trace-agent-rw.c | 7 ++++--- > 1 file changed, 4 insertions(+), 3 deletions(-) > > diff --git a/tools/virtio/virtio-trace/trace-agent-rw.c b/tools/virtio/virtio-trace/trace-agent-rw.c > index ddfe7875eb16..e8a4c4f0c499 100644 > --- a/tools/virtio/virtio-trace/trace-agent-rw.c > +++ b/tools/virtio/virtio-trace/trace-agent-rw.c > @@ -8,6 +8,7 @@ > */ > > #define _GNU_SOURCE > +#include > #include > #include > #include > @@ -127,10 +128,10 @@ static void *rw_thread_main(void *thread_info) > rlen = splice(ts->in_fd, NULL, ts->read_pipe, NULL, > ts->pipe_size, SPLICE_F_MOVE | SPLICE_F_MORE); > > - if (rlen < 0) { > - pr_err("Splice_read in rw-thread(%d)\n", ts->cpu_num); > + if (rlen < 0 && errno != EAGAIN) { > + pr_err("Splice_read error (%d) in rw-thread(%d)\n", errno, ts->cpu_num); > goto error; > - } else if (rlen == 0) { > + } else if (rlen == 0 || errno == EAGAIN) { Ah, this caused a drop. errno can be EAGAIN even if rlen > 0. I've fixed this and that works. BTW, I think this virtio-trace would be better to move under tools/tracing because it is a tracing tool. Thanks, > /* > * If trace data do not exist or are unreadable not > * for exceeding the page size, splice_read returns > -- > 2.34.1 > > > -- > Masami Hiramatsu (Google) -- Masami Hiramatsu (Google)