Skip to contentSkip to conversation

scsi: target: tcmu: allocate zeroed pages for data area

PATCH Applied Bodo Stroesser 2 participants 3 messages Oct 13, 2021 – Oct 21, 2021

Subsystems (3)
lore
Share & tools
lore

Bodo Stroesser

author maintainer
#0 lore raw

PATCH 1/1 scsi: target: tcmu: allocate zeroed pages for data area

Tcmu populates the data area (used for communication with userspace) with pages that are allocated by calling alloc_page(GFP_NOIO).
Therefore previous content of the allocated pages is exposed to user space. Avoid this by adding __GFP_ZERO flag.

Zeroing the pages does (nearly) not affect tcmu throughput, because allocated pages are re-used for the data transfers of later SCSI cmds.

---
 drivers/target/target_core_user.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
drivers/target/target_core_user.c +3 -2
index dc220fad06fa..a19e53877b0b 100644
@@ -5,6 +5,7 @@
  * Copyright (C) 2015 Arrikto, Inc.
  * Copyright (C) 2017 Chinamobile, Inc.
  */
+#include <linux/delay.h>
 
 #include <linux/spinlock.h>
 #include <linux/module.h>
@@ -523,8 +524,8 @@ static inline int tcmu_get_empty_block(struct tcmu_dev *udev,
 	rcu_read_unlock();
 
 	for (i = cnt; i < page_cnt; i++) {
-		/* try to get new page from the mm */
-		page = alloc_page(GFP_NOIO);
+		/* try to get new zeroed page from the mm */
+		page = alloc_page(GFP_NOIO | __GFP_ZERO);
 		if (!page)
 			break;
 
Signature · 1 line
2.12.3
#1 lore raw

Bodo,

Quoted 4 lines

Tcmu populates the data area (used for communication with userspace) with pages that are allocated by calling alloc_page(GFP_NOIO). Therefore previous content of the allocated pages is exposed to user space. Avoid this by adding __GFP_ZERO flag.

Applied to 5.16/scsi-staging, thanks!

Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering
#2 lore raw
In reply to Bodo Stroesser
Quoted 11 lines · Bodo Stroesser

Tcmu populates the data area (used for communication with userspace) with pages that are allocated by calling alloc_page(GFP_NOIO).
Therefore previous content of the allocated pages is exposed to user space. Avoid this by adding __GFP_ZERO flag.

Zeroing the pages does (nearly) not affect tcmu throughput, because allocated pages are re-used for the data transfers of later SCSI cmds.

[...]

Applied to 5.16/scsi-queue, thanks!

[1/1] scsi: target: tcmu: allocate zeroed pages for data area

      https://git.kernel.org/mkp/scsi/c/1d2ac7b69d6a
Signature · 1 line
Martin K. Petersen	Oracle Linux Engineering