mmind00 changed the topic of #linux-rockchip to: Rockchip development discussion | public log at https://libera.irclog.whitequark.org/linux-rockchip
kevery has joined #linux-rockchip
kevery1 has joined #linux-rockchip
kevery has quit [Read error: Connection reset by peer]
kevery1 has quit [Read error: Connection reset by peer]
kevery has joined #linux-rockchip
Daanct12 has joined #linux-rockchip
System_Error has quit [Remote host closed the connection]
System_Error has joined #linux-rockchip
Daanct12 has quit [Quit: WeeChat 4.2.1]
Daanct12 has joined #linux-rockchip
vagrantc has quit [Quit: leaving]
Daanct12 has quit [Quit: WeeChat 4.2.1]
Daanct12 has joined #linux-rockchip
System_Error has quit [Remote host closed the connection]
System_Error has joined #linux-rockchip
Daanct12 has quit [Quit: WeeChat 4.2.1]
Daanct12 has joined #linux-rockchip
warpme has joined #linux-rockchip
raster has joined #linux-rockchip
warpme has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
warpme has joined #linux-rockchip
ldevulder has joined #linux-rockchip
Livio has joined #linux-rockchip
Livio has quit [Ping timeout: 268 seconds]
ldevulder has quit [Quit: Leaving]
ldevulder has joined #linux-rockchip
warpme has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
stikonas has joined #linux-rockchip
warpme has joined #linux-rockchip
stikonas has quit [Client Quit]
Livio has joined #linux-rockchip
warpme has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
warpme has joined #linux-rockchip
naoki has quit [Quit: naoki]
kevery has quit [Ping timeout: 268 seconds]
Daanct12 has quit [Quit: WeeChat 4.2.1]
psydroid has joined #linux-rockchip
Daanct12 has joined #linux-rockchip
FergusL has quit [Quit: FergusL]
FergusL has joined #linux-rockchip
FergusL has quit [Quit: FergusL]
FergusL has joined #linux-rockchip
FergusL has quit [Quit: FergusL]
warpme has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
Daanct12 has quit [Quit: WeeChat 4.2.1]
FergusL has joined #linux-rockchip
Daanct12 has joined #linux-rockchip
warpme has joined #linux-rockchip
dsimic has quit [Ping timeout: 255 seconds]
crabbedhaloablut has quit []
dsimic has joined #linux-rockchip
crabbedhaloablut has joined #linux-rockchip
Livio has quit [Ping timeout: 272 seconds]
warpme has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
eballetbo has joined #linux-rockchip
<qschulz> Kwiboo: do you have a Gru Kevin/Bob?
<qschulz> Because I'm not entirely sure U-Boot is supposed to be self-sufficient on the Chromebooks, I've only ever read using it as a payload of coreboot
<qschulz> so I'd assume that U-Boot SPL runs in DRAM instead of SRAM?
<qschulz> (I have a Gru Bob, but it's still running ChromeOS /me hears the boos)
Net147 has quit [Quit: Quit]
Net147 has joined #linux-rockchip
Daanct12 has quit [Quit: WeeChat 4.2.1]
Net147 has quit [Changing host]
Net147 has joined #linux-rockchip
warpme has joined #linux-rockchip
<diederik> macromorgan: as the author of the original code, what do you think about this patch? https://paste.debian.net/1312806/
<diederik> I copied the last 2 lines to show that in your code you used `* 1000` in one part and `/ 1000` in another, which I assume was deliberate
<diederik> That patch is floating around for PineTab2, but maybe it ought to be upstream
raster has quit [Quit: Gettin' stinky!]
Stat_headcrabed has joined #linux-rockchip
<macromorgan> diederik: I believe you, but do you have an example of this occuring? I want to try and troubleshoot it a bit.
<macromorgan> basically I want to protect against 3 things... unsigned overflows, values less than logical, and values more than logical
<macromorgan> I figured that code I wrote would do all 3, but I guess it isn't
<CounterPillow> haven't read the code much but the kernel explicitly has helper macros to deal with overflow checking multiplies
<macromorgan> while somewhat arbitrary, I didn't figure we'd have batteries smaller than 500ma (I honestly don't remember but I think we can't even tell the columb counter about such batteries)
<macromorgan> right...and we're putting a 24bit unsigned int into a signed int... aren't signed ints 31?
<diederik> AFAIK the battery in the PineTab2 sometimes gave 'weird' values and that patch apparently fixed that. It was mostly the 'integer overflow' part which made me bring it to your attention as that's genrally not good
<macromorgan> yes
<macromorgan> I wonder how big the battery is in that, maybe it's bigger than I thought it could be
<CounterPillow> in this case using mult_frac from math.h would seem appropriate
<diederik> from the PineTab2 wiki page: Battery: 6000 mAh (22.2Wh)
<macromorgan> also the /1000 and *1000 is because the precision in the registers is done in mah not uah like the power infra expects
<macromorgan> the registers are actually arbitrary (we have more than enough nvram to store uah values), but BSP did it that way and I didn't want to break compatibility
<macromorgan> okay, I have an errand to run but I'll look at this a bit later today
<diederik> My remark with `/ 1000` or `* 1000` was that on line 718 you did `* 1000` but on line 722 you did `/ 1000` and the patch changed that to using `/ 1000` in both cases
<CounterPillow> If this is a case of an integer overflow, then overflows in calculations of different sized ints in a comparison go deep into the woods of the C standard integer promotion rules https://en.cppreference.com/w/c/language/conversion#Usual_arithmetic_conversions
<CounterPillow> Shuffling around which side of the equation you do multiply/divide on is kind of an icky "fix" in that case.
<diederik> good point :)
<CounterPillow> might be worth it to just do everything in 64 bit ints and search the kernel source for some overflow-checking multiply macro
<qschulz> diederik: there are other places where charger->bat_charge_full_design_uah / 1000 is used
<qschulz> so i guess the division is deemed safe (or the same mistake is made in multiple places)
<diederik> qschulz: yeah, I guess that's the reason for the change. But I agree with CP that it's an icky fix
<diederik> My eye caught it as some kind of anomaly. I'd expect the same construct everywhere, unless there's a reason to divert from it
<diederik> Which I expect there is; I just didn't know the reason
<qschulz> diederik: then all the division and multiplication in that driver should be checked and use the proper function :)
<diederik> Sounds reasonable :)
warpme has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
raster has joined #linux-rockchip
<macromorgan> in theory I think we always know (given the use of u8 reges) the maximum size of stuff. My question though is if our reg we're reading is 3 bytes, how does it overflow when cast into a 4 byte signed int? I'd love to see the case that triggers the error is all, I'm having a hard time understanding it (again I trust you that there IS a problem, I just don't understand it currently)
<macromorgan> actually hang on
<qschulz> macromorgan: you get a u24 and if you multiply it by 1000, it's more than what a u32 can contain
<macromorgan> yeah
<qschulz> macromorgan: >>> (1<<32)-1
<qschulz> 4294967295
<qschulz> >>> ((1<<24)-1) * 1000
<macromorgan> I see that now... duh
<qschulz> 16777215000
<macromorgan> had to break out the calculator, thank you, I'll look
<qschulz> macromorgan: what do you think I did just now :D
<diederik> I haven't seen it myself and the author of that patch has a PineTab2 v0.1 IIRC (not v2.0 like most), so it could be a pre-production error
Hypfer has quit [Quit: The Lounge - https://thelounge.github.io]
<macromorgan> so tl;dr a battery larger than 21Ah will cause the overflow
npcomp has quit [Ping timeout: 252 seconds]
s1b1 has quit [Quit: ZNC 1.8.2+deb3.1 - https://znc.in]
<macromorgan> let me confirm maximum supported in the datasheet... we'll either sanity check for the absolute maximum or instead check for overflows... both situations should prevent overflows
npcomp has joined #linux-rockchip
<macromorgan> ugg... okay, this is a bigger problem I guess I just never saw with smaller batteries
<macromorgan> who has a PineTab2 so I can ping them?
<diederik> I have one (4GB RAM/64GB eMMC)
s1b1 has joined #linux-rockchip
<macromorgan> I have a few values I should probably work on as long long int
<macromorgan> okay, let me tinker with some values
<macromorgan> first I'll try to identify the potental places where an overflow can occur
Stat_headcrabed has quit [Quit: Stat_headcrabed]
Segfault has joined #linux-rockchip
Segfault is now known as Segfault0
Segfault0 is now known as Segfault_0
<Segfault_0> hey i see there's discussion going on about the rk817 sanity check patch :P
<diederik> o/ (Segfault_0 is the author of that patch)
<Segfault_0> i don't remember much of the details and the tablet with corrupted nvram wasn't mine so i wasn't able to get much info but i do know without the change to the sanity check the driver was reporting POWER_SUPPLY_CHARGE_FULL=-424144184
<Segfault_0> i'm fairly sure there was an overflow going on but with how little info i had i wasn't able to check for sure so if there's something else happening instead that wouldn't surprise me lol
Hypfer has joined #linux-rockchip
Segfault_0 has quit [Quit: Client closed]
<macromorgan> yeah, that's definitely an overflow
<macromorgan> I'm trying to check if the code elsewhere does any overflows, while I see a bunch of spots where it COULD happen it looks like it takes really dumb values to get there. Like a sleep enter current of 63 amps
<macromorgan> or if the max amp hours is 10000, which also seems ridiculously high for this device
<macromorgan> so no using your RK817 to power your electric vehicles...
<macromorgan> looking at the nvram code now though, I know at one point I had a few overflows there but I thought I fixed them all
<macromorgan> maybe instead we just do (charger->fcc_mah > (charger->bat_charge_full_design_uah / 1000))
<macromorgan> basically does the same math, but gives us more room to breathe
<macromorgan> and allows us to hold 4000A, which seems like more than enough without having to do any additional changes or fancy math
<macromorgan> Segfault_0: did you already submit this patch upstream? If not I can do it.
<CounterPillow> macromorgan: please don't do this, use the checked overflow functions I linked
<CounterPillow> Or I guess if you're just dividing and everything is 32 bit it's fine
<CounterPillow> that is, if everything is unsigned
<CounterPillow> But I am uneasy about garbage in nvram producing negative numbers if these are signed ints
<diederik> Segfault didn't submit the patch upstream
<macromorgan> it only happens because we have 24 bits, which usually is perfectly fine but when we multiply by 1000 values greater than 16384mAh cause the overflow
<macromorgan> if we omit the multiplication step we don't get an overflow until we try more than 4294967mAH which is way out of spec and a condition we shouldn't encounter
<CounterPillow> where does the value come from? If from DT, okay, if from nvram, not okay
<macromorgan> checking for overflows is good... in my view making them impossible is better
<macromorgan> the 24 bit value is from nvram
<macromorgan> if we don't multiply by 1000 there's no way to get a 24 bit number to overflow
<CounterPillow> if the maximum number you can store in nvram does not cause an overflow then that's fine
<macromorgan> in a 32 bit int
<macromorgan> yes, the maximum is 24 bits
<macromorgan> we read 3 u8 values with regmap_bulk_read() to get that value
<CounterPillow> Make sure to an a -EINVAL return condition if it ever goes larger than the max int of 24 bits, because someone might change that code down the line and break the invariant :P
<macromorgan> I'm going to do one better and try to hard limit the acceptable values, plus i'll comment that function
<macromorgan> the 24bits is to preserve backwards compatibility with the BSP, otherwise I'd have done it different
<CounterPillow> Yeah that's fair
<macromorgan> okay... I'm not seeing anywhere else where an overflow can occur until you have a battery with more than 42Ah, which is about 4 times the size of a high capacity laptop battery. It will take a fair amount of work to prevent that from happening.
<macromorgan> For now it looks like the only opportunity for an overflow (aside from a fully charged 42Ah battery) is reading a value greater than 16M from the nvram
<macromorgan> I'll push a fix. Segfault_0, is that your name/email in this patch? https://paste.debian.net/1312806/
<diederik> Seems like he left already, so I'll answer it: yes
<macromorgan> okay, I see two potential fixes that are needed. One to sanity check values before we write to nvram, another to improve the sanity check of what we read back.
raster has quit [Quit: Gettin' stinky!]
<macromorgan> going to have to test it out now, but I'll at least start with the obvious that was reported upstream
stikonas has joined #linux-rockchip
System_Error has quit [Remote host closed the connection]
System_Error has joined #linux-rockchip
warpme has joined #linux-rockchip
warpme has quit [Quit: My MacBook has gone to sleep. ZZZzzz…]
vagrantc has joined #linux-rockchip
System_Error has quit [Remote host closed the connection]
System_Error has joined #linux-rockchip
Livio has joined #linux-rockchip
psydroid has quit [Quit: KVIrc 5.0.0 Aria http://www.kvirc.net/]
raster has joined #linux-rockchip
naoki has joined #linux-rockchip
raster has quit [Quit: Gettin' stinky!]
System_Error has quit [Remote host closed the connection]
vagrantc has quit [Quit: leaving]
System_Error has joined #linux-rockchip