Skip to content

Commit a38eb63

Browse files
rhvgoyalaxboe
authored andcommitted
blk-throttle: Take blkcg->lock while traversing blkcg->policy_list
blkcg->policy_list is protected by blkcg->lock. Its not rcu protected list. So even for readers, they need to take blkcg->lock. There are few functions which were reading the list without taking lock. Fix it. Signed-off-by: Vivek Goyal <vgoyal@redhat.com> Acked-by: Tejun Heo <tj@kernel.org> Signed-off-by: Jens Axboe <axboe@kernel.dk>
1 parent e060f00 commit a38eb63

1 file changed

Lines changed: 40 additions & 14 deletions

File tree

‎block/blk-cgroup.c‎

Lines changed: 40 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -869,60 +869,86 @@ unsigned int blkcg_get_weight(struct blkio_cgroup *blkcg,
869869
dev_t dev)
870870
{
871871
struct blkio_policy_node *pn;
872+
unsigned long flags;
873+
unsigned int weight;
874+
875+
spin_lock_irqsave(&blkcg->lock, flags);
872876

873877
pn = blkio_policy_search_node(blkcg, dev, BLKIO_POLICY_PROP,
874878
BLKIO_PROP_weight_device);
875879
if (pn)
876-
return pn->val.weight;
880+
weight = pn->val.weight;
877881
else
878-
return blkcg->weight;
882+
weight = blkcg->weight;
883+
884+
spin_unlock_irqrestore(&blkcg->lock, flags);
885+
886+
return weight;
879887
}
880888
EXPORT_SYMBOL_GPL(blkcg_get_weight);
881889

882890
uint64_t blkcg_get_read_bps(struct blkio_cgroup *blkcg, dev_t dev)
883891
{
884892
struct blkio_policy_node *pn;
893+
unsigned long flags;
894+
uint64_t bps = -1;
885895

896+
spin_lock_irqsave(&blkcg->lock, flags);
886897
pn = blkio_policy_search_node(blkcg, dev, BLKIO_POLICY_THROTL,
887898
BLKIO_THROTL_read_bps_device);
888899
if (pn)
889-
return pn->val.bps;
890-
else
891-
return -1;
900+
bps = pn->val.bps;
901+
spin_unlock_irqrestore(&blkcg->lock, flags);
902+
903+
return bps;
892904
}
893905

894906
uint64_t blkcg_get_write_bps(struct blkio_cgroup *blkcg, dev_t dev)
895907
{
896908
struct blkio_policy_node *pn;
909+
unsigned long flags;
910+
uint64_t bps = -1;
911+
912+
spin_lock_irqsave(&blkcg->lock, flags);
897913
pn = blkio_policy_search_node(blkcg, dev, BLKIO_POLICY_THROTL,
898914
BLKIO_THROTL_write_bps_device);
899915
if (pn)
900-
return pn->val.bps;
901-
else
902-
return -1;
916+
bps = pn->val.bps;
917+
spin_unlock_irqrestore(&blkcg->lock, flags);
918+
919+
return bps;
903920
}
904921

905922
unsigned int blkcg_get_read_iops(struct blkio_cgroup *blkcg, dev_t dev)
906923
{
907924
struct blkio_policy_node *pn;
925+
unsigned long flags;
926+
unsigned int iops = -1;
908927

928+
spin_lock_irqsave(&blkcg->lock, flags);
909929
pn = blkio_policy_search_node(blkcg, dev, BLKIO_POLICY_THROTL,
910930
BLKIO_THROTL_read_iops_device);
911931
if (pn)
912-
return pn->val.iops;
913-
else
914-
return -1;
932+
iops = pn->val.iops;
933+
spin_unlock_irqrestore(&blkcg->lock, flags);
934+
935+
return iops;
915936
}
916937

917938
unsigned int blkcg_get_write_iops(struct blkio_cgroup *blkcg, dev_t dev)
918939
{
919940
struct blkio_policy_node *pn;
941+
unsigned long flags;
942+
unsigned int iops = -1;
943+
944+
spin_lock_irqsave(&blkcg->lock, flags);
920945
pn = blkio_policy_search_node(blkcg, dev, BLKIO_POLICY_THROTL,
921946
BLKIO_THROTL_write_iops_device);
922947
if (pn)
923-
return pn->val.iops;
924-
else
925-
return -1;
948+
iops = pn->val.iops;
949+
spin_unlock_irqrestore(&blkcg->lock, flags);
950+
951+
return iops;
926952
}
927953

928954
/* Checks whether user asked for deleting a policy rule */

0 commit comments

Comments
 (0)