Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp3630522pxb; Mon, 24 Jan 2022 13:57:50 -0800 (PST) X-Google-Smtp-Source: ABdhPJx3yNlwh85Qt6hsM8YnhY168RgKIewu4MGvU10sg6WyggL/qIRJWCs4LefFWYGlO1PdQPt6 X-Received: by 2002:aa7:9f5c:0:b0:4c8:fc66:e4a1 with SMTP id h28-20020aa79f5c000000b004c8fc66e4a1mr7060846pfr.22.1643061469816; Mon, 24 Jan 2022 13:57:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643061469; cv=none; d=google.com; s=arc-20160816; b=bUwldao4mxWAF2d1PDeSY3MCm4K/vgl67W5BjUMCePplJfyUEBrL6dy/U+cg7mRmMM ekQr6nQBVv4RZeI1NyhBEKg4FdIR66zK+NxcNHdRvZJx2nYvNvOvPjOIvvBERY74Vyyw swm/5kXpS1+E37AA5SxQ69898+yvNwg16/Pdzw3HaLXracq1h5gskO6gBhqbD+TCA7se mwciU5mII8PqglPiCETAlHeO2SavoI63YQEidIHmoDx/t9Pt9D1RbCUQwEaeh+PDUcxZ pc7lkEyViKUrEvS+Jkzz1YMrg547X0To7SLwUM1fb3mo56BO3NRK3rD5Yzy0Fw5AQ0uj VOMg== 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=mnwJOAXG4+UKdfKe1sHOvEMdTYvh0qi8sssdh3I7XhdCHqpNCVjuk17nruvaw9R/uA L+m3EsZmxiACqT7+StbFoj2BSNOf1475mnnvyEY9j1J1+RVC6ttcbX6v8FqtTIvNxat5 M2JIYHJ23ja3JseRzbofzIvZdZl5C24MT6wIva1dlS4w9KysL68Gy5NByZBCg2EeKQqg JN4dCqlhhoN1j+qdK4pj9pu0W+mm5bxnObQXc9wUlYcjYTaT2+CxwbrxH890oUfOh1Sw 23BCMgZgnNSl2CUHtfJWkPENo56c/Mz7kao4mldQD6ea3VMp/gMjk0SutQMe3ICH65VZ MBcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=0WUuNBlW; 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 o3si13166761pll.580.2022.01.24.13.57.38; Mon, 24 Jan 2022 13:57:49 -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=0WUuNBlW; 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 S1457127AbiAXVk6 (ORCPT + 99 others); Mon, 24 Jan 2022 16:40:58 -0500 Received: from dfw.source.kernel.org ([139.178.84.217]:53558 "EHLO dfw.source.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1445345AbiAXVCw (ORCPT ); Mon, 24 Jan 2022 16:02:52 -0500 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 dfw.source.kernel.org (Postfix) with ESMTPS id 7486F61320; Mon, 24 Jan 2022 21:02:51 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 4F357C340E5; Mon, 24 Jan 2022 21:02:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643058170; bh=c119dTtFJ/UsDiNJRoA+V53VfW8MDbBahmzYfXdX0aE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=0WUuNBlWta3mzI4mxH9Io1Q3rM2DbTuet8xmodACbe+Ud0fMJp3NSKJyuNtLUe17W 0rnK+OYQdaoZpPGBbQlYFRM/5o4VjMYxOlJjydn05NEZfYmNWTQ3EWMWE9+QIkp3u1 VJx9z5EQZ2NkWZ7j8XUPSy/pzF58NDokivxl8EtQ= 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.16 0203/1039] powerpc: Avoid discarding flags in system_call_exception() Date: Mon, 24 Jan 2022 19:33:12 +0100 Message-Id: <20220124184132.148938792@linuxfoundation.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220124184125.121143506@linuxfoundation.org> References: <20220124184125.121143506@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