#
…

2021-03-08

00:22choozy has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
01:19PhilippvK has quit [Read error: Connection reset by peer]
01:19phiologe has joined #asahi
02:04marcanTheLink: dougall is around here too :)
02:31hspak has quit [Quit: bye]
02:34hspak has joined #asahi
03:03inglor has quit [Quit: https://quassel-irc.org - Chat comfortably. Anywhere.]
03:13inglor has joined #asahi
03:45_whitelogger has joined #asahi
03:48phiologe has quit [Ping timeout: 260 seconds]
03:48phiologe has joined #asahi
04:04marvin24_ has quit [Ping timeout: 240 seconds]
04:05marvin24 has joined #asahi
04:09nicolas17 has quit [Quit: Konversation terminated!]
05:03marvin24 has quit [Ping timeout: 260 seconds]
05:03marvin24 has joined #asahi
05:43odmir has joined #asahi
05:48odmir has quit [Ping timeout: 276 seconds]
06:30VinDuv has joined #asahi
06:32TheLinkyeah, realized that afterwards
06:52jeff_miw has joined #asahi
06:55jeff_miwsven: nice:)  I would like to help to get usb on m1n1, I have a macbook air, let me the best way to help there
06:56svendo you have a uart cable and feel like reading cursed usb specs? then we could see if there's a way for you to help write serial code.
06:57svenotherwise i'd be happy to have some people test this once i make a little more progress and implement the serial class
06:58svenhttps://www.ti.com/lit/ug/spruhj7a/spruhj7a.pdf this is a user manual for this dwc3 controller fwiw
07:02jeff_miwno uart cable with all the usb pd/vdm stuff ... but I can work how to get one if mandatory. no problem to read the cursed specs :)
07:02jeff_miwlet me know once you have something that makes sense to test
07:03svennah, no need to get one. i hope that i'll be able to finish at least an initial version of the serial part this week. after that most people probably won't need the pd uart cable anymore
07:04sveni'll let you know once i have something that is more useful than just printing what commands it receives over uart :)
07:12jeff_miw has quit [Ping timeout: 240 seconds]
07:28VinDuv has quit [Quit: Leaving.]
07:38marcansven: it shouldn't be too hard to do CDC serial AIUI
07:51svenyeah, i think once i have enumerating working CDC serial shouldn't be much more complicated
08:18vimal has quit [Ping timeout: 260 seconds]
08:30raster has joined #asahi
08:34mxw39 has quit [Quit: Konversation terminated!]
08:35vimal has joined #asahi
09:00josiahmendes[m] has quit [Quit: Idle for 30+ days]
09:00dyniec[m] has quit [Quit: Idle for 30+ days]
09:00mofux[m] has quit [Quit: Idle for 30+ days]
09:00mazmarcan: finally ironed out the annoying timer issue over the weekend, though the result isn't pretty at all. guests now work reliably.
09:01mazmarcan: I'll explore a solution that doesn't involve the magic timer LR though, as it prevents the emulation of some GICv3 features Linux relies on.
09:02mofux[m] has joined #asahi
09:21zkrx has quit [Ping timeout: 245 seconds]
09:22kettenissven: TI probably has slightly different glue logic for the dwc3 controller
09:24kettenisso not everything in that document will apply
09:27svenyeah, especially the PHY doesn't apply at all.
09:27svenbut the "USB Device (Peripheral) Programming Model" should be close enough
09:29svenif I do the phy init manually from m1n1 and use my dart driver in linux their dwc3 driver also works without any modifications in gadget mode fwiw
09:30j`eytheir = linux or?
09:30kettenisyou don't have to muck around with the i2c type-c controller?
09:30svennot for gadget mode
09:30svenbut I believe that's unfortunately required for host mode
09:31kettenisyeah, my attempts to use host mode failed to detect any devices
09:31svenyeah, same here
09:31kettenisno port status changes
09:31svenexactly
09:32kettenisthat's when I switched to looking at pcie
09:32svenI then switched to writing usb code for m1n1 because I was tired to wait for my kernels to load over uart
09:43spikebike55dddd:LK;'
09:49zkrx has joined #asahi
10:24marcanmaz: awesome! what's the exact issue?
10:24marcanI think qemu on macos works reliably without that LR stuff, only mask bits for the two timers, though I'm not entirely sure
10:25marcansven: the ports won't go into DFP mode without poking the type C controller
10:25marcansame reason you need to be DFP for serial in m1n1
10:25marcanthe controller doesn't have DFP negotiation enabled by default, so if you present to it as an UFP it just does nothing until macos boots
10:26marcanI bet it's not too hard of a dance though, and those things are mostly documented
10:26marcanthe linux driver for it should mostly just work
10:26marcanbut that does depend on i2c
10:26marcanwhich I guess is a very good reason to make that my next target
10:27marcan(need to poke around the pasemi i2c driver)
10:32Jangal has quit [Remote host closed the connection]
10:32Janhouse has joined #asahi
10:44mazmarcan: the main problem is that you can't inject a timer interrupt using that magic register. the Pending state is only driven by the timer itself, and only the Active state is writable.
10:45mazmarcan: so although we can save/restore the timer state correctly, including the GIC Active state, we can't pend an interrupt from SW, and Linux relies on that for interrupt resending.
10:46marcanah, so you can save/restore the timer counter state, but not the pending bit?
10:46mazmarcan: the GICv3 architecture mandates that you can write to the pending state and generate the corresponding interrupt, so that's pretty annoying.
10:46marcancould you force the issue by, say, setting it up to count down 0 ticks?
10:47mazmarcan: you don't need to save the pending bit itself. the state of the timer is enough to regenerate it.
10:47marcanbut wouldn't that be enough to inject the FIQ? AIUI it's level-triggered
10:47mazsetting TVAL to 0 would be observable by the guest, so that's a bit nono.
10:47marcanoh wait, you mean in that LR
10:48marcanI was talking about the timer IRQ flag itself in the control register
10:48marcanyeah. I noticed only one of the bits is writable in the LR
10:49mazso short of being able to set the Pending bit in the LR, we can't actually emulate the GICR_ISPENDING register for the virtual timer PPI.
10:49mazwhich is why I'm going to try and switch to just masking/unmasking the interrupt.
10:50mazand rely on a normal LR for injection.
10:50marcanthis is for emulating a normal GIC system, not the FIQ stuff, right?
10:50mazwe'll get a performance degradation because of the exit on EOI.
10:50mazI'm only concerved with GIC emulation, because that's the only thing KVM supports.
10:50mazin the kernel, that is.
10:50mazyou can obviously plug a userspace interrupt controller.
10:51marcanso I actually don't know at all how the timers interact with the vGIC stuff
10:51marcanor that magic LR register for that matter
10:51marcanso I need a bit of context :)
10:52marcanis that magic LR connected to the vGIC stuff?
10:52marcanoh, I guess what that HACR bit is redirect the vtimer from FIQ to that LR which then interacts with vGIC?
10:52marcan*bit does
10:53mazyes. the magic LR takes the timer output as its pending bit, and exposes the resulting interrupt in the guest via ICV_IAR*_EL1.
10:53marcanmakes sense
10:53marcanand what you're saying is we can't make the timer drive a pending state?
10:53mazit's a really nice shortcut in the sense that it doesn't generate an exit from the VM when the timer fires.
10:53vimal has quit [Quit: Leaving]
10:54mazbecause that pending state is *only* drive by the timer, SW can't inject an interrupt in that LR despite the timer not firing, which the GICv3 architecture allows.
10:55mazdriven*
10:55marcanhow would that be used? wouldn't the guest always expect the timer to be pending when it receives an IRQ?
10:56mazin the case of a level interrupt, that's not a huge problem. it's more for edge interrupt that it is problematic.
10:56marcanright, but these timers are level, right?
10:56mazbut in general writing to GICx_ISPENDING must generate an interrupt, full stop.
10:56mazand we can't do that for the timer.
10:57marcanoh, you mean if the guest writes that
10:57marcanargh, okay
10:58mazit really is a corner case, but deviating from the architecture is in general a very bad idea.
10:58marcancan we use a regular LR for that?
10:59mazyup, at the expense of using mask/unmask to prevent the timer from firing.
10:59mazwhich we need to do anyway for the physical timer, which doesn't have a magic LR.
11:00mazthe main disadvantage is that you need to force an exit whenever the guest EOI a timer interrupt in order to unmask the physical interrupt.
11:01marcancould we use both, somehow? use a regular LR to inject pending states if the guest asks us to, otherwise let the timer use the shortcut LR
11:01mazwhich we don't have to do on normal GIC implementations, as the HW knows how to link the virtual interrupt to the physical one.
11:01mazmarcan: it is illegal to have two LRs with the same INTID...
11:02marcanyes, but a lot of things are illegal about this architecture already...
11:02marcanworth trying it :)
11:02marcanI mean that magic register is already way out in IMP-DEF territory anyway
11:03mazsure, but if I can get decent perf with just mask/unmask, I'd be happy to just ditch the IMPDEF stuff.
11:03marcansure, works for me
11:03mazbecase this is a major hack in the vgic implementation, which is already a very complicated beast.
11:03marcanespecially for a first implementation
11:03marcanwe can worry about micro-optimizing this later if we need to
11:04marcanwhen we have a use case
11:21svenmarcan: nice, I'm pretty sure usb host most is just going to work as well then once you have that i2c figured out
11:46klaus has joined #asahi
11:52jaalsa has quit [Quit: jaalsa]
11:52jaalsa has joined #asahi
12:11raster has quit [Quit: Gettin' stinky!]
12:11raster has joined #asahi
12:16jeff_miw has joined #asahi
12:16nmg_ has quit [Ping timeout: 246 seconds]
12:18jeff_miwI tried to mess around to understand how macOS is managing the USB port but I failed miserably to have the boot/kernel to take my kext :(. if anyone has a good pointer to replace an existing original macOS by one hacked, I'm interested :)
12:23nmg has joined #asahi
12:25sventhere are really three components to it: That TI chip connected over i2c to select the mode (DFP,UFP), the PHY (apple calls this one "ATC" I think, essentially magic register pokes required before accessing the controller), and this designware did controller (xhci + configuration for host mode, custom stuff for device mode)
12:25svenpart three is well documented if you just look hard enough. part one is mostly documented as well I think (except for the i2c part) and part 2 is completely custom apple stuff afaict
12:26jeff_miw has quit [Ping timeout: 240 seconds]
12:26sven*designware drd
12:32raster has quit [Quit: Gettin' stinky!]
12:43arndmaz: how does qemu/hvf do it?
12:43arnddoes it need a similar hack?
12:43tomtastic_ has joined #asahi
12:43tomtastic has quit [Ping timeout: 240 seconds]
13:03Spiffy has quit [Quit: BRB]
13:04Spiffy has joined #asahi
13:12mazarnd: I have no idea, and to be honest I don't really want to know what macos does...
13:13mazarnd: from what I understand, HVF gives you a prety high-level interface to the vcpu, and can do a lot of stuff in the hypervisor layer.
13:13arndok, so it's not just emulated in qemu then
13:14mazarnd: I doubt it. performance would be absolutely terrible, similar to what we end-up with running KVM on a RPi3...
13:52marcanarnd, maz: as far as I know hypervisor.framework only deals with IRQ/FIQ, it does not do vGIC
13:52marcanso it should all be emulated in userspace
13:53marcanall you get is management of the pending IRQ state and the vtimer mask
13:53marcan"After receiving a HV_EXIT_REASON_VTIMER_ACTIVATED exit reason, the caller of hv_vcpu_run() needs to make the interrupts to the VTimer pending in the guest’s virtual interrupt controller."
13:57odmir has joined #asahi
13:57lethalbit has quit [Read error: Connection reset by peer]
13:59lethalbit has joined #asahi
14:42vimal has joined #asahi
14:50mazmarcan: it has to do *some* vgic in the kernel, as the LRs cannot be populated from EL0. from what I see, their interface is exactly the same as KVM, except for the timer (and I don't really understand why).
14:50marcanmaz: I think they don't do vgic at all, and it's all emulated in userspace?
14:51mazmarcan: to do the GIC in userspace, you'd need to pass the trapping of all ICV_* regs to userspace.
14:51mazplus the distributor and RD MMIO as well.
14:51mazare they actually doing that?
14:51mazthat'd seem... silly.
14:52mazwhy would they build a vgic the first place if they aren't using it...
14:52marcanbecause this launch was very, *very* obviously rushed
14:52marcanand they probably never got around to implementing it
14:53marcanbut there is nothing on IRQs in the API other than "IRQ, FIQ"
14:53mazthey don't have any exit reason for a trapped sysreg.
14:54mazI think you are confusing two different things: injecting a IRQ/FIQ directly, and injecting a GIC interrupt.
14:54marcanprobably HV_EXIT_REASON_EXCEPTION?
14:54mazhv_vcpu_set_pending_interrupt clearly injects a GIC interrupt, because there is an interrupt value provided to it.
14:55mazIRQ?FIQ is just the grouping here.
14:55marcanah, I think you're right
14:55maz(grouping in the GIC sense)
14:55marcanI skimmed too quickly there
14:56mazI think they have the distributor in userspace, while KVM has it in the kernel.
14:56marcanand in that case they probably don't use that magic LR
14:56mazand that explains why userspace needs to mediate the vtimer as well.
14:57marcanwait, no, are you sure?
14:58marcanthe structure is called hv_interrupt_type_t
14:58marcanI think this is just an enum wrapper
14:58marcanand it really is just IRQ and FIQ
14:58marcanrawValue being the enum value
14:58mazwhat is rawValue then?
14:58marcanIRQ, or FIQ
14:59marcanthat's really all there is to it
14:59mazthen I don't understand how this stuff works.
14:59marcanI think all the registers trap...
15:00marcanagraf would know :)
15:00mazgreat for performance... I'll stay with my in-kernel, non-trapping handling, thank you very much.,
15:04marcanmaz: I'm really looking forward to this, running a few benchmarks side by side on qemu/macos vs qemu/kvm will make for good clickbait ;)
15:04mazmarcan: qemu needs fixing, there is a stupid but with the reduce IPA space.
15:04mazreduced*
15:05mazkvmtool and crossvm are equially broken.
15:05j`eyqemu on linux on m1 you mean?
15:16raster has joined #asahi
15:21agrafmaz: I'm not aware of any hw backed GICv3 MSRs, but I haven't looked hard from EL2 either. HVF definitely just traps and delegates emulation to EL0 for everything. The only remotely irq related thing that's handled in-kernel is the arch timer, and that also just tells user space when it crossed cval.
15:24mazagraf: KVM directly uses all the vgic registers without any trapping.
15:25mazagraf: all the standard GICv3 stuff is there and seems functionnal.
15:25agrafmaz: oh, so they actually implemented all of it?
15:25agrafThat's funny - in a way :)
15:26mazagraf: just enough to have a guest that doesn't suck too much.
15:27mazagraf: they of course miss all the linked deactivation, but hey, sub-standard HW... ;-)
15:27agrafmaz: I'm definitely eager to see some comparison on native vgic vs the el0 loop for real world use cases. Probably has quite a nasty impact on IPI heavy bits
15:28agrafmaz: macos doesn't use any of the gic parts, so expect pitfalls as large as TX1 ;)
15:28agrafI'm fairly confident it's not fully verified ip
15:29mazagraf: running hackbench (as IPI-heavy as it gets) in a guest, I get a 6/7% overhead.
15:29mazoverhead compared to running on bare-metal.
15:30mazagraf: as for bugs, I'm planning to taint the kernel with CPU_OUT_OF_SPEC at KVM-init time.
15:44Hetflik[m] has joined #asahi
15:44never_released has quit [Changing host]
15:44never_released has joined #asahi
15:46marcanOUT_OF_SPEC?
15:46marcanwhat spec?
15:55never_releasedmaz: so there is a GICv3?
15:55never_releasedin addition to AIC?
16:00ldhacker[m] has quit [Quit: Idle for 30+ days]
16:00maznever_released: no. what's available is the ICH_*_EL2 and the ICV__EL1 registerse.
16:00mazregisters*
16:00maznever_released: you get enough to *virtualise* a GICv3.
16:01never_releasedmaz: pretty odd that macOS doesn't use that at all
16:01never_releasedand just traps all the regs to the VMM through Hypervisor.framework
16:01maznever_released: as agraf said, it's possible that it is totally broken.
16:02maznever_released: but as long as the traps work, we can deal with that in the kernel, where we have all the required emulation already.
16:02never_releasedknowing Apple, it's probably fully functional
16:05never_releasedI wonder if the reg to trap the GIC regs is known though
16:36zkrx has quit [Ping timeout: 245 seconds]
16:42maznever_released: ICH_HCR_EL2.T{ALL0,ALL1,C}.
16:45marvin24 has quit [Ping timeout: 260 seconds]
16:56modwizcode has quit [Ping timeout: 246 seconds]
17:00vimal has quit [Ping timeout: 246 seconds]
17:01zkrx has joined #asahi
17:03modwizcode has joined #asahi
17:03nmg has quit [Quit: ZNC 1.7.2+deb3 - https://znc.in]
17:03nmg has joined #asahi
17:04nicolas17 has joined #asahi
17:10marvin24 has joined #asahi
17:16marvin24 has quit [Ping timeout: 240 seconds]
17:16marvin24 has joined #asahi
17:19vimal has joined #asahi
17:35marcanI still bet it works ~fine and they just didn't make shipping for macos
17:35marcanI mean ffs, the version of macos that shipped on these things had some hideous brokenness in the boot process; everyone was screaming "update before you even dare do anything"
17:39marvin24 has quit [Ping timeout: 240 seconds]
17:40marvin24 has joined #asahi
17:47TheJollyRoger has quit [Quit: TheJollyRoger]
17:57VinDuv has joined #asahi
18:05mxw39 has joined #asahi
18:52aratuk has joined #asahi
18:54aratuk has quit [Remote host closed the connection]
19:20marcanwriting blog posts takes a while... I'm 3500 words into the progress report and I haven't even gotten to the linux kernel yet
19:20marcanhopefully I can mostly wrap that up tomorrow
19:28KindTwo has joined #asahi
19:31KindOne has quit [Ping timeout: 272 seconds]
19:31KindTwo is now known as KindOne
19:38TheJollyRoger has joined #asahi
19:42jn__wow, excellent
19:45klaus has quit [Ping timeout: 272 seconds]
20:31choozy has joined #asahi
20:40aratuk has joined #asahi
20:45aratuk has quit [Ping timeout: 245 seconds]
21:23raster has quit [Quit: Gettin' stinky!]
22:00amw has joined #asahi
22:02marvin24 has quit [Ping timeout: 240 seconds]
22:03marvin24 has joined #asahi
22:03eta has quit [Ping timeout: 245 seconds]
22:07artemist has quit [Ping timeout: 240 seconds]
22:09VinDuv has quit [Quit: Leaving.]
22:12eta has joined #asahi
23:10Guest56 has joined #asahi
23:48choozy has quit [Remote host closed the connection]
23:49richbridger has quit [Quit: Leaving]
23:50richbridger has joined #asahi
…