Bug 259673 - ichwd does not detect qemu i6300esb virtual watchdog
Summary: ichwd does not detect qemu i6300esb virtual watchdog
Status: Open
Alias: None
Product: Base System
Classification: Unclassified
Component: kern (show other bugs)
Version: CURRENT
Hardware: amd64 Any
: --- Affects Some People
Assignee: freebsd-bugs (Nobody)
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-11-06 11:24 UTC by christi
Modified: 2022-12-26 01:18 UTC (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description christi 2021-11-06 11:24:33 UTC
I discovered this bug in FreeBSD 12.1 but was able to reproduce it using the latest FreeBSD daily qcows2 image.

Qemu has the facility to provide an emulated watchdog.  This shows up within a FreeBSD guest as follows (output of pciconf -v -l

    none0@pci0:0:4:0:       class=0x088000 card=0x11001af4 chip=0x25ab8086 rev=0x00 hdr=0x00
        vendor     = 'Intel Corporation'
        device     = '6300ESB Watchdog Timer'
        class      = base peripheral

If I enable ichwd by adding

    ichwd_enable="YES" 

to /boot/loader.conf, ichwd does not detect this "hardware".  The i6300ESB watchdog appears to be supported by ichwd, so it is not clear why this is not working.
Comment 1 Andriy Gapon freebsd_committer freebsd_triage 2021-11-07 08:59:05 UTC
(In reply to christi from comment #0)
Could you please share full output of pciconf -v -l?
Is there chip=0x25a18086 in it?
Comment 2 christi 2021-11-07 10:11:14 UTC
chip=0x25a18086 is not present.  This may be because QEMU does not emulate the entire i8300ESD chipset, just the watchdog device.  If ichwd is detecting by searching for the chipset rather than the watchdog specifically, that could explain why it is not being detected?

Full output from pciconf -v -l is:

hostb0@pci0:0:0:0:	class=0x060000 rev=0x02 hdr=0x00 vendor=0x8086 device=0x1237 subvendor=0x1af4 subdevice=0x1100
    vendor     = 'Intel Corporation'
    device     = '440FX - 82441FX PMC [Natoma]'
    class      = bridge
    subclass   = HOST-PCI
isab0@pci0:0:1:0:	class=0x060100 rev=0x00 hdr=0x00 vendor=0x8086 device=0x7000 subvendor=0x1af4 subdevice=0x1100
    vendor     = 'Intel Corporation'
    device     = '82371SB PIIX3 ISA [Natoma/Triton II]'
    class      = bridge
    subclass   = PCI-ISA
atapci0@pci0:0:1:1:	class=0x010180 rev=0x00 hdr=0x00 vendor=0x8086 device=0x7010 subvendor=0x1af4 subdevice=0x1100
    vendor     = 'Intel Corporation'
    device     = '82371SB PIIX3 IDE [Natoma/Triton II]'
    class      = mass storage
    subclass   = ATA
uhci0@pci0:0:1:2:	class=0x0c0300 rev=0x01 hdr=0x00 vendor=0x8086 device=0x7020 subvendor=0x1af4 subdevice=0x1100
    vendor     = 'Intel Corporation'
    device     = '82371SB PIIX3 USB [Natoma/Triton II]'
    class      = serial bus
    subclass   = USB
intsmb0@pci0:0:1:3:	class=0x068000 rev=0x03 hdr=0x00 vendor=0x8086 device=0x7113 subvendor=0x1af4 subdevice=0x1100
    vendor     = 'Intel Corporation'
    device     = '82371AB/EB/MB PIIX4 ACPI'
    class      = bridge
vgapci0@pci0:0:2:0:	class=0x030000 rev=0x02 hdr=0x00 vendor=0x1234 device=0x1111 subvendor=0x1af4 subdevice=0x1100
    class      = display
    subclass   = VGA
virtio_pci0@pci0:0:3:0:	class=0x00ff00 rev=0x00 hdr=0x00 vendor=0x1af4 device=0x1002 subvendor=0x1af4 subdevice=0x0005
    vendor     = 'Red Hat, Inc.'
    device     = 'Virtio memory balloon'
    class      = old
none0@pci0:0:4:0:	class=0x088000 rev=0x00 hdr=0x00 vendor=0x8086 device=0x25ab subvendor=0x1af4 subdevice=0x1100
    vendor     = 'Intel Corporation'
    device     = '6300ESB Watchdog Timer'
    class      = base peripheral
virtio_pci1@pci0:0:5:0:	class=0x010000 rev=0x00 hdr=0x00 vendor=0x1af4 device=0x1004 subvendor=0x1af4 subdevice=0x0008
    vendor     = 'Red Hat, Inc.'
    device     = 'Virtio SCSI'
    class      = mass storage
    subclass   = SCSI
virtio_pci2@pci0:0:18:0:	class=0x020000 rev=0x00 hdr=0x00 vendor=0x1af4 device=0x1000 subvendor=0x1af4 subdevice=0x0001
    vendor     = 'Red Hat, Inc.'
    device     = 'Virtio network device'
    class      = network
    subclass   = ethernet
pcib1@pci0:0:30:0:	class=0x060400 rev=0x00 hdr=0x01 vendor=0x1b36 device=0x0001 subvendor=0x0000 subdevice=0x0000
    vendor     = 'Red Hat, Inc.'
    device     = 'QEMU PCI-PCI bridge'
    class      = bridge
    subclass   = PCI-PCI
pcib2@pci0:0:31:0:	class=0x060400 rev=0x00 hdr=0x01 vendor=0x1b36 device=0x0001 subvendor=0x0000 subdevice=0x0000
    vendor     = 'Red Hat, Inc.'
    device     = 'QEMU PCI-PCI bridge'
    class      = bridge
    subclass   = PCI-PCI
Comment 3 Andriy Gapon freebsd_committer freebsd_triage 2021-11-07 22:24:00 UTC
(In reply to christi from comment #2)
Yes, that's how it works for physical hardware.  The driver searches for an LPC bridge devices instead of a watchdog device.  Apparently the driver needs to access configuration of the LPC device.
Comment 4 Andriy Gapon freebsd_committer freebsd_triage 2021-11-07 22:40:10 UTC
I made a quick look at Linux code and there is an interesting thing.
Linux has drivers/watchdog/iTCO_wdt.c driver which is roughly equivalent to FreeBSD ichwd and works approximately the same.  It's a "platform" driver and its configured via an LPC driver.
But additionally there is drivers/watchdog/i6300esb.c driver specifically for 6300ESB watchdog.  It attaches directly via PCI.

I am not sure if in the case of 6300ESB Linux has two drivers for the same hardware or if the hardware actually has multiple watchdogs...
Comment 5 Andriy Gapon freebsd_committer freebsd_triage 2021-11-08 09:50:50 UTC
Having looked at the 6300ESB datasheet, I believe that 0x25ab is a different watchdog.  It has a sufficiently different interface too.

So, the summary is:
- ichwd cannot support the qemu emulated watchdog, because it's different "hardware"
- FreeBSD currently does not have a driver that supports it
Comment 6 christi 2021-11-08 10:12:18 UTC
That seems very odd. Looking at the current source for ichwd.c at https://github.com/freebsd/freebsd-src/blob/main/sys/dev/ichwd/ichwd.c

Line 96 would appear to indicate the 6300esb is supported

   	{ DEVICEID_6300ESB,  "Intel 6300ESB watchdog timer",	5, 1 },

Line 110 also appears to indicate distinct 63xx support

	{ DEVICEID_63XXESB,  "Intel 63XXESB watchdog timer",	8, 2 },

Given that I think it would be quite surprising if ichwd didn't support it.  Whether or not the chipset was supported was of course something I looked into when debugging and as far as I can tell, support is there.
Comment 7 Andriy Gapon freebsd_committer freebsd_triage 2021-11-08 10:34:01 UTC
(In reply to christi from comment #6)
Please re-read my comments. ichwd supports a different watchdog module present in the real 6300ESB, a so called TCO watchdog.
Comment 8 Andriy Gapon freebsd_committer freebsd_triage 2021-11-08 10:36:26 UTC
In case I wasn't clear, real 6300ESB *chipset* contains two watchdogs.  FreeBSD supports only one of them while the qemu emulates the other.
Comment 9 christi 2021-11-08 10:38:56 UTC
Thank you.  That's clarified things.  Is there any possibility of porting over the Linux driver, please?
Comment 10 Ed Maste freebsd_committer freebsd_triage 2021-11-08 16:26:27 UTC
(In reply to christi from comment #9)

This would be a bespoke driver, not a port of the Linux driver (although perhaps done by using the latter as a reference). As the Linux driver is only about 200 LOC it seems like this would be a fairly straightforward endeavour.

That said, this is quite old hardware - I am surprised QEMU does not offer other usable watchdogs.

From qemu(1) I see:

       -watchdog model
              Create a virtual hardware watchdog device. Once enabled (by a
              guest action), the watchdog must be periodically polled by an
              agent inside the guest or else the guest will be restarted.
              Choose a model for which your guest has drivers.

              The model is the model of hardware watchdog to emulate. Use
              -watchdog help to list available hardware models. Only one
              watchdog can be enabled for a guest.

              The following models may be available:

              ib700  iBASE 700 is a very simple ISA watchdog with a single
                     timer.

              i6300esb
                     Intel 6300ESB I/O controller hub is a much more
                     featureful PCI-based dual-timer watchdog.

              diag288
                     A virtual watchdog for s390x backed by the diagnose 288
                     hypercall (currently KVM only).
Comment 11 christi 2021-11-08 18:18:14 UTC
I don't think any of the other qemu watchdogs are suitable.  The diag288 driver is for the IBM System 390 mainframe architecture, and I certainly wouldn't expect it to be supported on AMD64 (it's also not listed as an option in the production version of qemu I'm using running under Proxmox 6.4).

I have tried the ib700, but it is an ISA watchdog even older than the i6300esb and will not attach to my VM with a virtual PCI bus.  I think it's unlikely FreeBSD will support that even if I could get it working.  It does not appear in the list of ichwd supported watchdogs.

While I appreciate it's old physical hardware, it appears to have become the de facto qemu standard watchdog, and I don't think it's a particularly niche use case given that.  If I had the skills to write a driver myself, I'd be tempted to give it a go, but I think I have to acknowledge it's beyond my capabilities.
Comment 12 Ed Maste freebsd_committer freebsd_triage 2021-11-08 19:15:54 UTC
(In reply to christi from comment #11)
It looks like there is a virtio-watchdog supported by some VMMs and perhaps QEMU ought to grow support for this.

Anyhow, it does seem like support for i6300esb watchdog would be a useful addition to FreeBSD, but I am not aware of anyone who is likely to do so. I will keep it in mind though if an opportunity for a project comes up.
Comment 13 Andriy Gapon freebsd_committer freebsd_triage 2021-11-10 14:19:19 UTC
It would not be hard to write a driver, the hardware is sufficiently simple and well documented (public too).  Anyone who has time and some coding skills and interest (or some other motivation) could do it.