Skip to contentSkip to conversation

freebsd/privcmd: fix MMAP_RESOURCE ioctl definition

PATCH In review Roger Pau Monne 3 participants 5 messages Nov 15, 2021 – Nov 16, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 freebsd/privcmd: fix MMAP_RESOURCE ioctl definition

Current ioctl definition was wrong in both FreeBSD and Xen sources, as the MMAP_RESOURCE ioctl needs to copy back the size of the resource when passed a zero address and size. FreeBSD encodes in the definition of the ioctl number whether parameters should be copied in (W) and/or copied out (R). The current definition for MMAP_RESOURCE is lacking the copy out part (R), and thus the call to query the size of a resource would always return 0.

This change will break the current ioctl interface, the tools can however fall back to using the foreign memory interface in order to map resources from guests.

This was a shortcoming from when the hypercall and ioctl gained the ability to query the size of the resources, as originally the MMAP_RESOURCE ioctl didn't need to copy out any data.

---
Cc: Ian Jackson <[email protected]>

The change only affects FreeBSD, and it's only a change in a definition of an ioctl, so it's unlikely to break existing code logic. Without this change Xen tools won't be able to use the MMAP_RESOURCE ioctl.

---
 tools/include/xen-sys/FreeBSD/privcmd.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
tools/include/xen-sys/FreeBSD/privcmd.h +1 -1
index 649ad443c7..70cee3db68 100644
@@ -84,7 +84,7 @@ typedef struct ioctl_privcmd_dmop privcmd_dm_op_t;
 #define IOCTL_PRIVCMD_MMAPBATCH					\
 	_IOWR('E', 1, struct ioctl_privcmd_mmapbatch)
 #define IOCTL_PRIVCMD_MMAP_RESOURCE				\
-	_IOW('E', 2, struct ioctl_privcmd_mmapresource)
+	_IOWR('E', 2, struct ioctl_privcmd_mmapresource)
 #define IOCTL_PRIVCMD_DM_OP					\
 	_IOW('E', 3, struct ioctl_privcmd_dmop)
 #define IOCTL_PRIVCMD_RESTRICT					\
Signature · 1 line
2.33.0
#1 lore raw
Quoted 16 lines · Roger Pau Monne

Current ioctl definition was wrong in both FreeBSD and Xen sources, as the MMAP_RESOURCE ioctl needs to copy back the size of the resource when passed a zero address and size. FreeBSD encodes in the definition of the ioctl number whether parameters should be copied in (W) and/or copied out (R). The current definition for MMAP_RESOURCE is lacking the copy out part (R), and thus the call to query the size of a resource would always return 0.

This change will break the current ioctl interface, the tools can however fall back to using the foreign memory interface in order to map resources from guests.

This was a shortcoming from when the hypercall and ioctl gained the ability to query the size of the resources, as originally the MMAP_RESOURCE ioctl didn't need to copy out any data.

Quoted 8 lines

---
Cc: Ian Jackson <[email protected]>

The change only affects FreeBSD, and it's only a change in a definition of an ioctl, so it's unlikely to break existing code logic. Without this change Xen tools won't be able to use the MMAP_RESOURCE ioctl.

I guess you found this while trying to fix test-resource, in which case a further argument for the change is "the unit tests now pass on FreeBSD" ?

~Andrew

#2 lore raw
Quoted 21 lines · Andrew Cooper
Quoted 20 lines · Roger Pau Monne

Current ioctl definition was wrong in both FreeBSD and Xen sources, as the MMAP_RESOURCE ioctl needs to copy back the size of the resource when passed a zero address and size. FreeBSD encodes in the definition of the ioctl number whether parameters should be copied in (W) and/or copied out (R). The current definition for MMAP_RESOURCE is lacking the copy out part (R), and thus the call to query the size of a resource would always return 0.

This change will break the current ioctl interface, the tools can however fall back to using the foreign memory interface in order to map resources from guests.

This was a shortcoming from when the hypercall and ioctl gained the ability to query the size of the resources, as originally the MMAP_RESOURCE ioctl didn't need to copy out any data.

---
Cc: Ian Jackson <[email protected]>

Quoted 7 lines
Quoted 4 lines

The change only affects FreeBSD, and it's only a change in a definition of an ioctl, so it's unlikely to break existing code logic. Without this change Xen tools won't be able to use the MMAP_RESOURCE ioctl.

I guess you found this while trying to fix test-resource, in which case a further argument for the change is "the unit tests now pass on FreeBSD" ?

Indeed. It seems like this is the only instance of a resource size query that we have implemented so far.

Thanks, Roger.

#3 lore raw
Quoted 22 lines · Roger Pau Monné
Quoted 21 lines · Andrew Cooper
Quoted 20 lines · Roger Pau Monne

Current ioctl definition was wrong in both FreeBSD and Xen sources, as the MMAP_RESOURCE ioctl needs to copy back the size of the resource when passed a zero address and size. FreeBSD encodes in the definition of the ioctl number whether parameters should be copied in (W) and/or copied out (R). The current definition for MMAP_RESOURCE is lacking the copy out part (R), and thus the call to query the size of a resource would always return 0.

This change will break the current ioctl interface, the tools can however fall back to using the foreign memory interface in order to map resources from guests.

This was a shortcoming from when the hypercall and ioctl gained the ability to query the size of the resources, as originally the MMAP_RESOURCE ioctl didn't need to copy out any data.

---
Cc: Ian Jackson <[email protected]>

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

The change only affects FreeBSD, and it's only a change in a definition of an ioctl, so it's unlikely to break existing code logic. Without this change Xen tools won't be able to use the MMAP_RESOURCE ioctl.

I guess you found this while trying to fix test-resource, in which case a further argument for the change is "the unit tests now pass on FreeBSD" ?

Indeed. It seems like this is the only instance of a resource size query that we have implemented so far.

Well - it's used on the domain create path ever since being introduced to avoid the "shoot a hole in a superpage in order to map the grant table" problem, but it does have a fallback which is probably why it went unnoticed.

~Andrew

#4 lore raw
In reply to Roger Pau Monne

Roger Pau Monne writes ("[PATCH for-4.16] freebsd/privcmd: fix MMAP_RESOURCE ioctl definition"):

Quoted 16 lines

Current ioctl definition was wrong in both FreeBSD and Xen sources, as the MMAP_RESOURCE ioctl needs to copy back the size of the resource when passed a zero address and size. FreeBSD encodes in the definition of the ioctl number whether parameters should be copied in (W) and/or copied out (R). The current definition for MMAP_RESOURCE is lacking the copy out part (R), and thus the call to query the size of a resource would always return 0.

This change will break the current ioctl interface, the tools can however fall back to using the foreign memory interface in order to map resources from guests.

This was a shortcoming from when the hypercall and ioctl gained the ability to query the size of the resources, as originally the MMAP_RESOURCE ioctl didn't need to copy out any data.

Quoted 8 lines

---
Cc: Ian Jackson <[email protected]>

The change only affects FreeBSD, and it's only a change in a definition of an ioctl, so it's unlikely to break existing code logic. Without this change Xen tools won't be able to use the MMAP_RESOURCE ioctl.