I changed code a little bit to be able to examine variables:
func GetGroupFD(group int, pciDevice *string) (int, error) {
ioctlId := 0x3b6a
var buffer uintptr
buffer = uintptr(unsafe.Pointer(pciDevice))
device, _, errno := syscall.Syscall(
syscall.SYS_IOCTL,
uintptr(group),
uintptr(unsafe.Pointer(&ioctlId)),
buffer,
)
(gdb) p &buffer
$8 = (uintptr *) 0xc4200c7b88
(gdb) x/g 0xc4200c7b88
0xc4200c7b88: 0x000000c4200c7d08
(gdb) x/g 0x000000c4200c7d08
0xc4200c7d08: 0x000000c4200122d0
(gdb) x/g 0x000000c4200122d0
0xc4200122d0: 0x3a31383a30303030
0x30303030 is start of expected string “0000:81:11.1”, first 4 bytes are not part of it. Anybody knows where those 4 bytes could have come from? And how to get rid of them?
Thank you
Serguei
--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Hi Max,
Thanks for the suggestion, unfortunately it did not help, see below:
func GetGroupFD(group int, pciDevice *string) (int, error) {
fmt.Printf("VFIO_GROUP_GET_DEVICE_FD() returned: %04x\n", VFIO_GROUP_GET_DEVICE_FD())
buffer := make([]byte, len(*pciDevice)+1)
for i, c := range *pciDevice {
buffer[i] = uint8(c)
}
buffer[len(*pciDevice)] = 0x0
fmt.Printf("pciDevice: %s\n", string(buffer))
device, _, errno := syscall.Syscall(
syscall.SYS_IOCTL,
uintptr(group),
uintptr(VFIO_GROUP_GET_DEVICE_FD()),
uintptr(unsafe.Pointer(&buffer[0])),
)
if errno != 0 {
return 0, fmt.Errorf("fail to get file descriptor for %d with errno: %+v", group, errno)
}
return int(device), nil
}
Any other suggestions?
Thank you
Serguei
From: <golan...@googlegroups.com> on behalf of Max <massimilia...@gmail.com>
Date: Thursday, August 23, 2018 at 10:46 AM
To: golang-nuts <golan...@googlegroups.com>
--
Hello Jake,
Apologies about formatting, here is correctly formatted code:
// GetGroupFD gets File descriptor for a specified by PCI address device
func GetGroupFD(group int, pciDevice string) (int, error) {
buffer := make([]byte, len(pciDevice)+1)
for i, c := range pciDevice {
buffer[i] = uint8(c)
}
ioctlID := VFIO_GROUP_GET_DEVICE_FD()
fmt.Printf("VFIO_GROUP_GET_DEVICE_FD() returned: %04x\n", ioctlID)
buffer[len(pciDevice)] = 0x0
fmt.Printf("pciDevice: %s\n", string(buffer))
device, _, errno := syscall.Syscall(
syscall.SYS_IOCTL,
uintptr(group),
uintptr(unsafe.Pointer(&ioctlID)),
uintptr(unsafe.Pointer(&buffer[0])),
)
if errno != 0 {
return 0, fmt.Errorf("fail to get file descriptor for %d with errno: %+v", group, errno)
}
return int(device), nil
}
I have also addressed your suggestions without any success. It is latest Centos 7.5.
Thank you
Serguei
https://play.golang.org/p/ZQSf-PwMtd9
says
"device=18446744073709551615 errno=inappropriate ioctl for device"
VFIO_GROUP_GET_DEVICE_FD - _IOW(VFIO_TYPE, VFIO_BASE + 6, char) * * Return a new file descriptor for the device object described by * the provided string. The string should match a device listed in * the devices subdirectory of the IOMMU group sysfs entry. The * group containing the device must already be added to this context. * Return: new file descriptor on success, -errno on failure. * Availability: When attached to container */
The strange thing in vfio.go GetGroupFD is the use of *string - as you don't want to modify that path, you shouldn't use a pointer.
But that's nothing to do with the ioctl.
The fill of buffer, and the use seems legit.
IF you have a working C program, I'd try to strace both C and Go and see what's different.
This package is locked down. Code outside the standard Go repository should be migrated to use the corresponding package in the golang.org/x/sys repository. That is also where updates required by new systems or versions should be applied.
Hi Jake,
Ioctl implementation in unix package seems a bit limited, how do you pass for example a required struct if “func IoctlSetInt(fd int, req uint, value int)” allows only to accept int?? If this package had a func accepting uintptr as a parameter, then I guess that could work.
Thank you
Serguei
From: <golan...@googlegroups.com> on behalf of "jake...@gmail.com" <jake...@gmail.com>
Date: Friday, August 24, 2018 at 12:09 PM
To: golang-nuts <golan...@googlegroups.com>
--