Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

target/rd: T10-Dif: RAM disk is allocating more space than required.

Ram disk is allocating 8x more space than required for diff data.
For large RAM disk test, there is small potential for memory
starvation.

(Use block_size when calculating total_sg_needed - sagi + nab)

Signed-off-by: Giridhar Malavali <giridhar.malavali@qlogic.com>
Signed-off-by: Quinn Tran <quinn.tran@qlogic.com>
Cc: <stable@vger.kernel.org> #3.14+
Signed-off-by: Nicholas Bellinger <nab@linux-iscsi.org>

authored by

Quinn Tran and committed by
Nicholas Bellinger
9d2e59f2 d444edc6

+10 -4
+10 -4
drivers/target/target_core_rd.c
··· 242 242 rd_dev->sg_prot_count = 0; 243 243 } 244 244 245 - static int rd_build_prot_space(struct rd_dev *rd_dev, int prot_length) 245 + static int rd_build_prot_space(struct rd_dev *rd_dev, int prot_length, int block_size) 246 246 { 247 247 struct rd_dev_sg_table *sg_table; 248 248 u32 total_sg_needed, sg_tables; ··· 252 252 253 253 if (rd_dev->rd_flags & RDF_NULLIO) 254 254 return 0; 255 - 256 - total_sg_needed = rd_dev->rd_page_count / prot_length; 255 + /* 256 + * prot_length=8byte dif data 257 + * tot sg needed = rd_page_count * (PGSZ/block_size) * 258 + * (prot_length/block_size) + pad 259 + * PGSZ canceled each other. 260 + */ 261 + total_sg_needed = (rd_dev->rd_page_count * prot_length / block_size) + 1; 257 262 258 263 sg_tables = (total_sg_needed / max_sg_per_table) + 1; 259 264 ··· 611 606 if (!dev->dev_attrib.pi_prot_type) 612 607 return 0; 613 608 614 - return rd_build_prot_space(rd_dev, dev->prot_length); 609 + return rd_build_prot_space(rd_dev, dev->prot_length, 610 + dev->dev_attrib.block_size); 615 611 } 616 612 617 613 static void rd_free_prot(struct se_device *dev)