From nobody Wed Apr 10 15:19:06 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4VF61Q5NDhz5HHK8; Wed, 10 Apr 2024 15:19:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4VF61Q443cz4n1g; Wed, 10 Apr 2024 15:19:06 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712762346; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=CUdEf4XT+cH1ZygvR2vNg0KX+90/FfllM0U6d7FL0W4=; b=Wn0A2CkFQur2S7hvmEIw1g1D9b2whNRu5hfoaUAjpICiKxCz/fvgHNj0NK0n7aiMGI0R7Q TAvMEp5+VRQQLicex9pfMgo/Tl1ZEJQwvkev/Q6tc//SGgUgdwL6+zEmubg9YDKoSowUhL UO8cNrxC4ph35FtXd8ZnrCExmahPCsfopDKjkNmHU6r+duFbQ59ZnkgAV1ViNgOki4Z9Nf ArpCT8Ggp893rOaJh+7DNak2ujv5HmgBzoXjkDflhoY08+7jDuRpzVTCYuLvXSan0GRI05 vMYAFBVYIq+mcSsHxYsjxiVUeUKXpeeTvlKasKhia0237qu358VADrfAZBor9g== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1712762346; a=rsa-sha256; cv=none; b=G0Ndvri4Upulsm/htfpav4H4hQfTYdgd5cf1k3u8GW9qcQP+WVYvLG/dgsqXwmcinaPbjr 9XphHmJFPd/ZuK3HwvR5/UA6mxgefhn/QNzjRKrxuwgE0LTiN0PdUbvButnyIsmLL5a49q jccXV/SHMyJAoV7QLygj0tZUgkmbN5CxHSiMoh9tsDxHM9w2wkg5zAua2in0sPS+u/csMR bjaqpJyLFTaqKR3jjbVjaEb0u8R60BdLwAwbwPDgnVY87WQKtdeOHo1q374InsIHO2dMFo 0l/C1STyjIyxnMxJwhwYN0Gj1354qEUK30KpjuV+yCe0522KzktRQp3t/9PgeQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1712762346; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=CUdEf4XT+cH1ZygvR2vNg0KX+90/FfllM0U6d7FL0W4=; b=GcBu9RR83Wqz83CYObYb0pyJUHRFInUeoc2MQAAB8CB0Lfk+AiMb9Z68bCjqwYmJQLwyXp uqL7/MtqYucxwsmAhMYFfZVcG3TzHcW2vwG44svv2v75hJvWWdFNclAtqHmwWHKlo7ksRi aAa8vwHKtKpQ8Gs3ChoasHWfofbb5LHSohC8nBhoEyeSAIrm4Lwa5ftkB70Nc/qSQS+plh +4eSYXkm+UHlkaTPq6ag1IKVm96ewedSSlDwpqYbS2QASHIRFtqiI32kT1vO79vXnIbRYa kuHoXIj2y0cTITWErIyCwkZ43ggNn+gkOXt6Jp+vz/aRrpQfnQIYmoNAS3QNzQ== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4VF61Q3hM5zjlm; Wed, 10 Apr 2024 15:19:06 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 43AFJ6M9092853; Wed, 10 Apr 2024 15:19:06 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 43AFJ6AA092850; Wed, 10 Apr 2024 15:19:06 GMT (envelope-from git) Date: Wed, 10 Apr 2024 15:19:06 GMT Message-Id: <202404101519.43AFJ6AA092850@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 7f00e46b85e8 - main - libvmmapi: Split the ioctl list into MI and MD lists List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: dev-commits-src-main+owner@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 7f00e46b85e8c60259ad0bdd53593ea246f3e549 Auto-Submitted: auto-generated The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=7f00e46b85e8c60259ad0bdd53593ea246f3e549 commit 7f00e46b85e8c60259ad0bdd53593ea246f3e549 Author: Mark Johnston AuthorDate: 2024-04-03 16:55:54 +0000 Commit: Mark Johnston CommitDate: 2024-04-10 15:17:56 +0000 libvmmapi: Split the ioctl list into MI and MD lists To enable use in capability mode, libvmmapi needs a list of all the ioctls that might be invoked on the vmm device handle. Some of these ioctls are amd64-specific. Move the ioctl list to vmmapi_machdep.c and define a list of MI ioctls so that the arm64 port can build its own list without duplicating common ioctls. No functional change intended. Reviewed by: corvink, jhb MFC after: 2 weeks Sponsored by: Innovate UK Differential Revision: https://reviews.freebsd.org/D41001 --- lib/libvmmapi/amd64/vmmapi_machdep.c | 34 +++++++++++++++++++++++++ lib/libvmmapi/internal.h | 48 ++++++++++++++++++++++++++++++++++++ lib/libvmmapi/vmmapi.c | 37 +++++---------------------- 3 files changed, 88 insertions(+), 31 deletions(-) diff --git a/lib/libvmmapi/amd64/vmmapi_machdep.c b/lib/libvmmapi/amd64/vmmapi_machdep.c index c19e9c6f935f..2b50b2b1f3b7 100644 --- a/lib/libvmmapi/amd64/vmmapi_machdep.c +++ b/lib/libvmmapi/amd64/vmmapi_machdep.c @@ -31,6 +31,8 @@ #include #include +#include +#include #include @@ -52,6 +54,38 @@ const char *vm_capstrmap[] = { [VM_CAP_MAX] = NULL, }; +#define VM_MD_IOCTLS \ + VM_SET_SEGMENT_DESCRIPTOR, \ + VM_GET_SEGMENT_DESCRIPTOR, \ + VM_SET_KERNEMU_DEV, \ + VM_GET_KERNEMU_DEV, \ + VM_LAPIC_IRQ, \ + VM_LAPIC_LOCAL_IRQ, \ + VM_LAPIC_MSI, \ + VM_IOAPIC_ASSERT_IRQ, \ + VM_IOAPIC_DEASSERT_IRQ, \ + VM_IOAPIC_PULSE_IRQ, \ + VM_IOAPIC_PINCOUNT, \ + VM_ISA_ASSERT_IRQ, \ + VM_ISA_DEASSERT_IRQ, \ + VM_ISA_PULSE_IRQ, \ + VM_ISA_SET_IRQ_TRIGGER, \ + VM_INJECT_NMI, \ + VM_SET_X2APIC_STATE, \ + VM_GET_X2APIC_STATE, \ + VM_GET_HPET_CAPABILITIES, \ + VM_RTC_WRITE, \ + VM_RTC_READ, \ + VM_RTC_SETTIME, \ + VM_RTC_GETTIME + +const cap_ioctl_t vm_ioctl_cmds[] = { + VM_COMMON_IOCTLS, + VM_PPT_IOCTLS, + VM_MD_IOCTLS, +}; +size_t vm_ioctl_ncmds = nitems(vm_ioctl_cmds); + int vm_set_desc(struct vcpu *vcpu, int reg, uint64_t base, uint32_t limit, uint32_t access) diff --git a/lib/libvmmapi/internal.h b/lib/libvmmapi/internal.h index 973a70afe022..98e50f9a1bf4 100644 --- a/lib/libvmmapi/internal.h +++ b/lib/libvmmapi/internal.h @@ -7,6 +7,8 @@ #ifndef __VMMAPI_INTERNAL_H__ #define __VMMAPI_INTERNAL_H__ +#include + struct vmctx { int fd; uint32_t lowmem_limit; @@ -26,4 +28,50 @@ int vcpu_ioctl(struct vcpu *vcpu, u_long cmd, void *arg); extern const char *vm_capstrmap[]; +#define VM_COMMON_IOCTLS \ + VM_RUN, \ + VM_SUSPEND, \ + VM_REINIT, \ + VM_ALLOC_MEMSEG, \ + VM_GET_MEMSEG, \ + VM_MMAP_MEMSEG, \ + VM_MMAP_MEMSEG, \ + VM_MMAP_GETNEXT, \ + VM_MUNMAP_MEMSEG, \ + VM_SET_REGISTER, \ + VM_GET_REGISTER, \ + VM_SET_REGISTER_SET, \ + VM_GET_REGISTER_SET, \ + VM_INJECT_EXCEPTION, \ + VM_SET_CAPABILITY, \ + VM_GET_CAPABILITY, \ + VM_STATS, \ + VM_STAT_DESC, \ + VM_GET_GPA_PMAP, \ + VM_GLA2GPA, \ + VM_GLA2GPA_NOFAULT, \ + VM_ACTIVATE_CPU, \ + VM_GET_CPUS, \ + VM_SUSPEND_CPU, \ + VM_RESUME_CPU, \ + VM_SET_INTINFO, \ + VM_GET_INTINFO, \ + VM_RESTART_INSTRUCTION, \ + VM_SET_TOPOLOGY, \ + VM_GET_TOPOLOGY, \ + VM_SNAPSHOT_REQ, \ + VM_RESTORE_TIME + +#define VM_PPT_IOCTLS \ + VM_BIND_PPTDEV, \ + VM_UNBIND_PPTDEV, \ + VM_MAP_PPTDEV_MMIO, \ + VM_PPTDEV_MSI, \ + VM_PPTDEV_MSIX, \ + VM_UNMAP_PPTDEV_MMIO, \ + VM_PPTDEV_DISABLE_MSIX + +extern const cap_ioctl_t vm_ioctl_cmds[]; +extern size_t vm_ioctl_ncmds; + #endif /* !__VMMAPI_INTERNAL_H__ */ diff --git a/lib/libvmmapi/vmmapi.c b/lib/libvmmapi/vmmapi.c index cc765deb904c..db442a4cd94f 100644 --- a/lib/libvmmapi/vmmapi.c +++ b/lib/libvmmapi/vmmapi.c @@ -1351,42 +1351,15 @@ vm_get_topology(struct vmctx *ctx, return (error); } -/* Keep in sync with machine/vmm_dev.h. */ -static const cap_ioctl_t vm_ioctl_cmds[] = { VM_RUN, VM_SUSPEND, VM_REINIT, - VM_ALLOC_MEMSEG, VM_GET_MEMSEG, VM_MMAP_MEMSEG, VM_MMAP_MEMSEG, - VM_MMAP_GETNEXT, VM_MUNMAP_MEMSEG, VM_SET_REGISTER, VM_GET_REGISTER, - VM_SET_SEGMENT_DESCRIPTOR, VM_GET_SEGMENT_DESCRIPTOR, - VM_SET_REGISTER_SET, VM_GET_REGISTER_SET, - VM_SET_KERNEMU_DEV, VM_GET_KERNEMU_DEV, - VM_INJECT_EXCEPTION, VM_LAPIC_IRQ, VM_LAPIC_LOCAL_IRQ, - VM_LAPIC_MSI, VM_IOAPIC_ASSERT_IRQ, VM_IOAPIC_DEASSERT_IRQ, - VM_IOAPIC_PULSE_IRQ, VM_IOAPIC_PINCOUNT, VM_ISA_ASSERT_IRQ, - VM_ISA_DEASSERT_IRQ, VM_ISA_PULSE_IRQ, VM_ISA_SET_IRQ_TRIGGER, - VM_SET_CAPABILITY, VM_GET_CAPABILITY, VM_BIND_PPTDEV, - VM_UNBIND_PPTDEV, VM_MAP_PPTDEV_MMIO, VM_PPTDEV_MSI, - VM_PPTDEV_MSIX, VM_UNMAP_PPTDEV_MMIO, VM_PPTDEV_DISABLE_MSIX, - VM_INJECT_NMI, VM_STATS, VM_STAT_DESC, - VM_SET_X2APIC_STATE, VM_GET_X2APIC_STATE, - VM_GET_HPET_CAPABILITIES, VM_GET_GPA_PMAP, VM_GLA2GPA, - VM_GLA2GPA_NOFAULT, - VM_ACTIVATE_CPU, VM_GET_CPUS, VM_SUSPEND_CPU, VM_RESUME_CPU, - VM_SET_INTINFO, VM_GET_INTINFO, - VM_RTC_WRITE, VM_RTC_READ, VM_RTC_SETTIME, VM_RTC_GETTIME, - VM_RESTART_INSTRUCTION, VM_SET_TOPOLOGY, VM_GET_TOPOLOGY, - VM_SNAPSHOT_REQ, VM_RESTORE_TIME -}; - int vm_limit_rights(struct vmctx *ctx) { cap_rights_t rights; - size_t ncmds; cap_rights_init(&rights, CAP_IOCTL, CAP_MMAP_RW); if (caph_rights_limit(ctx->fd, &rights) != 0) return (-1); - ncmds = nitems(vm_ioctl_cmds); - if (caph_ioctls_limit(ctx->fd, vm_ioctl_cmds, ncmds) != 0) + if (caph_ioctls_limit(ctx->fd, vm_ioctl_cmds, vm_ioctl_ncmds) != 0) return (-1); return (0); } @@ -1407,15 +1380,17 @@ const cap_ioctl_t * vm_get_ioctls(size_t *len) { cap_ioctl_t *cmds; + size_t sz; if (len == NULL) { - cmds = malloc(sizeof(vm_ioctl_cmds)); + sz = vm_ioctl_ncmds * sizeof(vm_ioctl_cmds[0]); + cmds = malloc(sz); if (cmds == NULL) return (NULL); - bcopy(vm_ioctl_cmds, cmds, sizeof(vm_ioctl_cmds)); + bcopy(vm_ioctl_cmds, cmds, sz); return (cmds); } - *len = nitems(vm_ioctl_cmds); + *len = vm_ioctl_ncmds; return (NULL); }