linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Andy Lutomirski <luto@kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Subject: [PATCH 5.9 102/105] x86/membarrier: Get rid of a dubious optimization
Date: Mon, 14 Dec 2020 18:29:16 +0100	[thread overview]
Message-ID: <20201214172600.195381237@linuxfoundation.org> (raw)
In-Reply-To: <20201214172555.280929671@linuxfoundation.org>

From: Andy Lutomirski <luto@kernel.org>

commit a493d1ca1a03b532871f1da27f8dbda2b28b04c4 upstream.

sync_core_before_usermode() had an incorrect optimization.  If the kernel
returns from an interrupt, it can get to usermode without IRET. It just has
to schedule to a different task in the same mm and do SYSRET.  Fortunately,
there were no callers of sync_core_before_usermode() that could have had
in_irq() or in_nmi() equal to true, because it's only ever called from the
scheduler.

While at it, clarify a related comment.

Fixes: 70216e18e519 ("membarrier: Provide core serializing command, *_SYNC_CORE")
Signed-off-by: Andy Lutomirski <luto@kernel.org>
Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
Reviewed-by: Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: stable@vger.kernel.org
Link: https://lore.kernel.org/r/5afc7632be1422f91eaf7611aaaa1b5b8580a086.1607058304.git.luto@kernel.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

---
 arch/x86/include/asm/sync_core.h |    9 +++++----
 arch/x86/mm/tlb.c                |   10 ++++++++--
 2 files changed, 13 insertions(+), 6 deletions(-)

--- a/arch/x86/include/asm/sync_core.h
+++ b/arch/x86/include/asm/sync_core.h
@@ -88,12 +88,13 @@ static inline void sync_core_before_user
 	/* With PTI, we unconditionally serialize before running user code. */
 	if (static_cpu_has(X86_FEATURE_PTI))
 		return;
+
 	/*
-	 * Return from interrupt and NMI is done through iret, which is core
-	 * serializing.
+	 * Even if we're in an interrupt, we might reschedule before returning,
+	 * in which case we could switch to a different thread in the same mm
+	 * and return using SYSRET or SYSEXIT.  Instead of trying to keep
+	 * track of our need to sync the core, just sync right away.
 	 */
-	if (in_irq() || in_nmi())
-		return;
 	sync_core();
 }
 
--- a/arch/x86/mm/tlb.c
+++ b/arch/x86/mm/tlb.c
@@ -475,8 +475,14 @@ void switch_mm_irqs_off(struct mm_struct
 	/*
 	 * The membarrier system call requires a full memory barrier and
 	 * core serialization before returning to user-space, after
-	 * storing to rq->curr. Writing to CR3 provides that full
-	 * memory barrier and core serializing instruction.
+	 * storing to rq->curr, when changing mm.  This is because
+	 * membarrier() sends IPIs to all CPUs that are in the target mm
+	 * to make them issue memory barriers.  However, if another CPU
+	 * switches to/from the target mm concurrently with
+	 * membarrier(), it can cause that CPU not to receive an IPI
+	 * when it really should issue a memory barrier.  Writing to CR3
+	 * provides that full memory barrier and core serializing
+	 * instruction.
 	 */
 	if (real_prev == next) {
 		VM_WARN_ON(this_cpu_read(cpu_tlbstate.ctxs[prev_asid].ctx_id) !=



  parent reply	other threads:[~2020-12-14 18:15 UTC|newest]

Thread overview: 113+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-14 17:27 [PATCH 5.9 000/105] 5.9.15-rc1 review Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 001/105] Kbuild: do not emit debug info for assembly with LLVM_IAS=1 Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 002/105] mm/zsmalloc.c: drop ZSMALLOC_PGTABLE_MAPPING Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 003/105] kprobes: Remove NMI context check Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 004/105] kprobes: Tell lockdep about kprobe nesting Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 005/105] ASoC: Intel: bytcr_rt5640: Fix HP Pavilion x2 Detachable quirks Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 006/105] tools/bootconfig: Fix to check the write failure correctly Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 007/105] net, xsk: Avoid taking multiple skbuff references Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 008/105] bpftool: Fix error return value in build_btf_type_table Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 009/105] vhost-vdpa: fix page pinning leakage in error path (rework) Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 010/105] powerpc/64s: Fix hash ISA v3.0 TLBIEL instruction generation Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 011/105] batman-adv: Consider fragmentation for needed_headroom Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 012/105] batman-adv: Reserve needed_*room for fragments Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 013/105] batman-adv: Dont always reallocate the fragmentation skb head Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 014/105] ipvs: fix possible memory leak in ip_vs_control_net_init Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 015/105] ibmvnic: handle inconsistent login with reset Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 016/105] ibmvnic: stop free_all_rwi on failed reset Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 017/105] ibmvnic: avoid memset null scrq msgs Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 018/105] ibmvnic: delay next reset if hard reset fails Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 019/105] ibmvnic: track pending login Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 020/105] ibmvnic: send_login should check for crq errors Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 021/105] ibmvnic: reduce wait for completion time Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 022/105] drm/rockchip: Avoid uninitialized use of endpoint id in LVDS Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 023/105] drm/panel: sony-acx565akm: Fix race condition in probe Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 024/105] can: m_can: tcan4x5x_can_probe(): fix error path: remove erroneous clk_disable_unprepare() Greg Kroah-Hartman
2020-12-14 17:27 ` [PATCH 5.9 025/105] can: sja1000: sja1000_err(): dont count arbitration lose as an error Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 026/105] can: sun4i_can: sun4i_can_err(): " Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 027/105] can: c_can: c_can_power_up(): fix error handling Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 028/105] can: kvaser_pciefd: kvaser_pciefd_open(): " Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 029/105] samples/ftrace: Mark my_tramp[12]? global Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 030/105] scsi: storvsc: Fix error return in storvsc_probe() Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 031/105] net: broadcom CNIC: requires MMU Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 032/105] vdpa: mlx5: fix vdpa/vhost dependencies Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 033/105] iwlwifi: pcie: invert values of NO_160 device config entries Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 034/105] perf/x86/intel: Fix a warning on x86_pmu_stop() with large PEBS Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 035/105] usb: ohci-omap: Fix descriptor conversion Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 036/105] zlib: export S390 symbols for zlib modules Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 037/105] mm/mmap.c: fix mmap return value when vma is merged after call_mmap() Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 038/105] phy: usb: Fix incorrect clearing of tca_drv_sel bit in SETUP reg for 7211 Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 039/105] arm64: dts: rockchip: Remove system-power-controller from pmic on Odroid Go Advance Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 040/105] iwlwifi: pcie: limit memory read spin time Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 041/105] arm64: dts: rockchip: Assign a fixed index to mmc devices on rk3399 boards Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 042/105] arm64: dts: rockchip: Reorder LED triggers from mmc devices on rk3399-roc-pc Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 043/105] iwlwifi: sta: set max HE max A-MPDU according to HE capa Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 044/105] iwlwifi: pcie: set LTR to avoid completion timeout Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 045/105] iwlwifi: mvm: fix kernel panic in case of assert during CSA Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 046/105] powerpc: Drop -me200 addition to build flags Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 047/105] arm64: dts: broadcom: clear the warnings caused by empty dma-ranges Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 048/105] ARC: stack unwinding: dont assume non-current task is sleeping Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 049/105] scsi: ufs: Fix unexpected values from ufshcd_read_desc_param() Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 050/105] scsi: ufs: Make sure clk scaling happens only when HBA is runtime ACTIVE Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 051/105] interconnect: qcom: msm8916: Remove rpm-ids from non-RPM nodes Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 052/105] interconnect: qcom: qcs404: Remove GPU and display RPM IDs Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 053/105] ibmvnic: skip tx timeout reset while in resetting Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 054/105] irqchip/gic-v3-its: Unconditionally save/restore the ITS state on suspend Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 055/105] drm/exynos: depend on COMMON_CLK to fix compile tests Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 056/105] spi: spi-nxp-fspi: fix fspi panic by unexpected interrupts Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 057/105] arm-smmu-qcom: Ensure the qcom_scm driver has finished probing Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 058/105] habanalabs/gaudi: fix missing code in ECC handling Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 059/105] btrfs: do nofs allocations when adding and removing qgroup relations Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 060/105] btrfs: fix lockdep splat when enabling and disabling qgroups Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 061/105] soc: fsl: dpio: Get the cpumask through cpumask_of(cpu) Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 062/105] sched/idle: Fix arch_cpu_idle() vs tracing Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 063/105] intel_idle: Fix intel_idle() " Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 064/105] arm64: tegra: Disable the ACONNECT for Jetson TX2 Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 065/105] platform/x86: thinkpad_acpi: add P1 gen3 second fan support Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 066/105] platform/x86: thinkpad_acpi: Do not report SW_TABLET_MODE on Yoga 11e Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 067/105] platform/x86: thinkpad_acpi: Add BAT1 is primary battery quirk for Thinkpad Yoga 11e 4th gen Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 068/105] platform/x86: thinkpad_acpi: Whitelist P15 firmware for dual fan control Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 069/105] platform/x86: acer-wmi: add automatic keyboard background light toggle key as KEY_LIGHTS_TOGGLE Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 070/105] platform/x86: intel-vbtn: Support for tablet mode on HP Pavilion 13 x360 PC Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 071/105] platform/x86: touchscreen_dmi: Add info for the Predia Basic tablet Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 072/105] platform/x86: touchscreen_dmi: Add info for the Irbis TW118 tablet Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 073/105] can: m_can: m_can_dev_setup(): add support for bosch mcan version 3.3.0 Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 074/105] s390: fix irq state tracing Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 075/105] intel_idle: Build fix Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 076/105] media: pulse8-cec: fix duplicate free at disconnect or probe error Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 077/105] media: pulse8-cec: add support for FW v10 and up Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 078/105] mmc: mediatek: Fix system suspend/resume support for CQHCI Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 079/105] mmc: mediatek: Extend recheck_sdio_irq fix to more variants Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 080/105] ktest.pl: Fix incorrect reboot for grub2bls Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 081/105] xen: add helpers for caching grant mapping pages Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 082/105] xen: dont use page->lru for ZONE_DEVICE memory Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 083/105] Input: cm109 - do not stomp on control URB Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 084/105] Input: i8042 - add Acer laptops to the i8042 reset list Greg Kroah-Hartman
2020-12-14 17:28 ` [PATCH 5.9 085/105] pinctrl: jasperlake: Fix HOSTSW_OWN offset Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 086/105] pinctrl: amd: remove debounce filter setting in IRQ type setting Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 087/105] mmc: sdhci-of-arasan: Fix clock registration error for Keem Bay SOC Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 088/105] mmc: block: Fixup condition for CMD13 polling for RPMB requests Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 089/105] drm/amdgpu/disply: set num_crtc earlier Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 090/105] drm/i915/gem: Propagate error from cancelled submit due to context closure Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 091/105] drm/i915/display/dp: Compute the correct slice count for VDSC on DP Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 092/105] drm/i915/gt: Declare gen9 has 64 mocs entries! Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 093/105] drm/i915/gt: Ignore repeated attempts to suspend request flow across reset Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 094/105] drm/i915/gt: Cancel the preemption timeout on responding to it Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 095/105] drm/amdgpu: fix sdma instance fw version and feature version init Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 096/105] kbuild: avoid static_assert for genksyms Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 097/105] proc: use untagged_addr() for pagemap_read addresses Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 098/105] mm/hugetlb: clear compound_nr before freeing gigantic pages Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 099/105] zonefs: fix page reference and BIO leak Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 100/105] scsi: be2iscsi: Revert "Fix a theoretical leak in beiscsi_create_eqs()" Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 101/105] x86/mm/mem_encrypt: Fix definition of PMD_FLAGS_DEC_WP Greg Kroah-Hartman
2020-12-14 17:29 ` Greg Kroah-Hartman [this message]
2020-12-14 17:29 ` [PATCH 5.9 103/105] x86/apic/vector: Fix ordering in vector assignment Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 104/105] x86/kprobes: Fix optprobe to detect INT3 padding correctly Greg Kroah-Hartman
2020-12-14 17:29 ` [PATCH 5.9 105/105] compiler.h: fix barrier_data() on clang Greg Kroah-Hartman
2020-12-14 22:06 ` [PATCH 5.9 000/105] 5.9.15-rc1 review Jeffrin Jose T
2020-12-14 23:53 ` Shuah Khan
2020-12-16 13:20   ` Greg Kroah-Hartman
2020-12-15  2:27 ` Naresh Kamboju
2020-12-16 13:20   ` Greg Kroah-Hartman
2020-12-15 20:32 ` Guenter Roeck
2020-12-16 13:21   ` 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=20201214172600.195381237@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=stable@vger.kernel.org \
    --cc=tglx@linutronix.de \
    /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).