From: Michael Ellerman <mpe@ellerman•id.au>
To: Nathan Lynch <nathanl@linux•ibm.com>,
Tyrel Datwyler <tyreld@linux•ibm.com>,
linuxppc-dev@lists•ozlabs.org
Cc: cheloha@linux•ibm.com, ldufour@linux•ibm.com
Subject: Re: [PATCH v2] powerpc/pseries: explicitly reschedule during drmem_lmb list traversal
Date: Mon, 17 Aug 2020 13:45:52 +1000 [thread overview]
Message-ID: <87zh6u7x5b.fsf@mpe.ellerman.id.au> (raw)
In-Reply-To: <874kp7z73m.fsf@linux.ibm.com>
Nathan Lynch <nathanl@linux•ibm.com> writes:
> Michael Ellerman <mpe@ellerman•id.au> writes:
>> Tyrel Datwyler <tyreld@linux•ibm.com> writes:
>>> On 8/11/20 6:20 PM, Nathan Lynch wrote:
>>>>
>>>> +static inline struct drmem_lmb *drmem_lmb_next(struct drmem_lmb *lmb)
>>>> +{
>>>> + const unsigned int resched_interval = 20;
>>>> +
>>>> + BUG_ON(lmb < drmem_info->lmbs);
>>>> + BUG_ON(lmb >= drmem_info->lmbs + drmem_info->n_lmbs);
>>>
>>> I think BUG_ON is a pretty big no-no these days unless there is no other option.
>>
>> It's complicated, but yes we would like to avoid adding them if we can.
>>
>> In a case like this there is no other option, *if* the check has to be
>> in drmem_lmb_next().
>>
>> But I don't think we really need to check that there.
>>
>> If for some reason this was called with an *lmb pointing outside of the
>> lmbs array it would confuse the cond_resched() logic, but it's not worth
>> crashing the box for that IMHO.
>
> The BUG_ONs are pretty much orthogonal to the cond_resched().
Yes that was kind of my point. We don't need them to implement the
cond_resched() logic.
> It's not apparent from the context of the change, but some users of the
> for_each_drmem_lmb* macros modify elements of the drmem_info->lmbs
> array. If the lmb passed to drmem_lmb_next() violates the bounds check
> (say, if the callsite inappropriately modifies it within the loop), such
> users are guaranteed to corrupt other objects in memory. This was my
> thinking in adding the BUG_ONs, and I don't see another place to do
> it.
If it's really something we're worried about, I think we'd be better off
putting checks for that in the code that's doing those modifications.
That way you have enough context to do something more nuanced than a
BUG(), ie. you can print a useful message and fail whatever operation is
in progress.
If we did that then we could also add those BUG_ONs() as a safety net.
What you really want is a way for the for_each_xxx() construct to
express that there was an error traversing the list, but there isn't
really a nice way to do that in C.
cheers
prev parent reply other threads:[~2020-08-17 3:47 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-08-12 1:20 [PATCH v2] powerpc/pseries: explicitly reschedule during drmem_lmb list traversal Nathan Lynch
2020-08-12 5:19 ` Christophe Leroy
2020-08-12 13:46 ` Nathan Lynch
2020-08-12 14:26 ` Christophe Leroy
2020-08-12 16:22 ` Tyrel Datwyler
2020-08-13 0:28 ` Michael Ellerman
2020-08-13 1:07 ` Nathan Lynch
2020-08-17 3:45 ` Michael Ellerman [this message]
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=87zh6u7x5b.fsf@mpe.ellerman.id.au \
--to=mpe@ellerman$(echo .)id.au \
--cc=cheloha@linux$(echo .)ibm.com \
--cc=ldufour@linux$(echo .)ibm.com \
--cc=linuxppc-dev@lists$(echo .)ozlabs.org \
--cc=nathanl@linux$(echo .)ibm.com \
--cc=tyreld@linux$(echo .)ibm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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