@@ -1778,35 +1778,39 @@ struct smbd_connection *smbd_get_connection(
1778
1778
}
1779
1779
1780
1780
/*
1781
- * Receive data from receive reassembly queue
1781
+ * Receive data from the transport's receive reassembly queue
1782
1782
* All the incoming data packets are placed in reassembly queue
1783
- * buf : the buffer to read data into
1783
+ * iter : the buffer to read data into
1784
1784
* size: the length of data to read
1785
1785
* return value: actual data read
1786
- * Note: this implementation copies the data from reassebmly queue to receive
1786
+ *
1787
+ * Note: this implementation copies the data from reassembly queue to receive
1787
1788
* buffers used by upper layer. This is not the optimal code path. A better way
1788
1789
* to do it is to not have upper layer allocate its receive buffers but rather
1789
1790
* borrow the buffer from reassembly queue, and return it after data is
1790
1791
* consumed. But this will require more changes to upper layer code, and also
1791
1792
* need to consider packet boundaries while they still being reassembled.
1792
1793
*/
1793
- static int smbd_recv_buf (struct smbd_connection * info , char * buf ,
1794
- unsigned int size )
1794
+ int smbd_recv (struct smbd_connection * info , struct msghdr * msg )
1795
1795
{
1796
1796
struct smbdirect_socket * sc = & info -> socket ;
1797
1797
struct smbd_response * response ;
1798
1798
struct smbdirect_data_transfer * data_transfer ;
1799
+ size_t size = iov_iter_count (& msg -> msg_iter );
1799
1800
int to_copy , to_read , data_read , offset ;
1800
1801
u32 data_length , remaining_data_length , data_offset ;
1801
1802
int rc ;
1802
1803
1804
+ if (WARN_ON_ONCE (iov_iter_rw (& msg -> msg_iter ) == WRITE ))
1805
+ return - EINVAL ; /* It's a bug in upper layer to get there */
1806
+
1803
1807
again :
1804
1808
/*
1805
1809
* No need to hold the reassembly queue lock all the time as we are
1806
1810
* the only one reading from the front of the queue. The transport
1807
1811
* may add more entries to the back of the queue at the same time
1808
1812
*/
1809
- log_read (INFO , "size=%d info->reassembly_data_length=%d\n" , size ,
1813
+ log_read (INFO , "size=%zd info->reassembly_data_length=%d\n" , size ,
1810
1814
info -> reassembly_data_length );
1811
1815
if (info -> reassembly_data_length >= size ) {
1812
1816
int queue_length ;
@@ -1844,7 +1848,10 @@ static int smbd_recv_buf(struct smbd_connection *info, char *buf,
1844
1848
if (response -> first_segment && size == 4 ) {
1845
1849
unsigned int rfc1002_len =
1846
1850
data_length + remaining_data_length ;
1847
- * ((__be32 * )buf ) = cpu_to_be32 (rfc1002_len );
1851
+ __be32 rfc1002_hdr = cpu_to_be32 (rfc1002_len );
1852
+ if (copy_to_iter (& rfc1002_hdr , sizeof (rfc1002_hdr ),
1853
+ & msg -> msg_iter ) != sizeof (rfc1002_hdr ))
1854
+ return - EFAULT ;
1848
1855
data_read = 4 ;
1849
1856
response -> first_segment = false;
1850
1857
log_read (INFO , "returning rfc1002 length %d\n" ,
@@ -1853,10 +1860,9 @@ static int smbd_recv_buf(struct smbd_connection *info, char *buf,
1853
1860
}
1854
1861
1855
1862
to_copy = min_t (int , data_length - offset , to_read );
1856
- memcpy (
1857
- buf + data_read ,
1858
- (char * )data_transfer + data_offset + offset ,
1859
- to_copy );
1863
+ if (copy_to_iter ((char * )data_transfer + data_offset + offset ,
1864
+ to_copy , & msg -> msg_iter ) != to_copy )
1865
+ return - EFAULT ;
1860
1866
1861
1867
/* move on to the next buffer? */
1862
1868
if (to_copy == data_length - offset ) {
@@ -1921,90 +1927,6 @@ static int smbd_recv_buf(struct smbd_connection *info, char *buf,
1921
1927
goto again ;
1922
1928
}
1923
1929
1924
- /*
1925
- * Receive a page from receive reassembly queue
1926
- * page: the page to read data into
1927
- * to_read: the length of data to read
1928
- * return value: actual data read
1929
- */
1930
- static int smbd_recv_page (struct smbd_connection * info ,
1931
- struct page * page , unsigned int page_offset ,
1932
- unsigned int to_read )
1933
- {
1934
- struct smbdirect_socket * sc = & info -> socket ;
1935
- int ret ;
1936
- char * to_address ;
1937
- void * page_address ;
1938
-
1939
- /* make sure we have the page ready for read */
1940
- ret = wait_event_interruptible (
1941
- info -> wait_reassembly_queue ,
1942
- info -> reassembly_data_length >= to_read ||
1943
- sc -> status != SMBDIRECT_SOCKET_CONNECTED );
1944
- if (ret )
1945
- return ret ;
1946
-
1947
- /* now we can read from reassembly queue and not sleep */
1948
- page_address = kmap_atomic (page );
1949
- to_address = (char * ) page_address + page_offset ;
1950
-
1951
- log_read (INFO , "reading from page=%p address=%p to_read=%d\n" ,
1952
- page , to_address , to_read );
1953
-
1954
- ret = smbd_recv_buf (info , to_address , to_read );
1955
- kunmap_atomic (page_address );
1956
-
1957
- return ret ;
1958
- }
1959
-
1960
- /*
1961
- * Receive data from transport
1962
- * msg: a msghdr point to the buffer, can be ITER_KVEC or ITER_BVEC
1963
- * return: total bytes read, or 0. SMB Direct will not do partial read.
1964
- */
1965
- int smbd_recv (struct smbd_connection * info , struct msghdr * msg )
1966
- {
1967
- char * buf ;
1968
- struct page * page ;
1969
- unsigned int to_read , page_offset ;
1970
- int rc ;
1971
-
1972
- if (iov_iter_rw (& msg -> msg_iter ) == WRITE ) {
1973
- /* It's a bug in upper layer to get there */
1974
- cifs_dbg (VFS , "Invalid msg iter dir %u\n" ,
1975
- iov_iter_rw (& msg -> msg_iter ));
1976
- rc = - EINVAL ;
1977
- goto out ;
1978
- }
1979
-
1980
- switch (iov_iter_type (& msg -> msg_iter )) {
1981
- case ITER_KVEC :
1982
- buf = msg -> msg_iter .kvec -> iov_base ;
1983
- to_read = msg -> msg_iter .kvec -> iov_len ;
1984
- rc = smbd_recv_buf (info , buf , to_read );
1985
- break ;
1986
-
1987
- case ITER_BVEC :
1988
- page = msg -> msg_iter .bvec -> bv_page ;
1989
- page_offset = msg -> msg_iter .bvec -> bv_offset ;
1990
- to_read = msg -> msg_iter .bvec -> bv_len ;
1991
- rc = smbd_recv_page (info , page , page_offset , to_read );
1992
- break ;
1993
-
1994
- default :
1995
- /* It's a bug in upper layer to get there */
1996
- cifs_dbg (VFS , "Invalid msg type %d\n" ,
1997
- iov_iter_type (& msg -> msg_iter ));
1998
- rc = - EINVAL ;
1999
- }
2000
-
2001
- out :
2002
- /* SMBDirect will read it all or nothing */
2003
- if (rc > 0 )
2004
- msg -> msg_iter .count = 0 ;
2005
- return rc ;
2006
- }
2007
-
2008
1930
/*
2009
1931
* Send data to transport
2010
1932
* Each rqst is transported as a SMBDirect payload
0 commit comments