Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp1100954pxa; Thu, 20 Aug 2020 02:28:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4Cd366BLshnjEG7GW/M+AguyRUgzVVHWL5FFzghMp6lXcfl8Ja76qfe8xREA66t5YofFP X-Received: by 2002:a17:906:fad2:: with SMTP id lu18mr2400595ejb.15.1597915681888; Thu, 20 Aug 2020 02:28:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597915681; cv=none; d=google.com; s=arc-20160816; b=umZ2t8nSquhZtM6FMfpFbCqqFtJlpZmBruATLywwb3nh7F6XCGW533l1jMg2E+kKH0 2CZ0hkGT6NSu+IxE+TQVHYA3vXR/XL4lPIh3cuonJOf3AldUS8KNfnEuVr1fmETUxcNa tixjL3eT85gVGxiuXZR1nSVStinruneGOcHU91zWuwektUUQB5Z7Gos9bKL5j2pJ4RSx bLZMUVbwUgYHNfRz/2xfp3qsfNFSnZghA3X4k3vozESs7VlDT6fzDF0oK+QqyZXGmMh1 X5O9sFMzOXhnXfCiWq0mfcfJ9bhhBu8ZDP62GvruagTSmwHkciaD2RoUsVAoOYAemKst RAEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yVeyZmty02oXqRoHuwxucDL6imnxhmc6HqH/HuvqKfU=; b=MrGDYT3g6R49+c8rcGjB4j8LoOD9b9zlGqEMRC1o67L6srFUhWwdz5L77VEsTJFZbk 7UgxAZUhWX8UaDOfeL/SlsFfLUWxfpGPI6dChxk+zZ4o7IxlgcsSjo8KiqhLmm3MJCZx o0yx3TdduC0SR6rpdjfvWDg9AEIfsXUsW4b+8feLfUogXJbnataSvG90mNpfJ0/Uv4BB botcn+mXeDVjjcZ5o5X71JM2XP1CJSx5bVevbF/RiCKvKKG9CGaxoxOjHSGGnIlKQtuu VRJWtTvvXkEYKlOPx/ofYulfgEu5D2Qr2jJ9MkXcfMiaCMt4fr4J2gP4o/u+xQvt5bn7 b+HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=wdHWT5co; 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=fail (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 z7si821757ejj.711.2020.08.20.02.27.37; Thu, 20 Aug 2020 02:28:01 -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=@kernel.org header.s=default header.b=wdHWT5co; 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=fail (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726772AbgHTJ0V (ORCPT + 99 others); Thu, 20 Aug 2020 05:26:21 -0400 Received: from mail.kernel.org ([198.145.29.99]:34340 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727794AbgHTJZq (ORCPT ); Thu, 20 Aug 2020 05:25:46 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 1931D21744; Thu, 20 Aug 2020 09:25:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1597915533; bh=n3so6R77g/5ICdm/NwPemyOsyMTa3kJfmjr8hXCUdWY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=wdHWT5co0vcM4rcUH3UguFPUP7w2fA+awdzS0nVpC0bxFJdYFNPNYsM63AJsuSGII Xt6JcKsjW94B/rYikXbxSiRj7rQr3gfcsgTivrzRRaac0wDL05CvETyEkahu1ECAS7 IiOog94Wt+TTdYnMfzcTuuI74E44S0WEATsbShH4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Max Filippov Subject: [PATCH 5.8 047/232] xtensa: add missing exclusive access state management Date: Thu, 20 Aug 2020 11:18:18 +0200 Message-Id: <20200820091615.060069169@linuxfoundation.org> X-Mailer: git-send-email 2.28.0 In-Reply-To: <20200820091612.692383444@linuxfoundation.org> References: <20200820091612.692383444@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Max Filippov commit a0fc1436f1f4f84e93144480bf30e0c958d135b6 upstream. The result of the s32ex opcode is recorded in the ATOMCTL special register and must be retrieved with the getex opcode. Context switch between s32ex and getex may trash the ATOMCTL register and result in duplicate update or missing update of the atomic variable. Add atomctl8 field to the struct thread_info and use getex to swap ATOMCTL bit 8 as a part of context switch. Clear exclusive access monitor on kernel entry. Cc: stable@vger.kernel.org Fixes: f7c34874f04a ("xtensa: add exclusive atomics support") Signed-off-by: Max Filippov Signed-off-by: Greg Kroah-Hartman --- arch/xtensa/include/asm/thread_info.h | 4 ++++ arch/xtensa/kernel/asm-offsets.c | 3 +++ arch/xtensa/kernel/entry.S | 11 +++++++++++ 3 files changed, 18 insertions(+) --- a/arch/xtensa/include/asm/thread_info.h +++ b/arch/xtensa/include/asm/thread_info.h @@ -55,6 +55,10 @@ struct thread_info { mm_segment_t addr_limit; /* thread address space */ unsigned long cpenable; +#if XCHAL_HAVE_EXCLUSIVE + /* result of the most recent exclusive store */ + unsigned long atomctl8; +#endif /* Allocate storage for extra user states and coprocessor states. */ #if XTENSA_HAVE_COPROCESSORS --- a/arch/xtensa/kernel/asm-offsets.c +++ b/arch/xtensa/kernel/asm-offsets.c @@ -93,6 +93,9 @@ int main(void) DEFINE(THREAD_RA, offsetof (struct task_struct, thread.ra)); DEFINE(THREAD_SP, offsetof (struct task_struct, thread.sp)); DEFINE(THREAD_CPENABLE, offsetof (struct thread_info, cpenable)); +#if XCHAL_HAVE_EXCLUSIVE + DEFINE(THREAD_ATOMCTL8, offsetof (struct thread_info, atomctl8)); +#endif #if XTENSA_HAVE_COPROCESSORS DEFINE(THREAD_XTREGS_CP0, offsetof(struct thread_info, xtregs_cp.cp0)); DEFINE(THREAD_XTREGS_CP1, offsetof(struct thread_info, xtregs_cp.cp1)); --- a/arch/xtensa/kernel/entry.S +++ b/arch/xtensa/kernel/entry.S @@ -374,6 +374,11 @@ common_exception: s32i a2, a1, PT_LCOUNT #endif +#if XCHAL_HAVE_EXCLUSIVE + /* Clear exclusive access monitor set by interrupted code */ + clrex +#endif + /* It is now save to restore the EXC_TABLE_FIXUP variable. */ rsr a2, exccause @@ -2020,6 +2025,12 @@ ENTRY(_switch_to) s32i a3, a4, THREAD_CPENABLE #endif +#if XCHAL_HAVE_EXCLUSIVE + l32i a3, a5, THREAD_ATOMCTL8 + getex a3 + s32i a3, a4, THREAD_ATOMCTL8 +#endif + /* Flush register file. */ spill_registers_kernel