From: Fedor Pchelkin <pchelkin@ispras.ru>
To: Robin Murphy <robin.murphy@arm.com>
Cc: Xiang Chen <chenxiang66@hisilicon.com>,
Barry Song <21cnbao@gmail.com>, Christoph Hellwig <hch@lst.de>,
Marek Szyprowski <m.szyprowski@samsung.com>,
iommu@lists.linux.dev, linux-kernel@vger.kernel.org,
Alexey Khoroshilov <khoroshilov@ispras.ru>,
lvc-project@linuxtesting.org
Subject: Re: [PATCH v2 1/4] dma-mapping: benchmark: fix up kthread-related error handling
Date: Wed, 15 May 2024 15:14:59 +0300 [thread overview]
Message-ID: <20240515-91223372820af49c191c67fc-pchelkin@ispras.ru> (raw)
In-Reply-To: <11456e13-23f8-43f7-8ffd-cd4e4ff825d7@arm.com>
Hi,
Thanks for review of the series!
Robin Murphy wrote:
> On 2024-05-04 12:47 pm, Fedor Pchelkin wrote:
> > kthread creation failure is invalidly handled inside do_map_benchmark().
> > The put_task_struct() calls on the error path are supposed to balance the
> > get_task_struct() calls which only happen after all the kthreads are
> > successfully created. Rollback using kthread_stop() for already created
> > kthreads in case of such failure.
> >
> > In normal situation call kthread_stop_put() to gracefully stop kthreads
> > and put their task refcounts. This should be done for all started
> > kthreads.
>
> Although strictly there were two overlapping bugs here, I'd agree that
> it really doesn't seem worth the bother of trying to distinguish them.
> I'm far from a kthread expert, but as best I can tell this looks like it
> achieves a sensible final state. Modulo one nit below,
>
> Reviewed-by: Robin Murphy <robin.murphy@arm.com>
>
> > Found by Linux Verification Center (linuxtesting.org).
> >
> > Fixes: 65789daa8087 ("dma-mapping: add benchmark support for streaming DMA APIs")
> > Suggested-by: Robin Murphy <robin.murphy@arm.com>
> > Signed-off-by: Fedor Pchelkin <pchelkin@ispras.ru>
> > ---
> > kernel/dma/map_benchmark.c | 16 ++++++++++------
> > 1 file changed, 10 insertions(+), 6 deletions(-)
> >
> > diff --git a/kernel/dma/map_benchmark.c b/kernel/dma/map_benchmark.c
> > index 02205ab53b7e..2478957cf9f8 100644
> > --- a/kernel/dma/map_benchmark.c
> > +++ b/kernel/dma/map_benchmark.c
> > @@ -118,6 +118,8 @@ static int do_map_benchmark(struct map_benchmark_data *map)
> > if (IS_ERR(tsk[i])) {
> > pr_err("create dma_map thread failed\n");
> > ret = PTR_ERR(tsk[i]);
> > + while (--i >= 0)
> > + kthread_stop(tsk[i]);
>
> I think this means we'd end up actually starting the threads purely to
> get them to see the KTHREAD_SHOULD_STOP flag and exit again? Not that
> I'm too fussed about optimising an unexpected error path, however I
> can't help but wonder if we might only need a put_task_struct() if we
> can safely assume that the threads have never been started at this point.
The threads have been already started to the moment by
kthread_create_on_node() but put to uninterruptible sleep: please see
kthread() function. They just have to be explicitly awakened, find that
the KTHREAD_SHOULD_STOP flag was set and perform do_exit() in order to
terminate and release all resources. The thread_fn won't be executed in
such case.
I feel there is no more convenient way for doing this differently than
calling kthread_stop(). And the comment for kthread_stop() actually implies
that it is intended to work also just after kthread creation.
Calling put_task_struct() in that place will hit WARN_ON(!tsk->exit_state).
I'd say the last call to this function should be made after (or in result
of) the do_exit().
next prev parent reply other threads:[~2024-05-15 12:24 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-05-04 11:47 [PATCH v2 0/4] dma-mapping: benchmark: fixes and error handling improvements Fedor Pchelkin
2024-05-04 11:47 ` [PATCH v2 1/4] dma-mapping: benchmark: fix up kthread-related error handling Fedor Pchelkin
2024-05-10 17:35 ` Robin Murphy
2024-05-15 12:14 ` Fedor Pchelkin [this message]
2024-05-04 11:47 ` [PATCH v2 2/4] dma-mapping: benchmark: avoid needless copy_to_user if benchmark fails Fedor Pchelkin
2024-05-10 17:52 ` Robin Murphy
2024-05-04 11:47 ` [PATCH v2 3/4] dma-mapping: benchmark: fix node id validation Fedor Pchelkin
2024-05-10 17:45 ` Robin Murphy
2024-05-04 11:47 ` [PATCH v2 4/4] dma-mapping: benchmark: handle NUMA_NO_NODE correctly Fedor Pchelkin
2024-05-07 6:56 ` Barry Song
2024-05-23 13:10 ` [PATCH v2 0/4] dma-mapping: benchmark: fixes and error handling improvements Christoph Hellwig
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240515-91223372820af49c191c67fc-pchelkin@ispras.ru \
--to=pchelkin@ispras.ru \
--cc=21cnbao@gmail.com \
--cc=chenxiang66@hisilicon.com \
--cc=hch@lst.de \
--cc=iommu@lists.linux.dev \
--cc=khoroshilov@ispras.ru \
--cc=linux-kernel@vger.kernel.org \
--cc=lvc-project@linuxtesting.org \
--cc=m.szyprowski@samsung.com \
--cc=robin.murphy@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).