@@ -850,7 +850,7 @@ static void *nvme_add_user_metadata(struct bio *bio, void __user *ubuf,
850850static int nvme_submit_user_cmd (struct request_queue * q ,
851851 struct nvme_command * cmd , void __user * ubuffer ,
852852 unsigned bufflen , void __user * meta_buffer , unsigned meta_len ,
853- u32 meta_seed , u32 * result , unsigned timeout )
853+ u32 meta_seed , u64 * result , unsigned timeout )
854854{
855855 bool write = nvme_is_write (cmd );
856856 struct nvme_ns * ns = q -> queuedata ;
@@ -891,7 +891,7 @@ static int nvme_submit_user_cmd(struct request_queue *q,
891891 else
892892 ret = nvme_req (req )-> status ;
893893 if (result )
894- * result = le32_to_cpu (nvme_req (req )-> result .u32 );
894+ * result = le64_to_cpu (nvme_req (req )-> result .u64 );
895895 if (meta && !ret && !write ) {
896896 if (copy_to_user (meta_buffer , meta , meta_len ))
897897 ret = - EFAULT ;
@@ -1338,6 +1338,54 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
13381338 struct nvme_command c ;
13391339 unsigned timeout = 0 ;
13401340 u32 effects ;
1341+ u64 result ;
1342+ int status ;
1343+
1344+ if (!capable (CAP_SYS_ADMIN ))
1345+ return - EACCES ;
1346+ if (copy_from_user (& cmd , ucmd , sizeof (cmd )))
1347+ return - EFAULT ;
1348+ if (cmd .flags )
1349+ return - EINVAL ;
1350+
1351+ memset (& c , 0 , sizeof (c ));
1352+ c .common .opcode = cmd .opcode ;
1353+ c .common .flags = cmd .flags ;
1354+ c .common .nsid = cpu_to_le32 (cmd .nsid );
1355+ c .common .cdw2 [0 ] = cpu_to_le32 (cmd .cdw2 );
1356+ c .common .cdw2 [1 ] = cpu_to_le32 (cmd .cdw3 );
1357+ c .common .cdw10 = cpu_to_le32 (cmd .cdw10 );
1358+ c .common .cdw11 = cpu_to_le32 (cmd .cdw11 );
1359+ c .common .cdw12 = cpu_to_le32 (cmd .cdw12 );
1360+ c .common .cdw13 = cpu_to_le32 (cmd .cdw13 );
1361+ c .common .cdw14 = cpu_to_le32 (cmd .cdw14 );
1362+ c .common .cdw15 = cpu_to_le32 (cmd .cdw15 );
1363+
1364+ if (cmd .timeout_ms )
1365+ timeout = msecs_to_jiffies (cmd .timeout_ms );
1366+
1367+ effects = nvme_passthru_start (ctrl , ns , cmd .opcode );
1368+ status = nvme_submit_user_cmd (ns ? ns -> queue : ctrl -> admin_q , & c ,
1369+ (void __user * )(uintptr_t )cmd .addr , cmd .data_len ,
1370+ (void __user * )(uintptr_t )cmd .metadata ,
1371+ cmd .metadata_len , 0 , & result , timeout );
1372+ nvme_passthru_end (ctrl , effects );
1373+
1374+ if (status >= 0 ) {
1375+ if (put_user (result , & ucmd -> result ))
1376+ return - EFAULT ;
1377+ }
1378+
1379+ return status ;
1380+ }
1381+
1382+ static int nvme_user_cmd64 (struct nvme_ctrl * ctrl , struct nvme_ns * ns ,
1383+ struct nvme_passthru_cmd64 __user * ucmd )
1384+ {
1385+ struct nvme_passthru_cmd64 cmd ;
1386+ struct nvme_command c ;
1387+ unsigned timeout = 0 ;
1388+ u32 effects ;
13411389 int status ;
13421390
13431391 if (!capable (CAP_SYS_ADMIN ))
@@ -1408,6 +1456,41 @@ static void nvme_put_ns_from_disk(struct nvme_ns_head *head, int idx)
14081456 srcu_read_unlock (& head -> srcu , idx );
14091457}
14101458
1459+ static bool is_ctrl_ioctl (unsigned int cmd )
1460+ {
1461+ if (cmd == NVME_IOCTL_ADMIN_CMD || cmd == NVME_IOCTL_ADMIN64_CMD )
1462+ return true;
1463+ if (is_sed_ioctl (cmd ))
1464+ return true;
1465+ return false;
1466+ }
1467+
1468+ static int nvme_handle_ctrl_ioctl (struct nvme_ns * ns , unsigned int cmd ,
1469+ void __user * argp ,
1470+ struct nvme_ns_head * head ,
1471+ int srcu_idx )
1472+ {
1473+ struct nvme_ctrl * ctrl = ns -> ctrl ;
1474+ int ret ;
1475+
1476+ nvme_get_ctrl (ns -> ctrl );
1477+ nvme_put_ns_from_disk (head , srcu_idx );
1478+
1479+ switch (cmd ) {
1480+ case NVME_IOCTL_ADMIN_CMD :
1481+ ret = nvme_user_cmd (ctrl , NULL , argp );
1482+ break ;
1483+ case NVME_IOCTL_ADMIN64_CMD :
1484+ ret = nvme_user_cmd64 (ctrl , NULL , argp );
1485+ break ;
1486+ default :
1487+ ret = sed_ioctl (ctrl -> opal_dev , cmd , argp );
1488+ break ;
1489+ }
1490+ nvme_put_ctrl (ctrl );
1491+ return ret ;
1492+ }
1493+
14111494static int nvme_ioctl (struct block_device * bdev , fmode_t mode ,
14121495 unsigned int cmd , unsigned long arg )
14131496{
@@ -1425,20 +1508,8 @@ static int nvme_ioctl(struct block_device *bdev, fmode_t mode,
14251508 * seperately and drop the ns SRCU reference early. This avoids a
14261509 * deadlock when deleting namespaces using the passthrough interface.
14271510 */
1428- if (cmd == NVME_IOCTL_ADMIN_CMD || is_sed_ioctl (cmd )) {
1429- struct nvme_ctrl * ctrl = ns -> ctrl ;
1430-
1431- nvme_get_ctrl (ns -> ctrl );
1432- nvme_put_ns_from_disk (head , srcu_idx );
1433-
1434- if (cmd == NVME_IOCTL_ADMIN_CMD )
1435- ret = nvme_user_cmd (ctrl , NULL , argp );
1436- else
1437- ret = sed_ioctl (ctrl -> opal_dev , cmd , argp );
1438-
1439- nvme_put_ctrl (ctrl );
1440- return ret ;
1441- }
1511+ if (is_ctrl_ioctl (cmd ))
1512+ return nvme_handle_ctrl_ioctl (ns , cmd , argp , head , srcu_idx );
14421513
14431514 switch (cmd ) {
14441515 case NVME_IOCTL_ID :
@@ -1451,6 +1522,9 @@ static int nvme_ioctl(struct block_device *bdev, fmode_t mode,
14511522 case NVME_IOCTL_SUBMIT_IO :
14521523 ret = nvme_submit_io (ns , argp );
14531524 break ;
1525+ case NVME_IOCTL_IO64_CMD :
1526+ ret = nvme_user_cmd64 (ns -> ctrl , ns , argp );
1527+ break ;
14541528 default :
14551529 if (ns -> ndev )
14561530 ret = nvme_nvm_ioctl (ns , cmd , arg );
@@ -2852,6 +2926,8 @@ static long nvme_dev_ioctl(struct file *file, unsigned int cmd,
28522926 switch (cmd ) {
28532927 case NVME_IOCTL_ADMIN_CMD :
28542928 return nvme_user_cmd (ctrl , NULL , argp );
2929+ case NVME_IOCTL_ADMIN64_CMD :
2930+ return nvme_user_cmd64 (ctrl , NULL , argp );
28552931 case NVME_IOCTL_IO_CMD :
28562932 return nvme_dev_user_cmd (ctrl , argp );
28572933 case NVME_IOCTL_RESET :
0 commit comments