Skip to contentSkip to conversation

lib/strtox: introduce kstrtoull_suffix() helper

PATCH Andy Shevchenko 2 participants 5 messages Dec 20, 2023 – Dec 21, 2023 Btrfs file system

lore
Share & tools
lore
#0 lore raw
Quoted 12 lines · Qu Wenruo
Quoted 10 lines · Alexey Dobriyan
Quoted 2 lines

Just as mentioned in the comment of memparse(), the simple_stroull() usage can lead to overflow all by itself.

which is the root cause...

I don't like one char suffixes. They are easy to integrate but then the _real_ suffixes are "MiB", "GiB", etc.

If you care only about memparse(), then using _parse_integer() can be arranged. I don't see why not.

Quoted 8 lines

Well, personally speaking I don't think we should even support the suffix at all, at least for the only two usage inside btrfs.

But unfortunately I'm not the one to do the final call, and the final call is to keep the suffix behavior...

And indeed using _parse_integer() with _parse_interger_fixup_radix() would be better, as we don't need to extend the _kstrtoull() code base.

My comment on the first patch got vanished due to my MTA issues, but I'll try to summarize my point here.

First of all, I do not like the naming, it's too vague. What kind of suffix? Do we suppose to have suffix in the input? What will be the behaviour w/o suffix? And so on...

Second, if it's a problem in memparse(), just fix it and that's all.

Third, as Alexey said, we have metric and byte suffixes and they are different. Supporting one without the other is just adding to the existing confusion.

Last, but not least, we do NOT accept new code in the lib/ without test cases.

So, that said here is my formal NAK for this series (at least in this form).

P.S> The Subject should start with either kstrtox: or lib/kstrtox.c.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#1 lore raw
Quoted 23 lines · Andy Shevchenko
Quoted 12 lines · Qu Wenruo
Quoted 10 lines · Alexey Dobriyan
Quoted 2 lines

Just as mentioned in the comment of memparse(), the simple_stroull() usage can lead to overflow all by itself.

which is the root cause...

I don't like one char suffixes. They are easy to integrate but then the _real_ suffixes are "MiB", "GiB", etc.

If you care only about memparse(), then using _parse_integer() can be arranged. I don't see why not.

Quoted 8 lines

Well, personally speaking I don't think we should even support the suffix at all, at least for the only two usage inside btrfs.

But unfortunately I'm not the one to do the final call, and the final call is to keep the suffix behavior...

And indeed using _parse_integer() with _parse_interger_fixup_radix() would be better, as we don't need to extend the _kstrtoull() code base.

Quoted 6 lines

My comment on the first patch got vanished due to my MTA issues, but I'll try to summarize my point here.

First of all, I do not like the naming, it's too vague. What kind of suffix? Do we suppose to have suffix in the input? What will be the behaviour w/o suffix? And so on...

I really like David Sterb to hear this though.

To me, we should mark memparse() as deprecated as soon as possible, not spreading the damn pandemic to any newer code.

The "convenience" is not an excuse to use incorrect code.

Quoted 2 lines

Second, if it's a problem in memparse(), just fix it and that's all.

Nope, the memparse() itself doesn't have any way to indicate errors.

It's not fixable in the first place, as long as you want a drop-in solution.

Quoted 7 lines

Third, as Alexey said, we have metric and byte suffixes and they are different. Supporting one without the other is just adding to the existing confusion.

Last, but not least, we do NOT accept new code in the lib/ without test cases.

So, that said here is my formal NAK for this series (at least in this form).

Then why there is the hell of memparse() in the first place? It doesn't have test case (we have cmdline_kunit, but it doesn't test memparse() at all), nor the proper error detection.

I'm fine to get my patch rejected, but why the hell of memparse() is here in the first place?
It doesn't fit any of the standard you mentioned.

Thanks,
Qu

Quoted 3 lines

P.S> The Subject should start with either kstrtox: or lib/kstrtox.c.

#2 lore raw
Quoted 23 lines · Qu Wenruo
Quoted 22 lines · Andy Shevchenko
Quoted 20 lines · Qu Wenruo
Quoted 10 lines · Alexey Dobriyan
Quoted 2 lines

Just as mentioned in the comment of memparse(), the simple_stroull() usage can lead to overflow all by itself.

which is the root cause...

I don't like one char suffixes. They are easy to integrate but then the _real_ suffixes are "MiB", "GiB", etc.

If you care only about memparse(), then using _parse_integer() can be arranged. I don't see why not.

Well, personally speaking I don't think we should even support the suffix at all, at least for the only two usage inside btrfs.

But unfortunately I'm not the one to do the final call, and the final call is to keep the suffix behavior...

And indeed using _parse_integer() with _parse_interger_fixup_radix() would be better, as we don't need to extend the _kstrtoull() code base.

Quoted 8 lines
Quoted 6 lines

My comment on the first patch got vanished due to my MTA issues, but I'll try to summarize my point here.

First of all, I do not like the naming, it's too vague. What kind of suffix? Do we suppose to have suffix in the input? What will be the behaviour w/o suffix? And so on...

I really like David Sterb to hear this though.

Me too, I like to hear opinions. But I will fight for the best we can do here.

Quoted 2 lines

To me, we should mark memparse() as deprecated as soon as possible, not spreading the damn pandemic to any newer code.

Send a patch!

Quoted 1 line

The "convenience" is not an excuse to use incorrect code.

I do not object this.

Quoted 6 lines
Quoted 1 line

Second, if it's a problem in memparse(), just fix it and that's all.

Nope, the memparse() itself doesn't have any way to indicate errors.

It's not fixable in the first place, as long as you want a drop-in solution.

Quoted 8 lines
Quoted 6 lines

Third, as Alexey said, we have metric and byte suffixes and they are different. Supporting one without the other is just adding to the existing confusion.

Last, but not least, we do NOT accept new code in the lib/ without test cases.

So, that said here is my formal NAK for this series (at least in this form).

Then why there is the hell of memparse() in the first place?

You have all means to investigate.
It used to be setup_mem() till 9b0f5889b12b ("Linux 2.2.18pre9"), which in turn was split from setup_arch() in 716454f016a9 ("Import 2.1.121pre1")... Looking deeper seems it comes as a parser at hand for the mem= command line parameter very long time ago.

Quoted 2 lines

It doesn't have test case (we have cmdline_kunit, but it doesn't test memparse() at all), nor the proper error detection.

Exactly! Someone's job to add this. And the best is the one who touches the code. See how cmdline_kunit appears.

Quoted 3 lines

I'm fine to get my patch rejected, but why the hell of memparse() is here in the first place?
It doesn't fit any of the standard you mentioned.

So, what standard did we have in above mentioned (prehistorical) time?

Quoted 1 line
Quoted 1 line

P.S> The Subject should start with either kstrtox: or lib/kstrtox.c.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#3 lore raw
Quoted 68 lines · Andy Shevchenko
Quoted 23 lines · Qu Wenruo
Quoted 22 lines · Andy Shevchenko
Quoted 20 lines · Qu Wenruo
Quoted 10 lines · Alexey Dobriyan
Quoted 2 lines

Just as mentioned in the comment of memparse(), the simple_stroull() usage can lead to overflow all by itself.

which is the root cause...

I don't like one char suffixes. They are easy to integrate but then the _real_ suffixes are "MiB", "GiB", etc.

If you care only about memparse(), then using _parse_integer() can be arranged. I don't see why not.

Well, personally speaking I don't think we should even support the suffix at all, at least for the only two usage inside btrfs.

But unfortunately I'm not the one to do the final call, and the final call is to keep the suffix behavior...

And indeed using _parse_integer() with _parse_interger_fixup_radix() would be better, as we don't need to extend the _kstrtoull() code base.

Quoted 8 lines
Quoted 6 lines

My comment on the first patch got vanished due to my MTA issues, but I'll try to summarize my point here.

First of all, I do not like the naming, it's too vague. What kind of suffix? Do we suppose to have suffix in the input? What will be the behaviour w/o suffix? And so on...

I really like David Sterb to hear this though.

Me too, I like to hear opinions. But I will fight for the best we can do here.

Quoted 2 lines

To me, we should mark memparse() as deprecated as soon as possible, not spreading the damn pandemic to any newer code.

Send a patch!

Quoted 1 line

The "convenience" is not an excuse to use incorrect code.

I do not object this.

Quoted 6 lines
Quoted 1 line

Second, if it's a problem in memparse(), just fix it and that's all.

Nope, the memparse() itself doesn't have any way to indicate errors.

It's not fixable in the first place, as long as you want a drop-in solution.

Quoted 8 lines
Quoted 6 lines

Third, as Alexey said, we have metric and byte suffixes and they are different. Supporting one without the other is just adding to the existing confusion.

Last, but not least, we do NOT accept new code in the lib/ without test cases.

So, that said here is my formal NAK for this series (at least in this form).

Then why there is the hell of memparse() in the first place?

You have all means to investigate.
It used to be setup_mem() till 9b0f5889b12b ("Linux 2.2.18pre9"), which in turn was split from setup_arch() in 716454f016a9 ("Import 2.1.121pre1")... Looking deeper seems it comes as a parser at hand for the mem= command line parameter very long time ago.

Quoted 2 lines

It doesn't have test case (we have cmdline_kunit, but it doesn't test memparse() at all), nor the proper error detection.

Quoted 8 lines

Exactly! Someone's job to add this. And the best is the one who touches the code. See how cmdline_kunit appears.

Quoted 3 lines

I'm fine to get my patch rejected, but why the hell of memparse() is here in the first place?
It doesn't fit any of the standard you mentioned.

So, what standard did we have in above mentioned (prehistorical) time?

Fine, there is no standard in the ancient days.

Then what about going the following path for the whole memparse() rabbit hole?

- Mark the old memparse() deprecated
- Add a new function memparse_safe() (or rename the older one to __memparse, and let the new one to be named memparse()?)
- Add unit test for the new memparse_safe() or whatever the name is
- Try my best to migrate as many call sites as possible Only the two btrfs ones I'm 100% confident for now

Would that be a sounding plan?

Thanks,
Qu

Quoted 3 lines
Quoted 2 lines
Quoted 2 lines

P.S> The Subject should start with either kstrtox: or lib/kstrtox.c.

#4 lore raw
Quoted 1 line · Qu Wenruo

On 2023/12/21 22:30, Andy Shevchenko wrote:

...

Quoted 11 lines

Then what about going the following path for the whole memparse() rabbit hole?

- Mark the old memparse() deprecated
- Add a new function memparse_safe() (or rename the older one to __memparse, and let the new one to be named memparse()?)
- Add unit test for the new memparse_safe() or whatever the name is
- Try my best to migrate as many call sites as possible Only the two btrfs ones I'm 100% confident for now

Would that be a sounding plan?

As long as it does not break any ABI (like kernel command line parsing), sounds good to me.

Signature · 2 lines
With Best Regards,
Andy Shevchenko