@@ -1789,7 +1789,7 @@ static bool ublk_batch_prep_dispatch(struct ublk_queue *ubq,
17891789 * Filter out UBLK_BATCH_IO_UNUSED_TAG entries from tag_buf.
17901790 * Returns the new length after filtering.
17911791 */
1792- static unsigned int ublk_filter_unused_tags (unsigned short * tag_buf ,
1792+ static noinline unsigned int ublk_filter_unused_tags (unsigned short * tag_buf ,
17931793 unsigned int len )
17941794{
17951795 unsigned int i , j ;
@@ -1805,6 +1805,41 @@ static unsigned int ublk_filter_unused_tags(unsigned short *tag_buf,
18051805 return j ;
18061806}
18071807
1808+ static noinline void ublk_batch_dispatch_fail (struct ublk_queue * ubq ,
1809+ const struct ublk_batch_io_data * data ,
1810+ unsigned short * tag_buf , size_t len , int ret )
1811+ {
1812+ int i , res ;
1813+
1814+ /*
1815+ * Undo prep state for all IOs since userspace never received them.
1816+ * This restores IOs to pre-prepared state so they can be cleanly
1817+ * re-prepared when tags are pulled from FIFO again.
1818+ */
1819+ for (i = 0 ; i < len ; i ++ ) {
1820+ struct ublk_io * io = & ubq -> ios [tag_buf [i ]];
1821+ int index = -1 ;
1822+
1823+ ublk_io_lock (io );
1824+ if (io -> flags & UBLK_IO_FLAG_AUTO_BUF_REG )
1825+ index = io -> buf .auto_reg .index ;
1826+ io -> flags &= ~(UBLK_IO_FLAG_OWNED_BY_SRV | UBLK_IO_FLAG_AUTO_BUF_REG );
1827+ io -> flags |= UBLK_IO_FLAG_ACTIVE ;
1828+ ublk_io_unlock (io );
1829+
1830+ if (index != -1 )
1831+ io_buffer_unregister_bvec (data -> cmd , index ,
1832+ data -> issue_flags );
1833+ }
1834+
1835+ res = kfifo_in_spinlocked_noirqsave (& ubq -> evts_fifo ,
1836+ tag_buf , len , & ubq -> evts_lock );
1837+
1838+ pr_warn_ratelimited ("%s: copy tags or post CQE failure, move back "
1839+ "tags(%d %zu) ret %d\n" , __func__ , res , len ,
1840+ ret );
1841+ }
1842+
18081843#define MAX_NR_TAG 128
18091844static int __ublk_batch_dispatch (struct ublk_queue * ubq ,
18101845 const struct ublk_batch_io_data * data ,
@@ -1848,37 +1883,8 @@ static int __ublk_batch_dispatch(struct ublk_queue *ubq,
18481883
18491884 sel .val = ublk_batch_copy_io_tags (fcmd , sel .addr , tag_buf , len * tag_sz );
18501885 ret = ublk_batch_fetch_post_cqe (fcmd , & sel , data -> issue_flags );
1851- if (unlikely (ret < 0 )) {
1852- int i , res ;
1853-
1854- /*
1855- * Undo prep state for all IOs since userspace never received them.
1856- * This restores IOs to pre-prepared state so they can be cleanly
1857- * re-prepared when tags are pulled from FIFO again.
1858- */
1859- for (i = 0 ; i < len ; i ++ ) {
1860- struct ublk_io * io = & ubq -> ios [tag_buf [i ]];
1861- int index = -1 ;
1862-
1863- ublk_io_lock (io );
1864- if (io -> flags & UBLK_IO_FLAG_AUTO_BUF_REG )
1865- index = io -> buf .auto_reg .index ;
1866- io -> flags &= ~(UBLK_IO_FLAG_OWNED_BY_SRV | UBLK_IO_FLAG_AUTO_BUF_REG );
1867- io -> flags |= UBLK_IO_FLAG_ACTIVE ;
1868- ublk_io_unlock (io );
1869-
1870- if (index != -1 )
1871- io_buffer_unregister_bvec (data -> cmd , index ,
1872- data -> issue_flags );
1873- }
1874-
1875- res = kfifo_in_spinlocked_noirqsave (& ubq -> evts_fifo ,
1876- tag_buf , len , & ubq -> evts_lock );
1877-
1878- pr_warn_ratelimited ("%s: copy tags or post CQE failure, move back "
1879- "tags(%d %zu) ret %d\n" , __func__ , res , len ,
1880- ret );
1881- }
1886+ if (unlikely (ret < 0 ))
1887+ ublk_batch_dispatch_fail (ubq , data , tag_buf , len , ret );
18821888 return ret ;
18831889}
18841890
0 commit comments