From: Sebastian Andrzej Siewior <bigeasy@linutronix.de>
To: Oliver Hartkopp <socketcan@hartkopp.net>
Cc: linux-can@vger.kernel.org, tglx@linutronix.de
Subject: Re: [RFC PATCH] can: gw: fix RCU/BH usage in cgw_create_job()
Date: Mon, 22 Jan 2024 11:10:37 +0100 [thread overview]
Message-ID: <20240122101037.FnYaYf7_@linutronix.de> (raw)
In-Reply-To: <b42b9988-98b5-411a-8493-b9d3d534c7d7@hartkopp.net>
On 2024-01-21 11:07:34 [+0100], Oliver Hartkopp wrote:
> On 2024-01-11 13:14, Sebastian Andrzej Siewior wrote:
>
> > Why are you afraid of doing
> > mod = kmalloc(sizeof(*mod), GFP_KERNEL);
> >
> > before invoking cgw_parse_attr()?
>
> The update of the modification content should be performed instantly and
> without any potential scheduling from kmalloc().
In most cases, the memory would be acquired without a delay. But if the
memory is tight it will get delayed over returning a NULL pointer and
(depending on the size) the NULL pointer can still be returned.
This code path is preemptible so the scheduler _can_ preempt the code in
favour of another task.
> As you pointed out one of the problems may arise from changing the
> modification functions but not from changing the modification content.
>
> So what about the below patch then?
Well, you do change parts of the data structure while the other side can
read it so I would say no. Also, in general there is no guarantee if the
memcpy() implementation copies the data from front or the end.
> Would a spin_lock() or spin_lock_bh() be an alternative to lock this update
> against the modification execution in can_can_gw_rcv()?
Yes, that is what locks are for. You would have to put the lock outside
of ccgw and acquire it before reading or writting ccgw.
> Best regards,
> Oliver
Sebastian
next prev parent reply other threads:[~2024-01-22 10:10 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-12-21 12:37 [RFC PATCH] can: gw: fix RCU/BH usage in cgw_create_job() Oliver Hartkopp
2024-01-11 12:14 ` Sebastian Andrzej Siewior
2024-01-21 10:07 ` Oliver Hartkopp
2024-01-22 10:10 ` Sebastian Andrzej Siewior [this message]
2024-04-29 9:47 ` Sebastian Andrzej Siewior
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=20240122101037.FnYaYf7_@linutronix.de \
--to=bigeasy@linutronix.de \
--cc=linux-can@vger.kernel.org \
--cc=socketcan@hartkopp.net \
--cc=tglx@linutronix.de \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.