Received: by 2002:a05:6a10:206:0:0:0:0 with SMTP id 6csp601613pxj; Tue, 18 May 2021 10:02:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxLIx4CP0DVtQaI0xxwxWSznaptplZP7NIafCdIb8+wphv77fHrcNsdQ5aNUKY1gJ3C5Nb5 X-Received: by 2002:a05:6402:40d0:: with SMTP id z16mr8364451edb.104.1621357340798; Tue, 18 May 2021 10:02:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1621357340; cv=none; d=google.com; s=arc-20160816; b=K9FGtjbhkJvSU0mcGO9cWiXUEifYAha7tuE2FvMNBGluDh92HVDM41Nye2YBmY5Bwv MlaWu1vKVS+7c8MZLipf4iUqDJO0kSritpibxLj+SPOZxN9tWRJcyq5g/jiMQyXFGq3f oTewx+ZK45VBPNuJORem6OAdlvsocGLXE4oqoa9pZnvxRvhAcsJxsXaXA16mxXNFzFxm tiq+WSv2mpCAteAjhLqfCLav/XWj1EVyvmvwaEeDGwatjw5cIPojReTXOVltI+01dx15 eS0zP7HbsK0zfBobe3/pq+jXFIMlvXYBhjMrWVoZ4z5KF005CI1CCyyS5gEx8f3GAEQ0 Eb9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BsxhsZVoEFay98GTx9aDk3OoCTdrcaKYT7ngqNFPWH8=; b=bgotvJF5m/2fwm8/AmZW4l698osEAQKCSwl6NtUGgYs8ddSxK2A07X4/+XsHx2PPQo tEX95Suz+kwEsNFfS2SD5+Bom9ZziIKabtMZXMG1+BhuskDLEc8V7rv7cQVUZtlpCbKY smegWhj18646bBNEHpUCaTZCs0M1KR9NguJRMn9PlcJEq4iBN/u41S4ZUIy0lYJ/HogD AkY81g8Nf+l8IxNsCaautxqqVZNo+rhX2K3VoVK/8KHV5IRD1qZKQXTgaBUgGUJ/bW04 bTBQqog7CbHXizH4ykiwbLpz0i4vGPcJk5hAEVPGnQ5Yy23l9RWKa9yajwohtHzO8K13 x7Eg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=d31C16Xi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n2si728765ejl.693.2021.05.18.10.01.53; Tue, 18 May 2021 10:02:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=d31C16Xi; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239236AbhEQQHZ (ORCPT + 99 others); Mon, 17 May 2021 12:07:25 -0400 Received: from mail.kernel.org ([198.145.29.99]:55918 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344596AbhEQPpE (ORCPT ); Mon, 17 May 2021 11:45:04 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 211A161D27; Mon, 17 May 2021 14:43:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1621262607; bh=sW30hGEOgzmyPBbhJjZzCybDxuhJUkoIUlbPobGMwLg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=d31C16XiaEN6kXY9sxl16PxwZb/Q39evpv2cIh45P6bbXlHlNAbPtqEJyB7eH/+6t 72nGV/bMzWtIxyZtDVorBiQhcw/OlScbb2rbun0XLHk0EhNdZskE1hUDhdLKG8c7Xk 2mEm4vkJc7QATliJlikoF7A6CuLU4/dPXiFbCsa4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Ellerman Subject: [PATCH 5.10 198/289] powerpc/64s: Fix crashes when toggling entry flush barrier Date: Mon, 17 May 2021 16:02:03 +0200 Message-Id: <20210517140311.777220456@linuxfoundation.org> X-Mailer: git-send-email 2.31.1 In-Reply-To: <20210517140305.140529752@linuxfoundation.org> References: <20210517140305.140529752@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Michael Ellerman commit aec86b052df6541cc97c5fca44e5934cbea4963b upstream. The entry flush mitigation can be enabled/disabled at runtime via a debugfs file (entry_flush), which causes the kernel to patch itself to enable/disable the relevant mitigations. However depending on which mitigation we're using, it may not be safe to do that patching while other CPUs are active. For example the following crash: sleeper[15639]: segfault (11) at c000000000004c20 nip c000000000004c20 lr c000000000004c20 Shows that we returned to userspace with a corrupted LR that points into the kernel, due to executing the partially patched call to the fallback entry flush (ie. we missed the LR restore). Fix it by doing the patching under stop machine. The CPUs that aren't doing the patching will be spinning in the core of the stop machine logic. That is currently sufficient for our purposes, because none of the patching we do is to that code or anywhere in the vicinity. Fixes: f79643787e0a ("powerpc/64s: flush L1D on kernel entry") Cc: stable@vger.kernel.org # v5.10+ Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20210506044959.1298123-2-mpe@ellerman.id.au Signed-off-by: Greg Kroah-Hartman --- arch/powerpc/lib/feature-fixups.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) --- a/arch/powerpc/lib/feature-fixups.c +++ b/arch/powerpc/lib/feature-fixups.c @@ -299,8 +299,9 @@ void do_uaccess_flush_fixups(enum l1d_fl : "unknown"); } -void do_entry_flush_fixups(enum l1d_flush_type types) +static int __do_entry_flush_fixups(void *data) { + enum l1d_flush_type types = *(enum l1d_flush_type *)data; unsigned int instrs[3], *dest; long *start, *end; int i; @@ -369,6 +370,19 @@ void do_entry_flush_fixups(enum l1d_flus : "ori type" : (types & L1D_FLUSH_MTTRIG) ? "mttrig type" : "unknown"); + + return 0; +} + +void do_entry_flush_fixups(enum l1d_flush_type types) +{ + /* + * The call to the fallback flush can not be safely patched in/out while + * other CPUs are executing it. So call __do_entry_flush_fixups() on one + * CPU while all other CPUs spin in the stop machine core with interrupts + * hard disabled. + */ + stop_machine(__do_entry_flush_fixups, &types, NULL); } void do_rfi_flush_fixups(enum l1d_flush_type types)