@@ -1542,7 +1542,8 @@ struct bpf_prog_array *bpf_prog_array_alloc(u32 prog_cnt, gfp_t flags)
1542
1542
{
1543
1543
if (prog_cnt )
1544
1544
return kzalloc (sizeof (struct bpf_prog_array ) +
1545
- sizeof (struct bpf_prog * ) * (prog_cnt + 1 ),
1545
+ sizeof (struct bpf_prog_array_item ) *
1546
+ (prog_cnt + 1 ),
1546
1547
flags );
1547
1548
1548
1549
return & empty_prog_array .hdr ;
@@ -1556,43 +1557,45 @@ void bpf_prog_array_free(struct bpf_prog_array __rcu *progs)
1556
1557
kfree_rcu (progs , rcu );
1557
1558
}
1558
1559
1559
- int bpf_prog_array_length (struct bpf_prog_array __rcu * progs )
1560
+ int bpf_prog_array_length (struct bpf_prog_array __rcu * array )
1560
1561
{
1561
- struct bpf_prog * * prog ;
1562
+ struct bpf_prog_array_item * item ;
1562
1563
u32 cnt = 0 ;
1563
1564
1564
1565
rcu_read_lock ();
1565
- prog = rcu_dereference (progs )-> progs ;
1566
- for (; * prog ; prog ++ )
1567
- if (* prog != & dummy_bpf_prog .prog )
1566
+ item = rcu_dereference (array )-> items ;
1567
+ for (; item -> prog ; item ++ )
1568
+ if (item -> prog != & dummy_bpf_prog .prog )
1568
1569
cnt ++ ;
1569
1570
rcu_read_unlock ();
1570
1571
return cnt ;
1571
1572
}
1572
1573
1573
- static bool bpf_prog_array_copy_core (struct bpf_prog * * prog ,
1574
+
1575
+ static bool bpf_prog_array_copy_core (struct bpf_prog_array __rcu * array ,
1574
1576
u32 * prog_ids ,
1575
1577
u32 request_cnt )
1576
1578
{
1579
+ struct bpf_prog_array_item * item ;
1577
1580
int i = 0 ;
1578
1581
1579
- for (; * prog ; prog ++ ) {
1580
- if (* prog == & dummy_bpf_prog .prog )
1582
+ item = rcu_dereference (array )-> items ;
1583
+ for (; item -> prog ; item ++ ) {
1584
+ if (item -> prog == & dummy_bpf_prog .prog )
1581
1585
continue ;
1582
- prog_ids [i ] = ( * prog ) -> aux -> id ;
1586
+ prog_ids [i ] = item -> prog -> aux -> id ;
1583
1587
if (++ i == request_cnt ) {
1584
- prog ++ ;
1588
+ item ++ ;
1585
1589
break ;
1586
1590
}
1587
1591
}
1588
1592
1589
- return !!(* prog );
1593
+ return !!(item -> prog );
1590
1594
}
1591
1595
1592
- int bpf_prog_array_copy_to_user (struct bpf_prog_array __rcu * progs ,
1596
+ int bpf_prog_array_copy_to_user (struct bpf_prog_array __rcu * array ,
1593
1597
__u32 __user * prog_ids , u32 cnt )
1594
1598
{
1595
- struct bpf_prog * * prog ;
1596
1599
unsigned long err = 0 ;
1597
1600
bool nospc ;
1598
1601
u32 * ids ;
@@ -1611,8 +1614,7 @@ int bpf_prog_array_copy_to_user(struct bpf_prog_array __rcu *progs,
1611
1614
if (!ids )
1612
1615
return - ENOMEM ;
1613
1616
rcu_read_lock ();
1614
- prog = rcu_dereference (progs )-> progs ;
1615
- nospc = bpf_prog_array_copy_core (prog , ids , cnt );
1617
+ nospc = bpf_prog_array_copy_core (array , ids , cnt );
1616
1618
rcu_read_unlock ();
1617
1619
err = copy_to_user (prog_ids , ids , cnt * sizeof (u32 ));
1618
1620
kfree (ids );
@@ -1623,14 +1625,14 @@ int bpf_prog_array_copy_to_user(struct bpf_prog_array __rcu *progs,
1623
1625
return 0 ;
1624
1626
}
1625
1627
1626
- void bpf_prog_array_delete_safe (struct bpf_prog_array __rcu * progs ,
1628
+ void bpf_prog_array_delete_safe (struct bpf_prog_array __rcu * array ,
1627
1629
struct bpf_prog * old_prog )
1628
1630
{
1629
- struct bpf_prog * * prog = progs -> progs ;
1631
+ struct bpf_prog_array_item * item = array -> items ;
1630
1632
1631
- for (; * prog ; prog ++ )
1632
- if (* prog == old_prog ) {
1633
- WRITE_ONCE (* prog , & dummy_bpf_prog .prog );
1633
+ for (; item -> prog ; item ++ )
1634
+ if (item -> prog == old_prog ) {
1635
+ WRITE_ONCE (item -> prog , & dummy_bpf_prog .prog );
1634
1636
break ;
1635
1637
}
1636
1638
}
@@ -1641,7 +1643,7 @@ int bpf_prog_array_copy(struct bpf_prog_array __rcu *old_array,
1641
1643
struct bpf_prog_array * * new_array )
1642
1644
{
1643
1645
int new_prog_cnt , carry_prog_cnt = 0 ;
1644
- struct bpf_prog * * existing_prog ;
1646
+ struct bpf_prog_array_item * existing ;
1645
1647
struct bpf_prog_array * array ;
1646
1648
bool found_exclude = false;
1647
1649
int new_prog_idx = 0 ;
@@ -1650,15 +1652,15 @@ int bpf_prog_array_copy(struct bpf_prog_array __rcu *old_array,
1650
1652
* the new array.
1651
1653
*/
1652
1654
if (old_array ) {
1653
- existing_prog = old_array -> progs ;
1654
- for (; * existing_prog ; existing_prog ++ ) {
1655
- if (* existing_prog == exclude_prog ) {
1655
+ existing = old_array -> items ;
1656
+ for (; existing -> prog ; existing ++ ) {
1657
+ if (existing -> prog == exclude_prog ) {
1656
1658
found_exclude = true;
1657
1659
continue ;
1658
1660
}
1659
- if (* existing_prog != & dummy_bpf_prog .prog )
1661
+ if (existing -> prog != & dummy_bpf_prog .prog )
1660
1662
carry_prog_cnt ++ ;
1661
- if (* existing_prog == include_prog )
1663
+ if (existing -> prog == include_prog )
1662
1664
return - EEXIST ;
1663
1665
}
1664
1666
}
@@ -1684,15 +1686,17 @@ int bpf_prog_array_copy(struct bpf_prog_array __rcu *old_array,
1684
1686
1685
1687
/* Fill in the new prog array */
1686
1688
if (carry_prog_cnt ) {
1687
- existing_prog = old_array -> progs ;
1688
- for (; * existing_prog ; existing_prog ++ )
1689
- if (* existing_prog != exclude_prog &&
1690
- * existing_prog != & dummy_bpf_prog .prog )
1691
- array -> progs [new_prog_idx ++ ] = * existing_prog ;
1689
+ existing = old_array -> items ;
1690
+ for (; existing -> prog ; existing ++ )
1691
+ if (existing -> prog != exclude_prog &&
1692
+ existing -> prog != & dummy_bpf_prog .prog ) {
1693
+ array -> items [new_prog_idx ++ ].prog =
1694
+ existing -> prog ;
1695
+ }
1692
1696
}
1693
1697
if (include_prog )
1694
- array -> progs [new_prog_idx ++ ] = include_prog ;
1695
- array -> progs [new_prog_idx ] = NULL ;
1698
+ array -> items [new_prog_idx ++ ]. prog = include_prog ;
1699
+ array -> items [new_prog_idx ]. prog = NULL ;
1696
1700
* new_array = array ;
1697
1701
return 0 ;
1698
1702
}
@@ -1701,7 +1705,6 @@ int bpf_prog_array_copy_info(struct bpf_prog_array __rcu *array,
1701
1705
u32 * prog_ids , u32 request_cnt ,
1702
1706
u32 * prog_cnt )
1703
1707
{
1704
- struct bpf_prog * * prog ;
1705
1708
u32 cnt = 0 ;
1706
1709
1707
1710
if (array )
@@ -1714,8 +1717,7 @@ int bpf_prog_array_copy_info(struct bpf_prog_array __rcu *array,
1714
1717
return 0 ;
1715
1718
1716
1719
/* this function is called under trace/bpf_trace.c: bpf_event_mutex */
1717
- prog = rcu_dereference_check (array , 1 )-> progs ;
1718
- return bpf_prog_array_copy_core (prog , prog_ids , request_cnt ) ? - ENOSPC
1720
+ return bpf_prog_array_copy_core (array , prog_ids , request_cnt ) ? - ENOSPC
1719
1721
: 0 ;
1720
1722
}
1721
1723
0 commit comments