locking/atomics: COCCINELLE/treewide: Convert trivial ACCESS_ONCE() patterns to READ_ONCE()/WRITE_ONCE()
Please do not apply this to mainline directly, instead please re-run the coccinelle script shown below and apply its output. For several reasons, it is desirable to use {READ,WRITE}_ONCE() in preference to ACCESS_ONCE(), and new code is expected to use one of the former. So far, there's been no reason to change most existing uses of ACCESS_ONCE(), as these aren't harmful, and changing them results in churn. However, for some features, the read/write distinction is critical to correct operation. To distinguish these cases, separate read/write accessors must be used. This patch migrates (most) remaining ACCESS_ONCE() instances to {READ,WRITE}_ONCE(), using the following coccinelle script: ---- // Convert trivial ACCESS_ONCE() uses to equivalent READ_ONCE() and // WRITE_ONCE() // $ make coccicheck COCCI=/home/mark/once.cocci SPFLAGS="--include-headers" MODE=patch virtual patch @ depends on patch @ expression E1, E2; @@ - ACCESS_ONCE(E1) = E2 + WRITE_ONCE(E1, E2) @ depends on patch @ expression E; @@ - ACCESS_ONCE(E) + READ_ONCE(E) ---- Signed-off-by: Mark Rutland <mark.rutland@arm.com> Signed-off-by: Paul E. McKenney <paulmck@linux.vnet.ibm.com> Cc: Linus Torvalds <torvalds@linux-foundation.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Thomas Gleixner <tglx@linutronix.de> Cc: davem@davemloft.net Cc: linux-arch@vger.kernel.org Cc: mpe@ellerman.id.au Cc: shuah@kernel.org Cc: snitzer@redhat.com Cc: thor.thayer@linux.intel.com Cc: tj@kernel.org Cc: viro@zeniv.linux.org.uk Cc: will.deacon@arm.com Link: http://lkml.kernel.org/r/1508792849-3115-19-git-send-email-paulmck@linux.vnet.ibm.com Signed-off-by: Ingo Molnar <mingo@kernel.org>
This commit is contained in:

committed by
Ingo Molnar

parent
b03a0fe0c5
commit
6aa7de0591
@@ -264,7 +264,7 @@ static void i40e_dbg_dump_vsi_seid(struct i40e_pf *pf, int seid)
|
||||
vsi->rx_buf_failed, vsi->rx_page_failed);
|
||||
rcu_read_lock();
|
||||
for (i = 0; i < vsi->num_queue_pairs; i++) {
|
||||
struct i40e_ring *rx_ring = ACCESS_ONCE(vsi->rx_rings[i]);
|
||||
struct i40e_ring *rx_ring = READ_ONCE(vsi->rx_rings[i]);
|
||||
|
||||
if (!rx_ring)
|
||||
continue;
|
||||
@@ -320,7 +320,7 @@ static void i40e_dbg_dump_vsi_seid(struct i40e_pf *pf, int seid)
|
||||
ITR_IS_DYNAMIC(rx_ring->rx_itr_setting) ? "dynamic" : "fixed");
|
||||
}
|
||||
for (i = 0; i < vsi->num_queue_pairs; i++) {
|
||||
struct i40e_ring *tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
|
||||
struct i40e_ring *tx_ring = READ_ONCE(vsi->tx_rings[i]);
|
||||
|
||||
if (!tx_ring)
|
||||
continue;
|
||||
|
@@ -1570,7 +1570,7 @@ static void i40e_get_ethtool_stats(struct net_device *netdev,
|
||||
}
|
||||
rcu_read_lock();
|
||||
for (j = 0; j < vsi->num_queue_pairs; j++) {
|
||||
tx_ring = ACCESS_ONCE(vsi->tx_rings[j]);
|
||||
tx_ring = READ_ONCE(vsi->tx_rings[j]);
|
||||
|
||||
if (!tx_ring)
|
||||
continue;
|
||||
|
@@ -455,7 +455,7 @@ static void i40e_get_netdev_stats_struct(struct net_device *netdev,
|
||||
u64 bytes, packets;
|
||||
unsigned int start;
|
||||
|
||||
tx_ring = ACCESS_ONCE(vsi->tx_rings[i]);
|
||||
tx_ring = READ_ONCE(vsi->tx_rings[i]);
|
||||
if (!tx_ring)
|
||||
continue;
|
||||
i40e_get_netdev_stats_struct_tx(tx_ring, stats);
|
||||
@@ -791,7 +791,7 @@ static void i40e_update_vsi_stats(struct i40e_vsi *vsi)
|
||||
rcu_read_lock();
|
||||
for (q = 0; q < vsi->num_queue_pairs; q++) {
|
||||
/* locate Tx ring */
|
||||
p = ACCESS_ONCE(vsi->tx_rings[q]);
|
||||
p = READ_ONCE(vsi->tx_rings[q]);
|
||||
|
||||
do {
|
||||
start = u64_stats_fetch_begin_irq(&p->syncp);
|
||||
|
@@ -130,7 +130,7 @@ static int i40e_ptp_adjfreq(struct ptp_clock_info *ptp, s32 ppb)
|
||||
}
|
||||
|
||||
smp_mb(); /* Force any pending update before accessing. */
|
||||
adj = ACCESS_ONCE(pf->ptp_base_adj);
|
||||
adj = READ_ONCE(pf->ptp_base_adj);
|
||||
|
||||
freq = adj;
|
||||
freq *= ppb;
|
||||
@@ -499,7 +499,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
|
||||
wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
|
||||
|
||||
/* Update the base adjustement value. */
|
||||
ACCESS_ONCE(pf->ptp_base_adj) = incval;
|
||||
WRITE_ONCE(pf->ptp_base_adj, incval);
|
||||
smp_mb(); /* Force the above update. */
|
||||
}
|
||||
|
||||
|
@@ -375,7 +375,7 @@ u32 igb_rd32(struct e1000_hw *hw, u32 reg);
|
||||
/* write operations, indexed using DWORDS */
|
||||
#define wr32(reg, val) \
|
||||
do { \
|
||||
u8 __iomem *hw_addr = ACCESS_ONCE((hw)->hw_addr); \
|
||||
u8 __iomem *hw_addr = READ_ONCE((hw)->hw_addr); \
|
||||
if (!E1000_REMOVED(hw_addr)) \
|
||||
writel((val), &hw_addr[(reg)]); \
|
||||
} while (0)
|
||||
|
@@ -750,7 +750,7 @@ static void igb_cache_ring_register(struct igb_adapter *adapter)
|
||||
u32 igb_rd32(struct e1000_hw *hw, u32 reg)
|
||||
{
|
||||
struct igb_adapter *igb = container_of(hw, struct igb_adapter, hw);
|
||||
u8 __iomem *hw_addr = ACCESS_ONCE(hw->hw_addr);
|
||||
u8 __iomem *hw_addr = READ_ONCE(hw->hw_addr);
|
||||
u32 value = 0;
|
||||
|
||||
if (E1000_REMOVED(hw_addr))
|
||||
|
@@ -161,7 +161,7 @@ static inline bool ixgbe_removed(void __iomem *addr)
|
||||
|
||||
static inline void ixgbe_write_reg(struct ixgbe_hw *hw, u32 reg, u32 value)
|
||||
{
|
||||
u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr);
|
||||
u8 __iomem *reg_addr = READ_ONCE(hw->hw_addr);
|
||||
|
||||
if (ixgbe_removed(reg_addr))
|
||||
return;
|
||||
@@ -180,7 +180,7 @@ static inline void writeq(u64 val, void __iomem *addr)
|
||||
|
||||
static inline void ixgbe_write_reg64(struct ixgbe_hw *hw, u32 reg, u64 value)
|
||||
{
|
||||
u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr);
|
||||
u8 __iomem *reg_addr = READ_ONCE(hw->hw_addr);
|
||||
|
||||
if (ixgbe_removed(reg_addr))
|
||||
return;
|
||||
|
@@ -380,7 +380,7 @@ static void ixgbe_check_remove(struct ixgbe_hw *hw, u32 reg)
|
||||
*/
|
||||
u32 ixgbe_read_reg(struct ixgbe_hw *hw, u32 reg)
|
||||
{
|
||||
u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr);
|
||||
u8 __iomem *reg_addr = READ_ONCE(hw->hw_addr);
|
||||
u32 value;
|
||||
|
||||
if (ixgbe_removed(reg_addr))
|
||||
@@ -8630,7 +8630,7 @@ static void ixgbe_get_stats64(struct net_device *netdev,
|
||||
|
||||
rcu_read_lock();
|
||||
for (i = 0; i < adapter->num_rx_queues; i++) {
|
||||
struct ixgbe_ring *ring = ACCESS_ONCE(adapter->rx_ring[i]);
|
||||
struct ixgbe_ring *ring = READ_ONCE(adapter->rx_ring[i]);
|
||||
u64 bytes, packets;
|
||||
unsigned int start;
|
||||
|
||||
@@ -8646,12 +8646,12 @@ static void ixgbe_get_stats64(struct net_device *netdev,
|
||||
}
|
||||
|
||||
for (i = 0; i < adapter->num_tx_queues; i++) {
|
||||
struct ixgbe_ring *ring = ACCESS_ONCE(adapter->tx_ring[i]);
|
||||
struct ixgbe_ring *ring = READ_ONCE(adapter->tx_ring[i]);
|
||||
|
||||
ixgbe_get_ring_stats64(stats, ring);
|
||||
}
|
||||
for (i = 0; i < adapter->num_xdp_queues; i++) {
|
||||
struct ixgbe_ring *ring = ACCESS_ONCE(adapter->xdp_ring[i]);
|
||||
struct ixgbe_ring *ring = READ_ONCE(adapter->xdp_ring[i]);
|
||||
|
||||
ixgbe_get_ring_stats64(stats, ring);
|
||||
}
|
||||
|
@@ -378,7 +378,7 @@ static int ixgbe_ptp_adjfreq_82599(struct ptp_clock_info *ptp, s32 ppb)
|
||||
}
|
||||
|
||||
smp_mb();
|
||||
incval = ACCESS_ONCE(adapter->base_incval);
|
||||
incval = READ_ONCE(adapter->base_incval);
|
||||
|
||||
freq = incval;
|
||||
freq *= ppb;
|
||||
@@ -1159,7 +1159,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
|
||||
}
|
||||
|
||||
/* update the base incval used to calculate frequency adjustment */
|
||||
ACCESS_ONCE(adapter->base_incval) = incval;
|
||||
WRITE_ONCE(adapter->base_incval, incval);
|
||||
smp_mb();
|
||||
|
||||
/* need lock to prevent incorrect read while modifying cyclecounter */
|
||||
|
@@ -164,7 +164,7 @@ static void ixgbevf_check_remove(struct ixgbe_hw *hw, u32 reg)
|
||||
|
||||
u32 ixgbevf_read_reg(struct ixgbe_hw *hw, u32 reg)
|
||||
{
|
||||
u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr);
|
||||
u8 __iomem *reg_addr = READ_ONCE(hw->hw_addr);
|
||||
u32 value;
|
||||
|
||||
if (IXGBE_REMOVED(reg_addr))
|
||||
|
@@ -182,7 +182,7 @@ struct ixgbevf_info {
|
||||
|
||||
static inline void ixgbe_write_reg(struct ixgbe_hw *hw, u32 reg, u32 value)
|
||||
{
|
||||
u8 __iomem *reg_addr = ACCESS_ONCE(hw->hw_addr);
|
||||
u8 __iomem *reg_addr = READ_ONCE(hw->hw_addr);
|
||||
|
||||
if (IXGBE_REMOVED(reg_addr))
|
||||
return;
|
||||
|
Reference in New Issue
Block a user