The "mmc: Support capabilities in MMC_IOC_{MULTI_}CMD ioctls" patch previously hard-coded the ioctl command value in order to maintain compatibility with non-PCuABI ioctl handlers such as those found in block.c. This deviates from the standard approach which is to always define the ioctl command value in terms of the struct size (which may change), instead providing any fixes in the kernel via compat ioctl handlers.
This patch therefore aligns the MMC ioctl handlers in block.c with the standard approach. Undoing the hard-coding in the header leaves the ioctl command value unchanged in all situations except in PCuABI where the structs sizes, and hence the ioctl command values, are now larger (the ioctl value remains unchanged in compat64 as well). The additional comments that were added in the aforementioned patch regarding the changing size of the structs is also removed in this patch.
Signed-off-by: Akram Ahmad Akram.Ahmad@arm.com --- drivers/mmc/core/block.c | 64 ++++++++++++++++++++++++++++++++-- include/uapi/linux/mmc/ioctl.h | 22 +++--------- 2 files changed, 66 insertions(+), 20 deletions(-)
diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 17a1d24bdaed..ad63ba425d47 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -76,6 +76,15 @@ MODULE_ALIAS("mmc:block"); #define MMC_EXTRACT_INDEX_FROM_ARG(x) ((x & 0x00FF0000) >> 16) #define MMC_EXTRACT_VALUE_FROM_ARG(x) ((x & 0x0000FF00) >> 8)
+/* + * The compat_mmc_ioc_{multi_}cmd structs have different sizes in PCuABI and in + * compat64, which affects the expected MMC_IOC_{MULTI_}CMD ioctl values. The + * following ioctl values reflect the sizes of the compat64 structs defined in + * this file. + */ +#define MMC_IOC_CMD_COMPAT _IOWR(MMC_BLOCK_MAJOR, 0, struct compat_mmc_ioc_cmd) +#define MMC_IOC_MULTI_CMD_COMPAT _IOWR(MMC_BLOCK_MAJOR, 1, struct compat_mmc_ioc_multi_cmd) + static DEFINE_MUTEX(block_mutex);
/* @@ -891,7 +900,38 @@ static int mmc_blk_ioctl(struct block_device *bdev, blk_mode_t mode, static int mmc_blk_compat_ioctl(struct block_device *bdev, blk_mode_t mode, unsigned int cmd, unsigned long arg) { - return mmc_blk_ioctl(bdev, mode, cmd, (user_uintptr_t) compat_ptr(arg)); + struct mmc_blk_data *md; + int ret; + void __user *uarg = compat_ptr(arg); + + switch (cmd) { + case MMC_IOC_CMD_COMPAT: + ret = mmc_blk_check_blkdev(bdev); + if (ret) + return ret; + md = mmc_blk_get(bdev->bd_disk); + if (!md) + return -EINVAL; + ret = mmc_blk_ioctl_cmd(md, + uarg, + NULL); + mmc_blk_put(md); + return ret; + case MMC_IOC_MULTI_CMD_COMPAT: + ret = mmc_blk_check_blkdev(bdev); + if (ret) + return ret; + md = mmc_blk_get(bdev->bd_disk); + if (!md) + return -EINVAL; + ret = mmc_blk_ioctl_multi_cmd(md, + uarg, + NULL); + mmc_blk_put(md); + return ret; + default: + return -EINVAL; + } } #endif
@@ -2700,7 +2740,27 @@ static long mmc_rpmb_ioctl(struct file *filp, unsigned int cmd, static long mmc_rpmb_ioctl_compat(struct file *filp, unsigned int cmd, unsigned long arg) { - return mmc_rpmb_ioctl(filp, cmd, (user_uintptr_t)compat_ptr(arg)); + struct mmc_rpmb_data *rpmb = filp->private_data; + int ret; + void __user *uarg = compat_ptr(arg); + + switch (cmd) { + case MMC_IOC_CMD_COMPAT: + ret = mmc_blk_ioctl_cmd(rpmb->md, + uarg, + rpmb); + break; + case MMC_IOC_MULTI_CMD_COMPAT: + ret = mmc_blk_ioctl_multi_cmd(rpmb->md, + uarg, + rpmb); + break; + default: + ret = -EINVAL; + break; + } + + return ret; } #endif
diff --git a/include/uapi/linux/mmc/ioctl.h b/include/uapi/linux/mmc/ioctl.h index 9d34bfc49198..3ca3cd4785f7 100644 --- a/include/uapi/linux/mmc/ioctl.h +++ b/include/uapi/linux/mmc/ioctl.h @@ -64,29 +64,15 @@ struct mmc_ioc_multi_cmd { struct mmc_ioc_cmd cmds[]; };
-/* - * The size of struct mmc_ioc_cmd changes in PCuABI due to the use of - * __kernel_uintptr_t, which in turn modifies the command value for this - * ioctl. It is therefore necessary to hard-code the value for the ioctl - * using the size of the struct that is expected in any ABI other than - * PCuABI, to ensure that the value for MMC_IOC_CMD is unchanged. The - * original definition is as follows: - * - * #define MMC_IOC_CMD _IOWR(MMC_BLOCK_MAJOR, 0, struct mmc_ioc_cmd) - */ -#define MMC_IOC_CMD _IOC(_IOC_READ|_IOC_WRITE, MMC_BLOCK_MAJOR, 0, 72) +#define MMC_IOC_CMD _IOWR(MMC_BLOCK_MAJOR, 0, struct mmc_ioc_cmd) + /* * MMC_IOC_MULTI_CMD: Used to send an array of MMC commands described by * the structure mmc_ioc_multi_cmd. The MMC driver will issue all * commands in array in sequence to card. - * - * Note: the size of struct mmc_ioc_multi_cmd changes in PCuABI, due to the - * increased alignment of struct mmc_ioc_cmd. For that reason, its value needs - * to be hard-coded too. Original definition: - * - * #define MMC_IOC_MULTI_CMD _IOWR(MMC_BLOCK_MAJOR, 1, struct mmc_ioc_multi_cmd) */ -#define MMC_IOC_MULTI_CMD _IOC(_IOC_READ|_IOC_WRITE, MMC_BLOCK_MAJOR, 1, 8) +#define MMC_IOC_MULTI_CMD _IOWR(MMC_BLOCK_MAJOR, 1, struct mmc_ioc_multi_cmd) + /* * Since this ioctl is only meant to enhance (and not replace) normal access * to the mmc bus device, an upper data transfer limit of MMC_IOC_MAX_BYTES
On 15/04/2024 18:29, Akram Ahmad wrote:
The "mmc: Support capabilities in MMC_IOC_{MULTI_}CMD ioctls" patch previously hard-coded the ioctl command value in order to maintain compatibility with non-PCuABI ioctl handlers such as those found in block.c. This deviates from the standard approach which is to always define the ioctl command value in terms of the struct size (which may change), instead providing any fixes in the kernel via compat ioctl handlers.
This patch therefore aligns the MMC ioctl handlers in block.c with the standard approach. Undoing the hard-coding in the header leaves the ioctl command value unchanged in all situations except in PCuABI where the structs sizes, and hence the ioctl command values, are now larger (the ioctl value remains unchanged in compat64 as well). The additional comments that were added in the aforementioned patch regarding the changing size of the structs is also removed in this patch.
Signed-off-by: Akram Ahmad Akram.Ahmad@arm.com
drivers/mmc/core/block.c | 64 ++++++++++++++++++++++++++++++++-- include/uapi/linux/mmc/ioctl.h | 22 +++--------- 2 files changed, 66 insertions(+), 20 deletions(-)
Applied on next, thanks! I made a few minor witespace changes (removing unnecessary line breaks when calling functions, removing empty lines in the uapi header that weren't there originally).
Kevin
diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 17a1d24bdaed..ad63ba425d47 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -76,6 +76,15 @@ MODULE_ALIAS("mmc:block"); #define MMC_EXTRACT_INDEX_FROM_ARG(x) ((x & 0x00FF0000) >> 16) #define MMC_EXTRACT_VALUE_FROM_ARG(x) ((x & 0x0000FF00) >> 8) +/*
- The compat_mmc_ioc_{multi_}cmd structs have different sizes in PCuABI and in
- compat64, which affects the expected MMC_IOC_{MULTI_}CMD ioctl values. The
- following ioctl values reflect the sizes of the compat64 structs defined in
- this file.
- */
+#define MMC_IOC_CMD_COMPAT _IOWR(MMC_BLOCK_MAJOR, 0, struct compat_mmc_ioc_cmd) +#define MMC_IOC_MULTI_CMD_COMPAT _IOWR(MMC_BLOCK_MAJOR, 1, struct compat_mmc_ioc_multi_cmd)
static DEFINE_MUTEX(block_mutex); /* @@ -891,7 +900,38 @@ static int mmc_blk_ioctl(struct block_device *bdev, blk_mode_t mode, static int mmc_blk_compat_ioctl(struct block_device *bdev, blk_mode_t mode, unsigned int cmd, unsigned long arg) {
- return mmc_blk_ioctl(bdev, mode, cmd, (user_uintptr_t) compat_ptr(arg));
- struct mmc_blk_data *md;
- int ret;
- void __user *uarg = compat_ptr(arg);
- switch (cmd) {
- case MMC_IOC_CMD_COMPAT:
ret = mmc_blk_check_blkdev(bdev);
if (ret)
return ret;
md = mmc_blk_get(bdev->bd_disk);
if (!md)
return -EINVAL;
ret = mmc_blk_ioctl_cmd(md,
uarg,
NULL);
mmc_blk_put(md);
return ret;
- case MMC_IOC_MULTI_CMD_COMPAT:
ret = mmc_blk_check_blkdev(bdev);
if (ret)
return ret;
md = mmc_blk_get(bdev->bd_disk);
if (!md)
return -EINVAL;
ret = mmc_blk_ioctl_multi_cmd(md,
uarg,
NULL);
mmc_blk_put(md);
return ret;
- default:
return -EINVAL;
- }
} #endif @@ -2700,7 +2740,27 @@ static long mmc_rpmb_ioctl(struct file *filp, unsigned int cmd, static long mmc_rpmb_ioctl_compat(struct file *filp, unsigned int cmd, unsigned long arg) {
- return mmc_rpmb_ioctl(filp, cmd, (user_uintptr_t)compat_ptr(arg));
- struct mmc_rpmb_data *rpmb = filp->private_data;
- int ret;
- void __user *uarg = compat_ptr(arg);
- switch (cmd) {
- case MMC_IOC_CMD_COMPAT:
ret = mmc_blk_ioctl_cmd(rpmb->md,
uarg,
rpmb);
break;
- case MMC_IOC_MULTI_CMD_COMPAT:
ret = mmc_blk_ioctl_multi_cmd(rpmb->md,
uarg,
rpmb);
break;
- default:
ret = -EINVAL;
break;
- }
- return ret;
} #endif diff --git a/include/uapi/linux/mmc/ioctl.h b/include/uapi/linux/mmc/ioctl.h index 9d34bfc49198..3ca3cd4785f7 100644 --- a/include/uapi/linux/mmc/ioctl.h +++ b/include/uapi/linux/mmc/ioctl.h @@ -64,29 +64,15 @@ struct mmc_ioc_multi_cmd { struct mmc_ioc_cmd cmds[]; }; -/*
- The size of struct mmc_ioc_cmd changes in PCuABI due to the use of
- __kernel_uintptr_t, which in turn modifies the command value for this
- ioctl. It is therefore necessary to hard-code the value for the ioctl
- using the size of the struct that is expected in any ABI other than
- PCuABI, to ensure that the value for MMC_IOC_CMD is unchanged. The
- original definition is as follows:
- #define MMC_IOC_CMD _IOWR(MMC_BLOCK_MAJOR, 0, struct mmc_ioc_cmd)
- */
-#define MMC_IOC_CMD _IOC(_IOC_READ|_IOC_WRITE, MMC_BLOCK_MAJOR, 0, 72) +#define MMC_IOC_CMD _IOWR(MMC_BLOCK_MAJOR, 0, struct mmc_ioc_cmd)
/*
- MMC_IOC_MULTI_CMD: Used to send an array of MMC commands described by
- the structure mmc_ioc_multi_cmd. The MMC driver will issue all
- commands in array in sequence to card.
- Note: the size of struct mmc_ioc_multi_cmd changes in PCuABI, due to the
- increased alignment of struct mmc_ioc_cmd. For that reason, its value needs
- to be hard-coded too. Original definition:
*/
- #define MMC_IOC_MULTI_CMD _IOWR(MMC_BLOCK_MAJOR, 1, struct mmc_ioc_multi_cmd)
-#define MMC_IOC_MULTI_CMD _IOC(_IOC_READ|_IOC_WRITE, MMC_BLOCK_MAJOR, 1, 8) +#define MMC_IOC_MULTI_CMD _IOWR(MMC_BLOCK_MAJOR, 1, struct mmc_ioc_multi_cmd)
/*
- Since this ioctl is only meant to enhance (and not replace) normal access
- to the mmc bus device, an upper data transfer limit of MMC_IOC_MAX_BYTES
linux-morello@op-lists.linaro.org