Message ID | 20180530194807.31657-6-longli@linuxonhyperv.com (mailing list archive) |
---|---|
State | Not Applicable |
Headers | show |
On 5/30/2018 3:47 PM, Long Li wrote: > From: Long Li <longli@microsoft.com> > > It's possible that the page offset is non-zero in the pages in a request, > change the function to calculate the correct data buffer length. > > Signed-off-by: Long Li <longli@microsoft.com> > --- > fs/cifs/transport.c | 20 +++++++++++++++++--- > 1 file changed, 17 insertions(+), 3 deletions(-) > > diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c > index 927226a..d6b5523 100644 > --- a/fs/cifs/transport.c > +++ b/fs/cifs/transport.c > @@ -212,10 +212,24 @@ rqst_len(struct smb_rqst *rqst) > for (i = 0; i < rqst->rq_nvec; i++) > buflen += iov[i].iov_len; > > - /* add in the page array if there is one */ > + /* > + * Add in the page array if there is one. The caller needs to make > + * sure rq_offset and rq_tailsz are set correctly. If a buffer of > + * multiple pages ends at page boundary, rq_tailsz needs to be set to > + * PAGE_SIZE. > + */ > if (rqst->rq_npages) { > - buflen += rqst->rq_pagesz * (rqst->rq_npages - 1); > - buflen += rqst->rq_tailsz; > + if (rqst->rq_npages == 1) > + buflen += rqst->rq_tailsz; > + else { > + /* > + * If there is more than one page, calculate the > + * buffer length based on rq_offset and rq_tailsz > + */ > + buflen += rqst->rq_pagesz * (rqst->rq_npages - 1) - > + rqst->rq_offset; > + buflen += rqst->rq_tailsz; > + } Wouldn't it be simpler to keep the original code, but then just subtract the rq_offset? buflen += rqst->rq_pagesz * (rqst->rq_npages - 1); buflen += rqst->rq_tailsz; buflen -= rqst->rq_offset; It's kind of confusing as written. Also, what if it's just one page, but has a non-zero offset? Is that somehow not possible? My suggested code would take that into account, yours doesn't. Tom. > } > > return buflen; > -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
PiBTdWJqZWN0OiBSZTogW1BhdGNoIHYyIDA1LzE1XSBDSUZTOiBDYWxjdWxhdGUgdGhlI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DQo+ID4gICAJcmV0dXJuIGJ1ZmxlbjsNCj4gPg0K -- To unsubscribe from this list: send the line "unsubscribe linux-rdma" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html
diff --git a/fs/cifs/transport.c b/fs/cifs/transport.c index 927226a..d6b5523 100644 --- a/fs/cifs/transport.c +++ b/fs/cifs/transport.c @@ -212,10 +212,24 @@ rqst_len(struct smb_rqst *rqst) for (i = 0; i < rqst->rq_nvec; i++) buflen += iov[i].iov_len; - /* add in the page array if there is one */ + /* + * Add in the page array if there is one. The caller needs to make + * sure rq_offset and rq_tailsz are set correctly. If a buffer of + * multiple pages ends at page boundary, rq_tailsz needs to be set to + * PAGE_SIZE. + */ if (rqst->rq_npages) { - buflen += rqst->rq_pagesz * (rqst->rq_npages - 1); - buflen += rqst->rq_tailsz; + if (rqst->rq_npages == 1) + buflen += rqst->rq_tailsz; + else { + /* + * If there is more than one page, calculate the + * buffer length based on rq_offset and rq_tailsz + */ + buflen += rqst->rq_pagesz * (rqst->rq_npages - 1) - + rqst->rq_offset; + buflen += rqst->rq_tailsz; + } } return buflen;