8
8
#include <linux/io_uring.h>
9
9
#include "nvme.h"
10
10
11
+ enum {
12
+ NVME_IOCTL_VEC = (1 << 0 ),
13
+ };
14
+
11
15
static bool nvme_cmd_allowed (struct nvme_ns * ns , struct nvme_command * c ,
12
16
fmode_t mode )
13
17
{
@@ -150,7 +154,7 @@ static struct request *nvme_alloc_user_request(struct request_queue *q,
150
154
static int nvme_map_user_request (struct request * req , u64 ubuffer ,
151
155
unsigned bufflen , void __user * meta_buffer , unsigned meta_len ,
152
156
u32 meta_seed , void * * metap , struct io_uring_cmd * ioucmd ,
153
- bool vec )
157
+ unsigned int flags )
154
158
{
155
159
struct request_queue * q = req -> q ;
156
160
struct nvme_ns * ns = q -> queuedata ;
@@ -163,7 +167,7 @@ static int nvme_map_user_request(struct request *req, u64 ubuffer,
163
167
struct iov_iter iter ;
164
168
165
169
/* fixedbufs is only for non-vectored io */
166
- if (WARN_ON_ONCE (vec ))
170
+ if (WARN_ON_ONCE (flags & NVME_IOCTL_VEC ))
167
171
return - EINVAL ;
168
172
ret = io_uring_cmd_import_fixed (ubuffer , bufflen ,
169
173
rq_data_dir (req ), & iter , ioucmd );
@@ -172,8 +176,8 @@ static int nvme_map_user_request(struct request *req, u64 ubuffer,
172
176
ret = blk_rq_map_user_iov (q , req , NULL , & iter , GFP_KERNEL );
173
177
} else {
174
178
ret = blk_rq_map_user_io (req , NULL , nvme_to_user_ptr (ubuffer ),
175
- bufflen , GFP_KERNEL , vec , 0 , 0 ,
176
- rq_data_dir (req ));
179
+ bufflen , GFP_KERNEL , flags & NVME_IOCTL_VEC , 0 ,
180
+ 0 , rq_data_dir (req ));
177
181
}
178
182
179
183
if (ret )
@@ -203,9 +207,9 @@ static int nvme_map_user_request(struct request *req, u64 ubuffer,
203
207
}
204
208
205
209
static int nvme_submit_user_cmd (struct request_queue * q ,
206
- struct nvme_command * cmd , u64 ubuffer ,
207
- unsigned bufflen , void __user * meta_buffer , unsigned meta_len ,
208
- u32 meta_seed , u64 * result , unsigned timeout , bool vec )
210
+ struct nvme_command * cmd , u64 ubuffer , unsigned bufflen ,
211
+ void __user * meta_buffer , unsigned meta_len , u32 meta_seed ,
212
+ u64 * result , unsigned timeout , unsigned int flags )
209
213
{
210
214
struct nvme_ctrl * ctrl ;
211
215
struct request * req ;
@@ -221,7 +225,7 @@ static int nvme_submit_user_cmd(struct request_queue *q,
221
225
req -> timeout = timeout ;
222
226
if (ubuffer && bufflen ) {
223
227
ret = nvme_map_user_request (req , ubuffer , bufflen , meta_buffer ,
224
- meta_len , meta_seed , & meta , NULL , vec );
228
+ meta_len , meta_seed , & meta , NULL , flags );
225
229
if (ret )
226
230
return ret ;
227
231
}
@@ -304,10 +308,8 @@ static int nvme_submit_io(struct nvme_ns *ns, struct nvme_user_io __user *uio)
304
308
c .rw .apptag = cpu_to_le16 (io .apptag );
305
309
c .rw .appmask = cpu_to_le16 (io .appmask );
306
310
307
- return nvme_submit_user_cmd (ns -> queue , & c ,
308
- io .addr , length ,
309
- metadata , meta_len , lower_32_bits (io .slba ), NULL , 0 ,
310
- false);
311
+ return nvme_submit_user_cmd (ns -> queue , & c , io .addr , length , metadata ,
312
+ meta_len , lower_32_bits (io .slba ), NULL , 0 , 0 );
311
313
}
312
314
313
315
static bool nvme_validate_passthru_nsid (struct nvme_ctrl * ctrl ,
@@ -360,9 +362,8 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
360
362
timeout = msecs_to_jiffies (cmd .timeout_ms );
361
363
362
364
status = nvme_submit_user_cmd (ns ? ns -> queue : ctrl -> admin_q , & c ,
363
- cmd .addr , cmd .data_len ,
364
- nvme_to_user_ptr (cmd .metadata ), cmd .metadata_len ,
365
- 0 , & result , timeout , false);
365
+ cmd .addr , cmd .data_len , nvme_to_user_ptr (cmd .metadata ),
366
+ cmd .metadata_len , 0 , & result , timeout , 0 );
366
367
367
368
if (status >= 0 ) {
368
369
if (put_user (result , & ucmd -> result ))
@@ -373,8 +374,8 @@ static int nvme_user_cmd(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
373
374
}
374
375
375
376
static int nvme_user_cmd64 (struct nvme_ctrl * ctrl , struct nvme_ns * ns ,
376
- struct nvme_passthru_cmd64 __user * ucmd , bool vec ,
377
- fmode_t mode )
377
+ struct nvme_passthru_cmd64 __user * ucmd , unsigned int flags ,
378
+ fmode_t mode )
378
379
{
379
380
struct nvme_passthru_cmd64 cmd ;
380
381
struct nvme_command c ;
@@ -408,9 +409,8 @@ static int nvme_user_cmd64(struct nvme_ctrl *ctrl, struct nvme_ns *ns,
408
409
timeout = msecs_to_jiffies (cmd .timeout_ms );
409
410
410
411
status = nvme_submit_user_cmd (ns ? ns -> queue : ctrl -> admin_q , & c ,
411
- cmd .addr , cmd .data_len ,
412
- nvme_to_user_ptr (cmd .metadata ), cmd .metadata_len ,
413
- 0 , & cmd .result , timeout , vec );
412
+ cmd .addr , cmd .data_len , nvme_to_user_ptr (cmd .metadata ),
413
+ cmd .metadata_len , 0 , & cmd .result , timeout , flags );
414
414
415
415
if (status >= 0 ) {
416
416
if (put_user (cmd .result , & ucmd -> result ))
@@ -643,7 +643,7 @@ static int nvme_ctrl_ioctl(struct nvme_ctrl *ctrl, unsigned int cmd,
643
643
case NVME_IOCTL_ADMIN_CMD :
644
644
return nvme_user_cmd (ctrl , NULL , argp , mode );
645
645
case NVME_IOCTL_ADMIN64_CMD :
646
- return nvme_user_cmd64 (ctrl , NULL , argp , false , mode );
646
+ return nvme_user_cmd64 (ctrl , NULL , argp , 0 , mode );
647
647
default :
648
648
return sed_ioctl (ctrl -> opal_dev , cmd , argp );
649
649
}
@@ -670,6 +670,8 @@ struct nvme_user_io32 {
670
670
static int nvme_ns_ioctl (struct nvme_ns * ns , unsigned int cmd ,
671
671
void __user * argp , fmode_t mode )
672
672
{
673
+ unsigned int flags = 0 ;
674
+
673
675
switch (cmd ) {
674
676
case NVME_IOCTL_ID :
675
677
force_successful_syscall_return ();
@@ -686,10 +688,11 @@ static int nvme_ns_ioctl(struct nvme_ns *ns, unsigned int cmd,
686
688
#endif
687
689
case NVME_IOCTL_SUBMIT_IO :
688
690
return nvme_submit_io (ns , argp );
689
- case NVME_IOCTL_IO64_CMD :
690
- return nvme_user_cmd64 (ns -> ctrl , ns , argp , false, mode );
691
691
case NVME_IOCTL_IO64_CMD_VEC :
692
- return nvme_user_cmd64 (ns -> ctrl , ns , argp , true, mode );
692
+ flags |= NVME_IOCTL_VEC ;
693
+ fallthrough ;
694
+ case NVME_IOCTL_IO64_CMD :
695
+ return nvme_user_cmd64 (ns -> ctrl , ns , argp , flags , mode );
693
696
default :
694
697
return - ENOTTY ;
695
698
}
@@ -962,7 +965,7 @@ long nvme_dev_ioctl(struct file *file, unsigned int cmd,
962
965
case NVME_IOCTL_ADMIN_CMD :
963
966
return nvme_user_cmd (ctrl , NULL , argp , file -> f_mode );
964
967
case NVME_IOCTL_ADMIN64_CMD :
965
- return nvme_user_cmd64 (ctrl , NULL , argp , false , file -> f_mode );
968
+ return nvme_user_cmd64 (ctrl , NULL , argp , 0 , file -> f_mode );
966
969
case NVME_IOCTL_IO_CMD :
967
970
return nvme_dev_user_cmd (ctrl , argp , file -> f_mode );
968
971
case NVME_IOCTL_RESET :
0 commit comments