Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime-rs: add QMP support for Qemu(part I) #9604

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

Apokleos
Copy link
Contributor

@Apokleos Apokleos commented May 7, 2024

add support QMP socket in cmdline

Fixes: #9603

Signed-off-by: Alex Lyn alex.lyn@antgroup.com

@katacontainersbot katacontainersbot added the size/large Task of significant size label May 7, 2024
@Apokleos
Copy link
Contributor Author

Apokleos commented May 7, 2024

This patch can make kata/qemu running with qmp socket set well ! and the dumped cmdline as below:

/opt/kata/bin/qemu-system-x86_64 -name sandbox-1e28630de2b9b2e8bf22714561899249f6254fc8a9d167c454f3112f088a0710 -kernel /opt/kata/share/kata-containers/vmlinux-6.1.52-116 -append reboot=k panic=1 systemd.unit=kata-containers.target systemd.mask=systemd-networkd.service root=/dev/pmem0p1 rootflags=dax,data=ordered,errors=remount-ro ro rootfstype=ext4 -qmp unix:fd=14,server=on,wait=off -smp 1,maxcpus=6 -machine q35,accel=kvm,nvdimm=on -cpu host,pmu=off -m 2G,slots=128,maxmem=15668M -object memory-backend-file,id=entire-guest-memory-share,mem-path=/dev/shm,size=2G,share=on,readonly=off -rtc base=utc,clock=host,driftfix=slew -device vhost-vsock-pci,vhostfd=15,guest-cid=3259189863 -netdev tap,id=network-0,vhost=on,vhostfds=18,fds=17 -device virtio-net-pci,netdev=network-0,mac=9a:6a:d4:5f:60:60,mq=on,vectors=4 -chardev socket,id=virtiofsd-chardev,path=virtiofsd.sock -device vhost-user-fs-pci,chardev=virtiofsd-chardev,tag=kataShared -numa node,memdev=entire-guest-memory-share -object memory-backend-file,id=TODO,mem-path=/opt/kata/share/kata-containers/kata-ubuntu-latest.image,size=128M,share=off,readonly=on -device nvdimm,memdev=TODO,unarmed=on -device virtio-serial-pci,id=serial0 -device virtconsole,id=console0,chardev=charconsole0 -chardev socket,id=charconsole0,server=on,wait=off,path=console.sock -vga none -no-user-config -nodefaults -nographic -no-reboot

Copy link
Member

@BbolroC BbolroC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other than an ignorant question regarding a log message for validation. It looks good to me. Thanks @Apokleos !

// QMP listener file descriptor to be passed to qemu
pub fd: Option<File>,
// name is the socket name.
pub name: String,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing an fd and passing a name are mutually exclusive in QEMU. It is certainly possible to model that in a more idiomatic way.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I don't think we'll ever use both of these options, will we? We should leave out the one that we don't use. The rationale is again, unlike (the original) govmm our ambition is not a generic qemu support that can do whatever qemu can do - for the sake of simplicity, we only support what's actually useful for runtime-rs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, we can just use the unix:fd=xxx.. and no need to keep the name for unix:path=xx....
And I prepare to remove the field name in the next version.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMO, we can just use the unix:fd=xxx.. and no need to keep the name for unix:path=xx.... And I prepare to remove the field name in the next version.

Hold on. It is true that the primary QMP control point will only be unix:fd=XXX but the go runtime also offers the extra_monitor_socket configuration that allows to add an extra QMP/HMP control point for debugging purpose. The latter can only be unix:path=xx....

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right, that's a good point. We need to decide now whether the base and extra sockets share enough configuration to justify both being represented by the same struct - otherwise the extra socket might be better represented by a separate struct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@pmores @gkurz sure, I will take them into account !

@pmores
Copy link
Contributor

pmores commented May 7, 2024

@Apokleos Have you considered using an existing crate to take care of the low-level details of QMP? Maybe something like qapi-qmp could help us focus on what's important to us?

@Apokleos
Copy link
Contributor Author

Apokleos commented May 8, 2024

@Apokleos Have you considered using an existing crate to take care of the low-level details of QMP? Maybe something like qapi-qmp could help us focus on what's important to us?

Yes, you're right ! it seems fine to be the basis of QMP implementation for us and we don't need to reinvent the wheel with it.

@Apokleos Apokleos force-pushed the qmp-cmdline01 branch 2 times, most recently from b67794b to 2bfd42e Compare May 14, 2024 07:50
@Apokleos Apokleos requested review from gkurz, BbolroC and pmores May 14, 2024 07:54
@Apokleos
Copy link
Contributor Author

Hi @pmores @gkurz PTAL!

@@ -1212,6 +1320,8 @@ pub struct QemuCmdLine<'a> {
smp: Smp,
machine: Machine,
cpu: Cpu,
rtc: Rtc,
Copy link
Member

@BbolroC BbolroC May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was wondering why this item is added here even if it is added to devices below.

Copy link
Member

@gkurz gkurz May 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is certainly a rebase accident because rtc was just removed from there by #9571 😉

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry, I will fix it.

@@ -1228,6 +1296,9 @@ impl<'a> QemuCmdLine<'a> {
smp: Smp::new(config),
machine: Machine::new(config),
cpu: Cpu::new(config),
rtc: Rtc::new(),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

@@ -1437,6 +1508,10 @@ impl<'a> QemuCmdLine<'a> {
result.append(&mut self.machine.qemu_params().await?);
result.append(&mut self.cpu.qemu_params().await?);
result.append(&mut self.memory.qemu_params().await?);
result.append(&mut self.rtc.qemu_params().await?);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Copy link
Member

@gkurz gkurz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Apokleos , as explained in #9604 (comment) , the extra monitor socket must be created with unix:path=. The reason is that this extra control socket is to be used directly by the user with an external tool, e.g. nc. The shim won't need to pre-connect to the extra socket like it does with the primary one.

@Apokleos
Copy link
Contributor Author

@Apokleos , as explained in #9604 (comment) , the extra monitor socket must be created with unix:path=. The reason is that this extra control socket is to be used directly by the user with an external tool, e.g. nc. The shim won't need to pre-connect to the extra socket like it does with the primary one.

Ok, Thx Greg!

@Apokleos Apokleos force-pushed the qmp-cmdline01 branch 3 times, most recently from 8bcf53c to dd06917 Compare May 15, 2024 08:04
@Apokleos Apokleos requested a review from gkurz May 15, 2024 08:06
fn new() -> Result<Vec<Self>> {
let qmp_sockets: Vec<QmpSocket> = Vec::new();
let _proto = MonitorProtocol::new("qmp");
fn new(sid: &str, extra_monitor: bool) -> Result<Vec<Self>> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this works, however we now have a constructor that returns a container of instances instead of an instance - which is kind of unexpected. :-) Honestly I'd prefer if the QmpSocket::new() took the monitor protocol as a parameter and then returned a single instance as usual.

Then QmpSocket::fd and QmpSocket::name had probably better become a single member of an enum type since only one of them is ever needed.

Also, QemuCmdLine::new() would unconditionally create a QmpSocket instance for the Qmp socket and optionally, based on hypervisor config, another instance for Hmp, similar to how MMIO and RTC are already handled.

@@ -1299,7 +1352,7 @@ impl<'a> QemuCmdLine<'a> {
smp: Smp::new(config),
machine: Machine::new(config),
cpu: Cpu::new(config),
qmp_sockets: QmpSocket::new()?,
qmp_sockets: QmpSocket::new(id, false)?,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that the Qmp sockets should go to the anonymous devices container since QemuCmdLine doesn't need to interact with them anymore once they are created (@gkurz ?) so there's no need to hold them by name for future reference.

@pmores
Copy link
Contributor

pmores commented May 15, 2024

@Apokleos I proposed a bunch of structural changes - if you're fine with them but perhaps lack time to rework the PR to implement them we can merge as-is and I can make the changes subsequently. What do you think?

@Apokleos Apokleos added the wip Work in Progress (PR incomplete - needs more work or rework) label May 16, 2024
@Apokleos Apokleos force-pushed the qmp-cmdline01 branch 2 times, most recently from bf528f5 to f3139c6 Compare May 16, 2024 13:09
@Apokleos Apokleos removed the wip Work in Progress (PR incomplete - needs more work or rework) label May 17, 2024
@Apokleos Apokleos requested a review from pmores May 20, 2024 02:32
Copy link
Contributor

@pmores pmores left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, thanks @Apokleos !

(As a nit, I suspect the last two commits could be squashed however I leave that to your discretion.)

/// - "qmp-pretty" (same as "qmp" with pretty json formatting)
/// If set to the empty string "", no debug monitor socket is added. This is
/// the default.
/// dbg_monitor_socket = hmp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
/// dbg_monitor_socket = hmp
/// dbg_monitor_socket = "hmp"

Original config in go runtime also has this nit. No big deal.

This option allows to add a debug monitor socket when
`enable_debug = true` to control QEMU within debugging case.

Fixes: kata-containers#9603

Signed-off-by: Alex Lyn <alex.lyn@antgroup.com>
Fixes: kata-containers#9603

Signed-off-by: Alex Lyn <alex.lyn@antgroup.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ok-to-test size/large Task of significant size
Projects
None yet
Development

Successfully merging this pull request may close these issues.

runtime-rs: add QMP support for Qemu
6 participants