Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

nvme: replace the fmode_t argument to the nvme ioctl handlers with a simple bool

Instead of passing a fmode_t and only checking it fo0r FMODE_WRITE, pass
a bool open_for_write to prepare for callers that won't have the fmode_t.

Signed-off-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Acked-by: Christian Brauner <brauner@kernel.org>
Reviewed-by: Keith Busch <kbusch@kernel.org>
Link: https://lore.kernel.org/r/20230608110258.189493-22-hch@lst.de
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christoph Hellwig and committed by
Jens Axboe
7d9d7d59 1991299e

+34 -28
+34 -28
drivers/nvme/host/ioctl.c
··· 14 14 }; 15 15 16 16 static bool nvme_cmd_allowed(struct nvme_ns *ns, struct nvme_command *c, 17 - unsigned int flags, fmode_t mode) 17 + unsigned int flags, bool open_for_write) 18 18 { 19 19 u32 effects; 20 20 ··· 80 80 * writing. 81 81 */ 82 82 if (nvme_is_write(c) || (effects & NVME_CMD_EFFECTS_LBCC)) 83 - return mode & FMODE_WRITE; 83 + return open_for_write; 84 84 return true; 85 85 } 86 86 ··· 337 337 338 338 static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns, 339 339 struct nvme_passthru_cmd __user *ucmd, unsigned int flags, 340 - fmode_t mode) 340 + bool open_for_write) 341 341 { 342 342 struct nvme_passthru_cmd cmd; 343 343 struct nvme_command c; ··· 365 365 c.common.cdw14 = cpu_to_le32(cmd.cdw14); 366 366 c.common.cdw15 = cpu_to_le32(cmd.cdw15); 367 367 368 - if (!nvme_cmd_allowed(ns, &c, 0, mode)) 368 + if (!nvme_cmd_allowed(ns, &c, 0, open_for_write)) 369 369 return -EACCES; 370 370 371 371 if (cmd.timeout_ms) ··· 385 385 386 386 static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns, 387 387 struct nvme_passthru_cmd64 __user *ucmd, unsigned int flags, 388 - fmode_t mode) 388 + bool open_for_write) 389 389 { 390 390 struct nvme_passthru_cmd64 cmd; 391 391 struct nvme_command c; ··· 412 412 c.common.cdw14 = cpu_to_le32(cmd.cdw14); 413 413 c.common.cdw15 = cpu_to_le32(cmd.cdw15); 414 414 415 - if (!nvme_cmd_allowed(ns, &c, flags, mode)) 415 + if (!nvme_cmd_allowed(ns, &c, flags, open_for_write)) 416 416 return -EACCES; 417 417 418 418 if (cmd.timeout_ms) ··· 583 583 c.common.cdw14 = cpu_to_le32(READ_ONCE(cmd->cdw14)); 584 584 c.common.cdw15 = cpu_to_le32(READ_ONCE(cmd->cdw15)); 585 585 586 - if (!nvme_cmd_allowed(ns, &c, 0, ioucmd->file->f_mode)) 586 + if (!nvme_cmd_allowed(ns, &c, 0, ioucmd->file->f_mode & FMODE_WRITE)) 587 587 return -EACCES; 588 588 589 589 d.metadata = READ_ONCE(cmd->metadata); ··· 649 649 } 650 650 651 651 static int nvme_ctrl_ioctl(struct nvme_ctrl *ctrl, unsigned int cmd, 652 - void __user *argp, fmode_t mode) 652 + void __user *argp, bool open_for_write) 653 653 { 654 654 switch (cmd) { 655 655 case NVME_IOCTL_ADMIN_CMD: 656 - return nvme_user_cmd(ctrl, NULL, argp, 0, mode); 656 + return nvme_user_cmd(ctrl, NULL, argp, 0, open_for_write); 657 657 case NVME_IOCTL_ADMIN64_CMD: 658 - return nvme_user_cmd64(ctrl, NULL, argp, 0, mode); 658 + return nvme_user_cmd64(ctrl, NULL, argp, 0, open_for_write); 659 659 default: 660 660 return sed_ioctl(ctrl->opal_dev, cmd, argp); 661 661 } ··· 680 680 #endif /* COMPAT_FOR_U64_ALIGNMENT */ 681 681 682 682 static int nvme_ns_ioctl(struct nvme_ns *ns, unsigned int cmd, 683 - void __user *argp, unsigned int flags, fmode_t mode) 683 + void __user *argp, unsigned int flags, bool open_for_write) 684 684 { 685 685 switch (cmd) { 686 686 case NVME_IOCTL_ID: 687 687 force_successful_syscall_return(); 688 688 return ns->head->ns_id; 689 689 case NVME_IOCTL_IO_CMD: 690 - return nvme_user_cmd(ns->ctrl, ns, argp, flags, mode); 690 + return nvme_user_cmd(ns->ctrl, ns, argp, flags, open_for_write); 691 691 /* 692 692 * struct nvme_user_io can have different padding on some 32-bit ABIs. 693 693 * Just accept the compat version as all fields that are used are the ··· 702 702 flags |= NVME_IOCTL_VEC; 703 703 fallthrough; 704 704 case NVME_IOCTL_IO64_CMD: 705 - return nvme_user_cmd64(ns->ctrl, ns, argp, flags, mode); 705 + return nvme_user_cmd64(ns->ctrl, ns, argp, flags, 706 + open_for_write); 706 707 default: 707 708 return -ENOTTY; 708 709 } ··· 713 712 unsigned int cmd, unsigned long arg) 714 713 { 715 714 struct nvme_ns *ns = bdev->bd_disk->private_data; 715 + bool open_for_write = mode & FMODE_WRITE; 716 716 void __user *argp = (void __user *)arg; 717 717 unsigned int flags = 0; 718 718 ··· 721 719 flags |= NVME_IOCTL_PARTITION; 722 720 723 721 if (is_ctrl_ioctl(cmd)) 724 - return nvme_ctrl_ioctl(ns->ctrl, cmd, argp, mode); 725 - return nvme_ns_ioctl(ns, cmd, argp, flags, mode); 722 + return nvme_ctrl_ioctl(ns->ctrl, cmd, argp, open_for_write); 723 + return nvme_ns_ioctl(ns, cmd, argp, flags, open_for_write); 726 724 } 727 725 728 726 long nvme_ns_chr_ioctl(struct file *file, unsigned int cmd, unsigned long arg) 729 727 { 730 728 struct nvme_ns *ns = 731 729 container_of(file_inode(file)->i_cdev, struct nvme_ns, cdev); 730 + bool open_for_write = file->f_mode & FMODE_WRITE; 732 731 void __user *argp = (void __user *)arg; 733 732 734 733 if (is_ctrl_ioctl(cmd)) 735 - return nvme_ctrl_ioctl(ns->ctrl, cmd, argp, file->f_mode); 736 - return nvme_ns_ioctl(ns, cmd, argp, 0, file->f_mode); 734 + return nvme_ctrl_ioctl(ns->ctrl, cmd, argp, open_for_write); 735 + return nvme_ns_ioctl(ns, cmd, argp, 0, open_for_write); 737 736 } 738 737 739 738 static int nvme_uring_cmd_checks(unsigned int issue_flags) ··· 803 800 #ifdef CONFIG_NVME_MULTIPATH 804 801 static int nvme_ns_head_ctrl_ioctl(struct nvme_ns *ns, unsigned int cmd, 805 802 void __user *argp, struct nvme_ns_head *head, int srcu_idx, 806 - fmode_t mode) 803 + bool open_for_write) 807 804 __releases(&head->srcu) 808 805 { 809 806 struct nvme_ctrl *ctrl = ns->ctrl; ··· 811 808 812 809 nvme_get_ctrl(ns->ctrl); 813 810 srcu_read_unlock(&head->srcu, srcu_idx); 814 - ret = nvme_ctrl_ioctl(ns->ctrl, cmd, argp, mode); 811 + ret = nvme_ctrl_ioctl(ns->ctrl, cmd, argp, open_for_write); 815 812 816 813 nvme_put_ctrl(ctrl); 817 814 return ret; ··· 821 818 unsigned int cmd, unsigned long arg) 822 819 { 823 820 struct nvme_ns_head *head = bdev->bd_disk->private_data; 821 + bool open_for_write = mode & FMODE_WRITE; 824 822 void __user *argp = (void __user *)arg; 825 823 struct nvme_ns *ns; 826 824 int srcu_idx, ret = -EWOULDBLOCK; ··· 842 838 */ 843 839 if (is_ctrl_ioctl(cmd)) 844 840 return nvme_ns_head_ctrl_ioctl(ns, cmd, argp, head, srcu_idx, 845 - mode); 841 + open_for_write); 846 842 847 - ret = nvme_ns_ioctl(ns, cmd, argp, flags, mode); 843 + ret = nvme_ns_ioctl(ns, cmd, argp, flags, open_for_write); 848 844 out_unlock: 849 845 srcu_read_unlock(&head->srcu, srcu_idx); 850 846 return ret; ··· 853 849 long nvme_ns_head_chr_ioctl(struct file *file, unsigned int cmd, 854 850 unsigned long arg) 855 851 { 852 + bool open_for_write = file->f_mode & FMODE_WRITE; 856 853 struct cdev *cdev = file_inode(file)->i_cdev; 857 854 struct nvme_ns_head *head = 858 855 container_of(cdev, struct nvme_ns_head, cdev); ··· 868 863 869 864 if (is_ctrl_ioctl(cmd)) 870 865 return nvme_ns_head_ctrl_ioctl(ns, cmd, argp, head, srcu_idx, 871 - file->f_mode); 866 + open_for_write); 872 867 873 - ret = nvme_ns_ioctl(ns, cmd, argp, 0, file->f_mode); 868 + ret = nvme_ns_ioctl(ns, cmd, argp, 0, open_for_write); 874 869 out_unlock: 875 870 srcu_read_unlock(&head->srcu, srcu_idx); 876 871 return ret; ··· 945 940 } 946 941 947 942 static int nvme_dev_user_cmd(struct nvme_ctrl *ctrl, void __user *argp, 948 - fmode_t mode) 943 + bool open_for_write) 949 944 { 950 945 struct nvme_ns *ns; 951 946 int ret; ··· 969 964 kref_get(&ns->kref); 970 965 up_read(&ctrl->namespaces_rwsem); 971 966 972 - ret = nvme_user_cmd(ctrl, ns, argp, 0, mode); 967 + ret = nvme_user_cmd(ctrl, ns, argp, 0, open_for_write); 973 968 nvme_put_ns(ns); 974 969 return ret; 975 970 ··· 981 976 long nvme_dev_ioctl(struct file *file, unsigned int cmd, 982 977 unsigned long arg) 983 978 { 979 + bool open_for_write = file->f_mode & FMODE_WRITE; 984 980 struct nvme_ctrl *ctrl = file->private_data; 985 981 void __user *argp = (void __user *)arg; 986 982 987 983 switch (cmd) { 988 984 case NVME_IOCTL_ADMIN_CMD: 989 - return nvme_user_cmd(ctrl, NULL, argp, 0, file->f_mode); 985 + return nvme_user_cmd(ctrl, NULL, argp, 0, open_for_write); 990 986 case NVME_IOCTL_ADMIN64_CMD: 991 - return nvme_user_cmd64(ctrl, NULL, argp, 0, file->f_mode); 987 + return nvme_user_cmd64(ctrl, NULL, argp, 0, open_for_write); 992 988 case NVME_IOCTL_IO_CMD: 993 - return nvme_dev_user_cmd(ctrl, argp, file->f_mode); 989 + return nvme_dev_user_cmd(ctrl, argp, open_for_write); 994 990 case NVME_IOCTL_RESET: 995 991 if (!capable(CAP_SYS_ADMIN)) 996 992 return -EACCES;