[PATCH] tests/ioctl_kvm_run.c: handle cpuid at the end of vcpu dentry
Dmitry V. Levin
ldv at altlinux.org
Wed May 2 01:15:42 UTC 2018
On Tue, May 01, 2018 at 03:36:48AM +0900, Masatake YAMATO wrote:
[...]
> @@ -56,7 +57,7 @@ kvm_ioctl(int fd, unsigned long cmd, const char *cmd_str, void *arg)
>
> static const char dev[] = "/dev/kvm";
> static const char vm_dev[] = "anon_inode:kvm-vm";
> -static const char vcpu_dev[] = "anon_inode:kvm-vcpu";
> +static char vcpu_dev[] = "anon_inode:kvm-vcpu:0";
> static size_t page_size;
>
> extern const char code[];
> @@ -165,6 +166,23 @@ run_kvm(const int vcpu_fd, struct kvm_run *const run, const size_t mmap_size,
> }
> }
>
> +static int
> +vcpu_dev_should_have_cpuid(int fd)
> +{
> + int r = 0;
> + char *filename = NULL;
> + char buf[sizeof("/proc/4294967296/fd/anon_inode:kvm-vcpu:0") + 1] = {'\0',};
This is quite non-traditional way of initializing strings.
> + if (asprintf(&filename, "/proc/%d/fd/%d", getpid(), fd) < 0)
> + error_msg_and_fail("asprintf");
> +
> + if ((readlink(filename, buf, sizeof(buf) - 1) >= 0)
> + && (strcmp(buf, "anon_inode:kvm-vcpu:0") == 0))
This cannot work properly because readlink does not append a null byte
to buf. I think the following alternative should work better:
char buf[sizeof(vcpu_dev)];
if (readlink(filename, buf, sizeof(buf)) == sizeof(buf) - 1
&& memcmp(buf, vcpu_dev, sizeof(buf) - 1) == 0)
--
ldv
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 801 bytes
Desc: not available
URL: <http://lists.strace.io/pipermail/strace-devel/attachments/20180502/06af3389/attachment.bin>
More information about the Strace-devel
mailing list