Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3648774pxb; Mon, 24 Jan 2022 14:23:38 -0800 (PST) X-Google-Smtp-Source: ABdhPJxq80iPiDCTi4B6vrhIZQAZQrVcnvx9rB2/7ceLWkgD+eoCPlc7SDtuDVdEeuYqDqdnU6s/ X-Received: by 2002:a17:90b:1803:: with SMTP id lw3mr431459pjb.114.1643063018023; Mon, 24 Jan 2022 14:23:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643063018; cv=none; d=google.com; s=arc-20160816; b=V3vSgC9YztbqMOtUDN3AoMzF4eZG3mXFeM8+wB5cMALKTUpLd+AuLBzhQzYDNj7ErF e5EgCpP9ypDv9O1820GX4ygUSV73CN79YjHPhv02GfpYqKq/4Cgs7vPDKiJAH/XCQ22F K0jJ1E7hvq+RI6A5ZBlUXj5x7OFOHZrY0Orm6KOnugLZbCTbfM+5ZiVYz4sFsEY8u+e9 FWUhdrPEjSlpGOyQnr9l4fNGh5zoHb/Kxktf6eOJi3njr/cb5NDd6VpPERvILt5FN/5x EFwy9++OcFsQbSbfVF8ErnpXlQn79NVa/0FBJn/yHD+IhD1gJAtTYHa8CxPE02aOE8Pq lSoQ== 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=hMF1ivGQogx0gqZUyUnmsUpmhylPm9204C6LWdTwh88=; b=P/XPxYKr89LzTNZ/IGJSm9oRNfhFzNzxULD+vdxGMFp58aSyDrc1+8gOvUA2/FjOKh BjZWsCY9NKzLXYTA8MOF23G2BDS80Tsn0IuXxr2qBstpHb9lAz5eIhCv1DJ8QMXL1OeC MsvIUQfYCgfBRJJg7LPUDi92+6+FBgw/yZfwAFHxVKUqwPAyzUQS9pNoiYKwvgfXQ4st o4VsOuFapguvto2RQ9eFxjsrej/MLFB1KufJ1w0yJkP9tgny/szOfVjK4WTIrMEP513O sxvCI5RGe9rxcexM9jyurIlmRi6roXkEgiAbwSDT2r/9jHQ4TQvIazxqSRXBGUpio/ax Bj8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=W6VVtflG; 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 s4si4357662pfg.237.2022.01.24.14.23.25; Mon, 24 Jan 2022 14:23:38 -0800 (PST) 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=W6VVtflG; 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 S1577099AbiAXWOg (ORCPT + 99 others); Mon, 24 Jan 2022 17:14:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52956 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1453010AbiAXV1j (ORCPT ); Mon, 24 Jan 2022 16:27:39 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0F921C07323B; Mon, 24 Jan 2022 12:18:40 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id A8406B8121A; Mon, 24 Jan 2022 20:18:39 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D6DE0C340E8; Mon, 24 Jan 2022 20:18:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643055518; bh=c119dTtFJ/UsDiNJRoA+V53VfW8MDbBahmzYfXdX0aE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=W6VVtflGs00qpVGfLhQwZSBzk1vio/DCHqT6mCSyhaR75yg70ObXsPpOdE/LjAV/n UyFY1waa1332msbIjN4aDwJa93HIYiPOn6KhP9/4YguXgJd1o0PEyz2c1lKN9lNQor ZlLTdpOBY38aWZ/iMkeeeHBSNrP7fFD+gLZFoNH8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Mark Rutland , Thomas Gleixner , Eirik Fuller , Michael Ellerman , Nicholas Piggin , Sasha Levin Subject: [PATCH 5.15 176/846] powerpc: Avoid discarding flags in system_call_exception() Date: Mon, 24 Jan 2022 19:34:53 +0100 Message-Id: <20220124184107.044834827@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184100.867127425@linuxfoundation.org> References: <20220124184100.867127425@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: Mark Rutland [ Upstream commit 08b0af5b2affbe7419853e8dd1330e4b3fe27125 ] Some thread flags can be set remotely, and so even when IRQs are disabled, the flags can change under our feet. Thus, when setting flags we must use an atomic operation rather than a plain read-modify-write sequence, as a plain read-modify-write may discard flags which are concurrently set by a remote thread, e.g. // task A // task B tmp = A->thread_info.flags; set_tsk_thread_flag(A, NEWFLAG_B); tmp |= NEWFLAG_A; A->thread_info.flags = tmp; arch/powerpc/kernel/interrupt.c's system_call_exception() sets _TIF_RESTOREALL in the thread info flags with a read-modify-write, which may result in other flags being discarded. Elsewhere in the file it uses clear_bits() to atomically remove flag bits, so use set_bits() here for consistency with those. There may be reasons (e.g. instrumentation) that prevent the use of set_thread_flag() and clear_thread_flag() here, which would otherwise be preferable. Fixes: ae7aaecc3f2f78b7 ("powerpc/64s: system call rfscv workaround for TM bugs") Signed-off-by: Mark Rutland Signed-off-by: Thomas Gleixner Cc: Eirik Fuller Cc: Michael Ellerman Cc: Nicholas Piggin Link: https://lore.kernel.org/r/20211129130653.2037928-10-mark.rutland@arm.com Signed-off-by: Sasha Levin --- arch/powerpc/kernel/interrupt.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/interrupt.c b/arch/powerpc/kernel/interrupt.c index 835b626cd4760..df048e331cbfe 100644 --- a/arch/powerpc/kernel/interrupt.c +++ b/arch/powerpc/kernel/interrupt.c @@ -148,7 +148,7 @@ notrace long system_call_exception(long r3, long r4, long r5, */ if (IS_ENABLED(CONFIG_PPC_TRANSACTIONAL_MEM) && unlikely(MSR_TM_TRANSACTIONAL(regs->msr))) - current_thread_info()->flags |= _TIF_RESTOREALL; + set_bits(_TIF_RESTOREALL, ¤t_thread_info()->flags); /* * If the system call was made with a transaction active, doom it and -- 2.34.1