Skip to contentSkip to conversation

writeback: don't access page->mapping directly in track_foreign_dirty TP

block/for-next Applied Tejun Heo 3 participants 3 messages Aug 30, 2019 – Sep 2, 2019

Subsystems (3)
lore
Share & tools
lore

Tejun Heo

author
#0 lore raw

page->mapping may encode different values in it and page_mapping() should always be used to access the mapping pointer. track_foreign_dirty tracepoint was incorrectly accessing page->mapping directly. Use page_mapping() instead. Also, add NULL checks while at it.

Fixes 3a8e9ac89e6a ("writeback: add tracepoints for cgroup foreign writebacks")
---
 include/trace/events/writeback.h |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
include/trace/events/writeback.h +4 -1
index 3dc9fb9e7c78..3a27335fce2c 100644
@@ -251,9 +251,12 @@ TRACE_EVENT(track_foreign_dirty,
 	),
 
 	TP_fast_assign(
+		struct address_space *mapping = page_mapping(page);
+		struct inode *inode = mapping ? mapping->host : NULL;
+
 		strncpy(__entry->name,	dev_name(wb->bdi->dev), 32);
 		__entry->bdi_id		= wb->bdi->id;
-		__entry->ino		= page->mapping->host->i_ino;
+		__entry->ino		= inode ? inode->i_ino : 0;
 		__entry->memcg_id	= wb->memcg_css->id;
 		__entry->cgroup_ino	= __trace_wb_assign_cgroup(wb);
 		__entry->page_cgroup_ino = page->mem_cgroup->css.cgroup->kn->id.ino;
maintainer Applied
#1 lore raw
Quoted 5 lines · Tejun Heo

page->mapping may encode different values in it and page_mapping() should always be used to access the mapping pointer. track_foreign_dirty tracepoint was incorrectly accessing page->mapping directly. Use page_mapping() instead. Also, add NULL checks while at it.

Applied, thanks.

Signature · 1 line
Jens Axboe
maintainer
#2 lore raw
In reply to Tejun Heo
Quoted 9 lines · Tejun Heo

page->mapping may encode different values in it and page_mapping() should always be used to access the mapping pointer. track_foreign_dirty tracepoint was incorrectly accessing page->mapping directly. Use page_mapping() instead. Also, add NULL checks while at it.

Fixes 3a8e9ac89e6a ("writeback: add tracepoints for cgroup foreign writebacks")

I can see Jens already picked this up so this is just informative: The patch now looks good to me.

Honza

Quoted 22 lines
---
 include/trace/events/writeback.h |    5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
include/trace/events/writeback.h +4 -1
index 3dc9fb9e7c78..3a27335fce2c 100644
@@ -251,9 +251,12 @@ TRACE_EVENT(track_foreign_dirty,
 	),
 
 	TP_fast_assign(
+		struct address_space *mapping = page_mapping(page);
+		struct inode *inode = mapping ? mapping->host : NULL;
+
 		strncpy(__entry->name,	dev_name(wb->bdi->dev), 32);
 		__entry->bdi_id		= wb->bdi->id;
-		__entry->ino		= page->mapping->host->i_ino;
+		__entry->ino		= inode ? inode->i_ino : 0;
 		__entry->memcg_id	= wb->memcg_css->id;
 		__entry->cgroup_ino	= __trace_wb_assign_cgroup(wb);
 		__entry->page_cgroup_ino = page->mem_cgroup->css.cgroup->kn->id.ino;
Signature · 2 lines
Jan Kara <[email protected]>
SUSE Labs, CR