From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
stable@vger.kernel.org, Mark Rutland <mark.rutland@arm.com>,
Will Deacon <will.deacon@arm.com>,
Steve Capper <steve.capper@linaro.org>,
Catalin Marinas <catalin.marinas@arm.com>
Subject: [PATCH 3.19 71/75] arm64: percpu: Make this_cpu accessors pre-empt safe
Date: Fri, 10 Apr 2015 15:19:37 +0200 [thread overview]
Message-ID: <20150410131711.141877008@linuxfoundation.org> (raw)
In-Reply-To: <20150410131707.794709951@linuxfoundation.org>
3.19-stable review patch. If anyone has any objections, please let me know.
------------------
From: Steve Capper <steve.capper@linaro.org>
commit f3eab7184ddcd4867cf42e3274ba24a66e1e093d upstream.
this_cpu operations were implemented for arm64 in:
5284e1b arm64: xchg: Implement cmpxchg_double
f97fc81 arm64: percpu: Implement this_cpu operations
Unfortunately, it is possible for pre-emption to take place between
address generation and data access. This can lead to cases where data
is being manipulated by this_cpu for a different CPU than it was
called on. Which effectively breaks the spec.
This patch disables pre-emption for the this_cpu operations
guaranteeing that address generation and data manipulation take place
without a pre-emption in-between.
Fixes: 5284e1b4bc8a ("arm64: xchg: Implement cmpxchg_double")
Fixes: f97fc810798c ("arm64: percpu: Implement this_cpu operations")
Reported-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Will Deacon <will.deacon@arm.com>
Signed-off-by: Steve Capper <steve.capper@linaro.org>
[catalin.marinas@arm.com: remove space after type cast]
Signed-off-by: Catalin Marinas <catalin.marinas@arm.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
arch/arm64/include/asm/cmpxchg.h | 30 ++++++++++++++++++++------
arch/arm64/include/asm/percpu.h | 44 +++++++++++++++++++++++++++++----------
2 files changed, 56 insertions(+), 18 deletions(-)
--- a/arch/arm64/include/asm/cmpxchg.h
+++ b/arch/arm64/include/asm/cmpxchg.h
@@ -246,14 +246,30 @@ static inline unsigned long __cmpxchg_mb
__ret; \
})
-#define this_cpu_cmpxchg_1(ptr, o, n) cmpxchg_local(raw_cpu_ptr(&(ptr)), o, n)
-#define this_cpu_cmpxchg_2(ptr, o, n) cmpxchg_local(raw_cpu_ptr(&(ptr)), o, n)
-#define this_cpu_cmpxchg_4(ptr, o, n) cmpxchg_local(raw_cpu_ptr(&(ptr)), o, n)
-#define this_cpu_cmpxchg_8(ptr, o, n) cmpxchg_local(raw_cpu_ptr(&(ptr)), o, n)
+#define _protect_cmpxchg_local(pcp, o, n) \
+({ \
+ typeof(*raw_cpu_ptr(&(pcp))) __ret; \
+ preempt_disable(); \
+ __ret = cmpxchg_local(raw_cpu_ptr(&(pcp)), o, n); \
+ preempt_enable(); \
+ __ret; \
+})
+
+#define this_cpu_cmpxchg_1(ptr, o, n) _protect_cmpxchg_local(ptr, o, n)
+#define this_cpu_cmpxchg_2(ptr, o, n) _protect_cmpxchg_local(ptr, o, n)
+#define this_cpu_cmpxchg_4(ptr, o, n) _protect_cmpxchg_local(ptr, o, n)
+#define this_cpu_cmpxchg_8(ptr, o, n) _protect_cmpxchg_local(ptr, o, n)
-#define this_cpu_cmpxchg_double_8(ptr1, ptr2, o1, o2, n1, n2) \
- cmpxchg_double_local(raw_cpu_ptr(&(ptr1)), raw_cpu_ptr(&(ptr2)), \
- o1, o2, n1, n2)
+#define this_cpu_cmpxchg_double_8(ptr1, ptr2, o1, o2, n1, n2) \
+({ \
+ int __ret; \
+ preempt_disable(); \
+ __ret = cmpxchg_double_local( raw_cpu_ptr(&(ptr1)), \
+ raw_cpu_ptr(&(ptr2)), \
+ o1, o2, n1, n2); \
+ preempt_enable(); \
+ __ret; \
+})
#define cmpxchg64(ptr,o,n) cmpxchg((ptr),(o),(n))
#define cmpxchg64_local(ptr,o,n) cmpxchg_local((ptr),(o),(n))
--- a/arch/arm64/include/asm/percpu.h
+++ b/arch/arm64/include/asm/percpu.h
@@ -204,25 +204,47 @@ static inline unsigned long __percpu_xch
return ret;
}
+#define _percpu_read(pcp) \
+({ \
+ typeof(pcp) __retval; \
+ preempt_disable(); \
+ __retval = (typeof(pcp))__percpu_read(raw_cpu_ptr(&(pcp)), \
+ sizeof(pcp)); \
+ preempt_enable(); \
+ __retval; \
+})
+
+#define _percpu_write(pcp, val) \
+do { \
+ preempt_disable(); \
+ __percpu_write(raw_cpu_ptr(&(pcp)), (unsigned long)(val), \
+ sizeof(pcp)); \
+ preempt_enable(); \
+} while(0) \
+
+#define _pcp_protect(operation, pcp, val) \
+({ \
+ typeof(pcp) __retval; \
+ preempt_disable(); \
+ __retval = (typeof(pcp))operation(raw_cpu_ptr(&(pcp)), \
+ (val), sizeof(pcp)); \
+ preempt_enable(); \
+ __retval; \
+})
+
#define _percpu_add(pcp, val) \
- __percpu_add(raw_cpu_ptr(&(pcp)), val, sizeof(pcp))
+ _pcp_protect(__percpu_add, pcp, val)
-#define _percpu_add_return(pcp, val) (typeof(pcp)) (_percpu_add(pcp, val))
+#define _percpu_add_return(pcp, val) _percpu_add(pcp, val)
#define _percpu_and(pcp, val) \
- __percpu_and(raw_cpu_ptr(&(pcp)), val, sizeof(pcp))
+ _pcp_protect(__percpu_and, pcp, val)
#define _percpu_or(pcp, val) \
- __percpu_or(raw_cpu_ptr(&(pcp)), val, sizeof(pcp))
-
-#define _percpu_read(pcp) (typeof(pcp)) \
- (__percpu_read(raw_cpu_ptr(&(pcp)), sizeof(pcp)))
-
-#define _percpu_write(pcp, val) \
- __percpu_write(raw_cpu_ptr(&(pcp)), (unsigned long)(val), sizeof(pcp))
+ _pcp_protect(__percpu_or, pcp, val)
#define _percpu_xchg(pcp, val) (typeof(pcp)) \
- (__percpu_xchg(raw_cpu_ptr(&(pcp)), (unsigned long)(val), sizeof(pcp)))
+ _pcp_protect(__percpu_xchg, pcp, (unsigned long)(val))
#define this_cpu_add_1(pcp, val) _percpu_add(pcp, val)
#define this_cpu_add_2(pcp, val) _percpu_add(pcp, val)
next prev parent reply other threads:[~2015-04-10 13:19 UTC|newest]
Thread overview: 76+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-10 13:18 [PATCH 3.19 00/75] 3.19.4-stable review Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 01/75] ASoC: da732x: Fix control-less DAPM routes Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 02/75] ASoC: ak4671: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 03/75] ASoC: sn95031: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 04/75] ASoC: sgtl5000: remove useless register write clearing CHRGPUMP_POWERUP Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 05/75] ASoC: pcm1681: Fix wrong value references for boolean kctl Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 06/75] ASoC: cs4271: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 07/75] ASoC: es8238: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 08/75] ASoC: wm8960: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 09/75] ASoC: tas5086: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 10/75] ASoC: wm8731: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 11/75] ASoC: wm2000: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 12/75] ASoC: wm8903: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 13/75] ASoC: wm8904: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 14/75] ASoC: ak4641: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 15/75] ASoC: adav80x: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 16/75] ASoC: wm8955: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 17/75] ASoC: wm9712: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 18/75] ASoC: wm9713: " Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 19/75] virtio_balloon: set DRIVER_OK before using device Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 20/75] virtio-balloon: do not call blocking ops when !TASK_RUNNING Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 21/75] clockevents: sun5i: Fix setup_irq init sequence Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 22/75] regmap: regcache-rbtree: Fix present bitmap resize Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 23/75] regmap: introduce regmap_name to fix syscon regmap trace events Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 25/75] tcm_fc: missing curly braces in ft_invl_hw_context() Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 26/75] tcm_qla2xxx: Fix incorrect use of __transport_register_session Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 27/75] Input: synaptics - split synaptics_resolution(), query first Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 28/75] Input: synaptics - log queried and quirked dimension values Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 29/75] Input: synaptics - query min dimensions for fw v8.1 Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 30/75] Input: synaptics - remove obsolete min/max quirk for X240 Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 31/75] Input: synaptics - support min/max board id in min_max_pnpid_table Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 32/75] Input: synaptics - skip quirks when post-2013 dimensions Greg Kroah-Hartman
2015-04-10 13:18 ` [PATCH 3.19 33/75] Input: synaptics - fix middle button on Lenovo 2015 products Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 34/75] Input: synaptics - handle spurious release of trackstick buttons Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 35/75] Input: synaptics - do not retrieve the board id on old firmwares Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 36/75] nl80211: ignore HT/VHT capabilities without QoS/WMM Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 37/75] mac80211: disable u-APSD queues by default Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 38/75] mac80211: drop unencrypted frames in mesh fwding Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 39/75] mac80211: count interfaces correctly for combination checks Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 40/75] powercap / RAPL: handle domains with different energy units Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 41/75] iwlwifi: mvm: rs: fix BT Coex check to look at the correct ant Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 42/75] iwlwifi: fix max_ht_ampdu_exponent for older devices Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 43/75] iwlwifi: mvm: BT Coex - fix a NULL pointer exception Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 44/75] iwlwifi: mvm: Fix ROC removal Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 45/75] uas: Add US_FL_NO_ATA_1X for Initio Corporation controllers / devices Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 46/75] usb: phy: am335x-control: check return value of bus_find_device Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 47/75] usb: chipidea: otg: add a_alt_hnp_support response for B device Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 48/75] usb: common: otg-fsm: only signal connect after switching to peripheral Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 49/75] phy: Find the right match in devm_phy_destroy() Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 50/75] rtlwifi: Improve handling of IPv6 packets Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 51/75] cpuidle: mvebu: Fix the CPU PM notifier usage Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 52/75] brcmfmac: Perform bound checking on vendor command buffer Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 53/75] of/irq: Fix of_irq_parse_one() returned error codes Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 54/75] perf: Fix irq_work tail recursion Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 55/75] staging: vt6656: vnt_rf_setpower: fix missing rate RATE_12M Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 56/75] vt6655: RFbSetPower " Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 57/75] vt6655: Fix late setting of byRFType Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 58/75] dmaengine: dw: append MODULE_ALIAS for platform driver Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 59/75] dm: hold suspend_lock while suspending device during device deletion Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 60/75] dm io: deal with wandering queue limits when handling REQ_DISCARD and REQ_WRITE_SAME Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 61/75] dm thin: fix to consistently zero-fill reads to unprovisioned blocks Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 62/75] dm snapshot: suspend origin when doing exception handover Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 63/75] dm snapshot: suspend merging snapshot " Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 64/75] spi: qup: Fix cs-num DT property parsing Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 65/75] spi: dw-mid: clear BUSY flag fist and test other one Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 67/75] hfsplus: fix B-tree corruption after insertion at position 0 Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 68/75] powerpc/book3s: Fix the MCE code to use CONFIG_KVM_BOOK3S_64_HANDLER Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 69/75] regulator: palmas: Correct TPS659038 register definition for REGEN2 Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 70/75] arm64: Use the reserved TTBR0 if context switching to the init_mm Greg Kroah-Hartman
2015-04-10 13:19 ` Greg Kroah-Hartman [this message]
2015-04-10 13:19 ` [PATCH 3.19 72/75] powerpc/pseries: Little endian fixes for post mobility device tree update Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 73/75] powerpc/mpc85xx: Add ranges to etsec2 nodes Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 74/75] net: ethernet: pcnet32: Setup the SRAM and NOUFLO on Am79C97{3, 5} Greg Kroah-Hartman
2015-04-10 13:19 ` [PATCH 3.19 75/75] mfd: kempld-core: Fix callback return value check Greg Kroah-Hartman
2015-04-10 18:03 ` [PATCH 3.19 00/75] 3.19.4-stable review Guenter Roeck
2015-04-11 7:33 ` Greg Kroah-Hartman
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20150410131711.141877008@linuxfoundation.org \
--to=gregkh@linuxfoundation.org \
--cc=catalin.marinas@arm.com \
--cc=linux-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=stable@vger.kernel.org \
--cc=steve.capper@linaro.org \
--cc=will.deacon@arm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).