aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeilBrown <neilb@suse.de>2006-10-04 05:15:47 -0400
committerLinus Torvalds <torvalds@g5.osdl.org>2006-10-04 10:55:15 -0400
commit3cc03b164cf01c6f36e64720b58610d292fb26f7 (patch)
treeb558e11a087945ad5b9a1a25483aa2acc8d93fbb
parent4452435948424e5322c2a2fefbdc2cf3732cc45d (diff)
[PATCH] knfsd: Avoid excess stack usage in svc_tcp_recvfrom
.. by allocating the array of 'kvec' in 'struct svc_rqst'. As we plan to increase RPCSVC_MAXPAGES from 8 upto 256, we can no longer allocate an array of this size on the stack. So we allocate it in 'struct svc_rqst'. However svc_rqst contains (indirectly) an array of the same type and size (actually several, but they are in a union). So rather than waste space, we move those arrays out of the separately allocated union and into svc_rqst to share with the kvec moved out of svc_tcp_recvfrom (various arrays are used at different times, so there is no conflict). Signed-off-by: Neil Brown <neilb@suse.de> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
-rw-r--r--fs/nfsd/nfs3proc.c4
-rw-r--r--fs/nfsd/nfs3xdr.c22
-rw-r--r--fs/nfsd/nfs4proc.c2
-rw-r--r--fs/nfsd/nfs4xdr.c26
-rw-r--r--fs/nfsd/nfsproc.c4
-rw-r--r--fs/nfsd/nfsxdr.c22
-rw-r--r--include/linux/nfsd/xdr.h2
-rw-r--r--include/linux/nfsd/xdr3.h2
-rw-r--r--include/linux/nfsd/xdr4.h2
-rw-r--r--include/linux/sunrpc/svc.h2
-rw-r--r--net/sunrpc/svcsock.c3
11 files changed, 44 insertions, 47 deletions
diff --git a/fs/nfsd/nfs3proc.c b/fs/nfsd/nfs3proc.c
index f61142afea44..0c4fab018791 100644
--- a/fs/nfsd/nfs3proc.c
+++ b/fs/nfsd/nfs3proc.c
@@ -180,7 +180,7 @@ nfsd3_proc_read(struct svc_rqst *rqstp, struct nfsd3_readargs *argp,
180 fh_copy(&resp->fh, &argp->fh); 180 fh_copy(&resp->fh, &argp->fh);
181 nfserr = nfsd_read(rqstp, &resp->fh, NULL, 181 nfserr = nfsd_read(rqstp, &resp->fh, NULL,
182 argp->offset, 182 argp->offset,
183 argp->vec, argp->vlen, 183 rqstp->rq_vec, argp->vlen,
184 &resp->count); 184 &resp->count);
185 if (nfserr == 0) { 185 if (nfserr == 0) {
186 struct inode *inode = resp->fh.fh_dentry->d_inode; 186 struct inode *inode = resp->fh.fh_dentry->d_inode;
@@ -210,7 +210,7 @@ nfsd3_proc_write(struct svc_rqst *rqstp, struct nfsd3_writeargs *argp,
210 resp->committed = argp->stable; 210 resp->committed = argp->stable;
211 nfserr = nfsd_write(rqstp, &resp->fh, NULL, 211 nfserr = nfsd_write(rqstp, &resp->fh, NULL,
212 argp->offset, 212 argp->offset,
213 argp->vec, argp->vlen, 213 rqstp->rq_vec, argp->vlen,
214 argp->len, 214 argp->len,
215 &resp->committed); 215 &resp->committed);
216 resp->count = argp->count; 216 resp->count = argp->count;
diff --git a/fs/nfsd/nfs3xdr.c b/fs/nfsd/nfs3xdr.c
index 20ba728a4642..4b9aefbcc93c 100644
--- a/fs/nfsd/nfs3xdr.c
+++ b/fs/nfsd/nfs3xdr.c
@@ -344,9 +344,9 @@ nfs3svc_decode_readargs(struct svc_rqst *rqstp, u32 *p,
344 v=0; 344 v=0;
345 while (len > 0) { 345 while (len > 0) {
346 pn = rqstp->rq_resused++; 346 pn = rqstp->rq_resused++;
347 args->vec[v].iov_base = page_address(rqstp->rq_respages[pn]); 347 rqstp->rq_vec[v].iov_base = page_address(rqstp->rq_respages[pn]);
348 args->vec[v].iov_len = len < PAGE_SIZE? len : PAGE_SIZE; 348 rqstp->rq_vec[v].iov_len = len < PAGE_SIZE? len : PAGE_SIZE;
349 len -= args->vec[v].iov_len; 349 len -= rqstp->rq_vec[v].iov_len;
350 v++; 350 v++;
351 } 351 }
352 args->vlen = v; 352 args->vlen = v;
@@ -372,22 +372,22 @@ nfs3svc_decode_writeargs(struct svc_rqst *rqstp, u32 *p,
372 rqstp->rq_arg.len - hdr < len) 372 rqstp->rq_arg.len - hdr < len)
373 return 0; 373 return 0;
374 374
375 args->vec[0].iov_base = (void*)p; 375 rqstp->rq_vec[0].iov_base = (void*)p;
376 args->vec[0].iov_len = rqstp->rq_arg.head[0].iov_len - hdr; 376 rqstp->rq_vec[0].iov_len = rqstp->rq_arg.head[0].iov_len - hdr;
377 377
378 if (len > NFSSVC_MAXBLKSIZE) 378 if (len > NFSSVC_MAXBLKSIZE)
379 len = NFSSVC_MAXBLKSIZE; 379 len = NFSSVC_MAXBLKSIZE;
380 v= 0; 380 v= 0;
381 while (len > args->vec[v].iov_len) { 381 while (len > rqstp->rq_vec[v].iov_len) {
382 len -= args->vec[v].iov_len; 382 len -= rqstp->rq_vec[v].iov_len;
383 v++; 383 v++;
384 args->vec[v].iov_base = page_address(rqstp->rq_pages[v]); 384 rqstp->rq_vec[v].iov_base = page_address(rqstp->rq_pages[v]);
385 args->vec[v].iov_len = PAGE_SIZE; 385 rqstp->rq_vec[v].iov_len = PAGE_SIZE;
386 } 386 }
387 args->vec[v].iov_len = len; 387 rqstp->rq_vec[v].iov_len = len;
388 args->vlen = v+1; 388 args->vlen = v+1;
389 389
390 return args->count == args->len && args->vec[0].iov_len > 0; 390 return args->count == args->len && rqstp->rq_vec[0].iov_len > 0;
391} 391}
392 392
393int 393int
diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
index 15ded7a30a72..38b0f91175d0 100644
--- a/fs/nfsd/nfs4proc.c
+++ b/fs/nfsd/nfs4proc.c
@@ -646,7 +646,7 @@ nfsd4_write(struct svc_rqst *rqstp, struct svc_fh *current_fh, struct nfsd4_writ
646 *p++ = nfssvc_boot.tv_usec; 646 *p++ = nfssvc_boot.tv_usec;
647 647
648 status = nfsd_write(rqstp, current_fh, filp, write->wr_offset, 648 status = nfsd_write(rqstp, current_fh, filp, write->wr_offset,
649 write->wr_vec, write->wr_vlen, write->wr_buflen, 649 rqstp->rq_vec, write->wr_vlen, write->wr_buflen,
650 &write->wr_how_written); 650 &write->wr_how_written);
651 if (filp) 651 if (filp)
652 fput(filp); 652 fput(filp);
diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
index 9f30c53ac0ed..df341956254e 100644
--- a/fs/nfsd/nfs4xdr.c
+++ b/fs/nfsd/nfs4xdr.c
@@ -926,26 +926,26 @@ nfsd4_decode_write(struct nfsd4_compoundargs *argp, struct nfsd4_write *write)
926 printk(KERN_NOTICE "xdr error! (%s:%d)\n", __FILE__, __LINE__); 926 printk(KERN_NOTICE "xdr error! (%s:%d)\n", __FILE__, __LINE__);
927 goto xdr_error; 927 goto xdr_error;
928 } 928 }
929 write->wr_vec[0].iov_base = p; 929 argp->rqstp->rq_vec[0].iov_base = p;
930 write->wr_vec[0].iov_len = avail; 930 argp->rqstp->rq_vec[0].iov_len = avail;
931 v = 0; 931 v = 0;
932 len = write->wr_buflen; 932 len = write->wr_buflen;
933 while (len > write->wr_vec[v].iov_len) { 933 while (len > argp->rqstp->rq_vec[v].iov_len) {
934 len -= write->wr_vec[v].iov_len; 934 len -= argp->rqstp->rq_vec[v].iov_len;
935 v++; 935 v++;
936 write->wr_vec[v].iov_base = page_address(argp->pagelist[0]); 936 argp->rqstp->rq_vec[v].iov_base = page_address(argp->pagelist[0]);
937 argp->pagelist++; 937 argp->pagelist++;
938 if (argp->pagelen >= PAGE_SIZE) { 938 if (argp->pagelen >= PAGE_SIZE) {
939 write->wr_vec[v].iov_len = PAGE_SIZE; 939 argp->rqstp->rq_vec[v].iov_len = PAGE_SIZE;
940 argp->pagelen -= PAGE_SIZE; 940 argp->pagelen -= PAGE_SIZE;
941 } else { 941 } else {
942 write->wr_vec[v].iov_len = argp->pagelen; 942 argp->rqstp->rq_vec[v].iov_len = argp->pagelen;
943 argp->pagelen -= len; 943 argp->pagelen -= len;
944 } 944 }
945 } 945 }
946 argp->end = (u32*) (write->wr_vec[v].iov_base + write->wr_vec[v].iov_len); 946 argp->end = (u32*) (argp->rqstp->rq_vec[v].iov_base + argp->rqstp->rq_vec[v].iov_len);
947 argp->p = (u32*) (write->wr_vec[v].iov_base + (XDR_QUADLEN(len) << 2)); 947 argp->p = (u32*) (argp->rqstp->rq_vec[v].iov_base + (XDR_QUADLEN(len) << 2));
948 write->wr_vec[v].iov_len = len; 948 argp->rqstp->rq_vec[v].iov_len = len;
949 write->wr_vlen = v+1; 949 write->wr_vlen = v+1;
950 950
951 DECODE_TAIL; 951 DECODE_TAIL;
@@ -2063,9 +2063,9 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, int nfserr,
2063 v = 0; 2063 v = 0;
2064 while (len > 0) { 2064 while (len > 0) {
2065 pn = resp->rqstp->rq_resused++; 2065 pn = resp->rqstp->rq_resused++;
2066 read->rd_iov[v].iov_base = 2066 resp->rqstp->rq_vec[v].iov_base =
2067 page_address(resp->rqstp->rq_respages[pn]); 2067 page_address(resp->rqstp->rq_respages[pn]);
2068 read->rd_iov[v].iov_len = 2068 resp->rqstp->rq_vec[v].iov_len =
2069 len < PAGE_SIZE ? len : PAGE_SIZE; 2069 len < PAGE_SIZE ? len : PAGE_SIZE;
2070 v++; 2070 v++;
2071 len -= PAGE_SIZE; 2071 len -= PAGE_SIZE;
@@ -2073,7 +2073,7 @@ nfsd4_encode_read(struct nfsd4_compoundres *resp, int nfserr,
2073 read->rd_vlen = v; 2073 read->rd_vlen = v;
2074 2074
2075 nfserr = nfsd_read(read->rd_rqstp, read->rd_fhp, read->rd_filp, 2075 nfserr = nfsd_read(read->rd_rqstp, read->rd_fhp, read->rd_filp,
2076 read->rd_offset, read->rd_iov, read->rd_vlen, 2076 read->rd_offset, resp->rqstp->rq_vec, read->rd_vlen,
2077 &maxcount); 2077 &maxcount);
2078 2078
2079 if (nfserr == nfserr_symlink) 2079 if (nfserr == nfserr_symlink)
diff --git a/fs/nfsd/nfsproc.c b/fs/nfsd/nfsproc.c
index 4e06810b6104..ca4973150218 100644
--- a/fs/nfsd/nfsproc.c
+++ b/fs/nfsd/nfsproc.c
@@ -159,7 +159,7 @@ nfsd_proc_read(struct svc_rqst *rqstp, struct nfsd_readargs *argp,
159 resp->count = argp->count; 159 resp->count = argp->count;
160 nfserr = nfsd_read(rqstp, fh_copy(&resp->fh, &argp->fh), NULL, 160 nfserr = nfsd_read(rqstp, fh_copy(&resp->fh, &argp->fh), NULL,
161 argp->offset, 161 argp->offset,
162 argp->vec, argp->vlen, 162 rqstp->rq_vec, argp->vlen,
163 &resp->count); 163 &resp->count);
164 164
165 if (nfserr) return nfserr; 165 if (nfserr) return nfserr;
@@ -185,7 +185,7 @@ nfsd_proc_write(struct svc_rqst *rqstp, struct nfsd_writeargs *argp,
185 185
186 nfserr = nfsd_write(rqstp, fh_copy(&resp->fh, &argp->fh), NULL, 186 nfserr = nfsd_write(rqstp, fh_copy(&resp->fh, &argp->fh), NULL,
187 argp->offset, 187 argp->offset,
188 argp->vec, argp->vlen, 188 rqstp->rq_vec, argp->vlen,
189 argp->len, 189 argp->len,
190 &stable); 190 &stable);
191 return nfsd_return_attrs(nfserr, resp); 191 return nfsd_return_attrs(nfserr, resp);
diff --git a/fs/nfsd/nfsxdr.c b/fs/nfsd/nfsxdr.c
index ad2fba3c54f8..ab6745e78d16 100644
--- a/fs/nfsd/nfsxdr.c
+++ b/fs/nfsd/nfsxdr.c
@@ -263,9 +263,9 @@ nfssvc_decode_readargs(struct svc_rqst *rqstp, u32 *p,
263 v=0; 263 v=0;
264 while (len > 0) { 264 while (len > 0) {
265 pn = rqstp->rq_resused++; 265 pn = rqstp->rq_resused++;
266 args->vec[v].iov_base = page_address(rqstp->rq_respages[pn]); 266 rqstp->rq_vec[v].iov_base = page_address(rqstp->rq_respages[pn]);
267 args->vec[v].iov_len = len < PAGE_SIZE?len:PAGE_SIZE; 267 rqstp->rq_vec[v].iov_len = len < PAGE_SIZE?len:PAGE_SIZE;
268 len -= args->vec[v].iov_len; 268 len -= rqstp->rq_vec[v].iov_len;
269 v++; 269 v++;
270 } 270 }
271 args->vlen = v; 271 args->vlen = v;
@@ -285,21 +285,21 @@ nfssvc_decode_writeargs(struct svc_rqst *rqstp, u32 *p,
285 args->offset = ntohl(*p++); /* offset */ 285 args->offset = ntohl(*p++); /* offset */
286 p++; /* totalcount */ 286 p++; /* totalcount */
287 len = args->len = ntohl(*p++); 287 len = args->len = ntohl(*p++);
288 args->vec[0].iov_base = (void*)p; 288 rqstp->rq_vec[0].iov_base = (void*)p;
289 args->vec[0].iov_len = rqstp->rq_arg.head[0].iov_len - 289 rqstp->rq_vec[0].iov_len = rqstp->rq_arg.head[0].iov_len -
290 (((void*)p) - rqstp->rq_arg.head[0].iov_base); 290 (((void*)p) - rqstp->rq_arg.head[0].iov_base);
291 if (len > NFSSVC_MAXBLKSIZE) 291 if (len > NFSSVC_MAXBLKSIZE)
292 len = NFSSVC_MAXBLKSIZE; 292 len = NFSSVC_MAXBLKSIZE;
293 v = 0; 293 v = 0;
294 while (len > args->vec[v].iov_len) { 294 while (len > rqstp->rq_vec[v].iov_len) {
295 len -= args->vec[v].iov_len; 295 len -= rqstp->rq_vec[v].iov_len;
296 v++; 296 v++;
297 args->vec[v].iov_base = page_address(rqstp->rq_pages[v]); 297 rqstp->rq_vec[v].iov_base = page_address(rqstp->rq_pages[v]);
298 args->vec[v].iov_len = PAGE_SIZE; 298 rqstp->rq_vec[v].iov_len = PAGE_SIZE;
299 } 299 }
300 args->vec[v].iov_len = len; 300 rqstp->rq_vec[v].iov_len = len;
301 args->vlen = v+1; 301 args->vlen = v+1;
302 return args->vec[0].iov_len > 0; 302 return rqstp->rq_vec[0].iov_len > 0;
303} 303}
304 304
305int 305int
diff --git a/include/linux/nfsd/xdr.h b/include/linux/nfsd/xdr.h
index a38f9d776de9..0e53de87d886 100644
--- a/include/linux/nfsd/xdr.h
+++ b/include/linux/nfsd/xdr.h
@@ -30,7 +30,6 @@ struct nfsd_readargs {
30 struct svc_fh fh; 30 struct svc_fh fh;
31 __u32 offset; 31 __u32 offset;
32 __u32 count; 32 __u32 count;
33 struct kvec vec[RPCSVC_MAXPAGES];
34 int vlen; 33 int vlen;
35}; 34};
36 35
@@ -38,7 +37,6 @@ struct nfsd_writeargs {
38 svc_fh fh; 37 svc_fh fh;
39 __u32 offset; 38 __u32 offset;
40 int len; 39 int len;
41 struct kvec vec[RPCSVC_MAXPAGES];
42 int vlen; 40 int vlen;
43}; 41};
44 42
diff --git a/include/linux/nfsd/xdr3.h b/include/linux/nfsd/xdr3.h
index a4322741f8b9..474d882dc2f3 100644
--- a/include/linux/nfsd/xdr3.h
+++ b/include/linux/nfsd/xdr3.h
@@ -33,7 +33,6 @@ struct nfsd3_readargs {
33 struct svc_fh fh; 33 struct svc_fh fh;
34 __u64 offset; 34 __u64 offset;
35 __u32 count; 35 __u32 count;
36 struct kvec vec[RPCSVC_MAXPAGES];
37 int vlen; 36 int vlen;
38}; 37};
39 38
@@ -43,7 +42,6 @@ struct nfsd3_writeargs {
43 __u32 count; 42 __u32 count;
44 int stable; 43 int stable;
45 __u32 len; 44 __u32 len;
46 struct kvec vec[RPCSVC_MAXPAGES];
47 int vlen; 45 int vlen;
48}; 46};
49 47
diff --git a/include/linux/nfsd/xdr4.h b/include/linux/nfsd/xdr4.h
index 77adba7d2281..66e642762a07 100644
--- a/include/linux/nfsd/xdr4.h
+++ b/include/linux/nfsd/xdr4.h
@@ -241,7 +241,6 @@ struct nfsd4_read {
241 stateid_t rd_stateid; /* request */ 241 stateid_t rd_stateid; /* request */
242 u64 rd_offset; /* request */ 242 u64 rd_offset; /* request */
243 u32 rd_length; /* request */ 243 u32 rd_length; /* request */
244 struct kvec rd_iov[RPCSVC_MAXPAGES];
245 int rd_vlen; 244 int rd_vlen;
246 struct file *rd_filp; 245 struct file *rd_filp;
247 246
@@ -326,7 +325,6 @@ struct nfsd4_write {
326 u64 wr_offset; /* request */ 325 u64 wr_offset; /* request */
327 u32 wr_stable_how; /* request */ 326 u32 wr_stable_how; /* request */
328 u32 wr_buflen; /* request */ 327 u32 wr_buflen; /* request */
329 struct kvec wr_vec[RPCSVC_MAXPAGES]; /* request */
330 int wr_vlen; 328 int wr_vlen;
331 329
332 u32 wr_bytes_written; /* response */ 330 u32 wr_bytes_written; /* response */
diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
index 3669e91c43b8..cb0ed9beb227 100644
--- a/include/linux/sunrpc/svc.h
+++ b/include/linux/sunrpc/svc.h
@@ -192,6 +192,8 @@ struct svc_rqst {
192 struct page * *rq_respages; /* points into rq_pages */ 192 struct page * *rq_respages; /* points into rq_pages */
193 int rq_resused; /* number of pages used for result */ 193 int rq_resused; /* number of pages used for result */
194 194
195 struct kvec rq_vec[RPCSVC_MAXPAGES]; /* generally useful.. */
196
195 __be32 rq_xid; /* transmission id */ 197 __be32 rq_xid; /* transmission id */
196 u32 rq_prog; /* program number */ 198 u32 rq_prog; /* program number */
197 u32 rq_vers; /* program version */ 199 u32 rq_vers; /* program version */
diff --git a/net/sunrpc/svcsock.c b/net/sunrpc/svcsock.c
index 25096d53667a..1d512337ccd9 100644
--- a/net/sunrpc/svcsock.c
+++ b/net/sunrpc/svcsock.c
@@ -955,7 +955,7 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp)
955 struct svc_sock *svsk = rqstp->rq_sock; 955 struct svc_sock *svsk = rqstp->rq_sock;
956 struct svc_serv *serv = svsk->sk_server; 956 struct svc_serv *serv = svsk->sk_server;
957 int len; 957 int len;
958 struct kvec vec[RPCSVC_MAXPAGES]; 958 struct kvec *vec;
959 int pnum, vlen; 959 int pnum, vlen;
960 960
961 dprintk("svc: tcp_recv %p data %d conn %d close %d\n", 961 dprintk("svc: tcp_recv %p data %d conn %d close %d\n",
@@ -1053,6 +1053,7 @@ svc_tcp_recvfrom(struct svc_rqst *rqstp)
1053 len = svsk->sk_reclen; 1053 len = svsk->sk_reclen;
1054 set_bit(SK_DATA, &svsk->sk_flags); 1054 set_bit(SK_DATA, &svsk->sk_flags);
1055 1055
1056 vec = rqstp->rq_vec;
1056 vec[0] = rqstp->rq_arg.head[0]; 1057 vec[0] = rqstp->rq_arg.head[0];
1057 vlen = PAGE_SIZE; 1058 vlen = PAGE_SIZE;
1058 pnum = 1; 1059 pnum = 1;