From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 622ABC47247 for ; Fri, 8 May 2020 12:45:34 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4452324969 for ; Fri, 8 May 2020 12:45:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588941934; bh=j01xWAyAuNXnR8tamYGcqZmr1N98cWIMCIaKrTG0R6s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:List-ID:From; b=EYNPJ9d4iL5Ew/aevmdOZHZBXMRyuoj5hiXTpySHXD8rV+ZqOKodrys+SuLmTLbL/ ORKHs/J1GXhcQFboILMVmSxzRYLpai6/JdGq4sK6MkYM7vJbB/WROhVX+TErGcfl/D KHgvNhFHYhEPcuplHYu2EOvJl+iDPODO0BqnwDSg= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729310AbgEHMpc (ORCPT ); Fri, 8 May 2020 08:45:32 -0400 Received: from mail.kernel.org ([198.145.29.99]:45180 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729309AbgEHMpa (ORCPT ); Fri, 8 May 2020 08:45:30 -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 E96042495A; Fri, 8 May 2020 12:45:29 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1588941930; bh=j01xWAyAuNXnR8tamYGcqZmr1N98cWIMCIaKrTG0R6s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bEJxgQuF0u8AqvgBJqiSOSbcbD0iTJaD9aYVzQyVMP8+uaRB+k7rJAXH6fenOMdaz IUTiFqboZzEMZVXud/M5P9va/ZxshgtIxOoVDB2Ejn5Ka1NYMvpllQIWXt0iWDko6g sKHkfgCtE6lAE/BvJrjIpYIb5Lb7I9NIuUKP48Ng= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Vikram Mulukutla , "Peter Zijlstra (Intel)" , Linus Torvalds , Thomas Gleixner , Ingo Molnar Subject: [PATCH 4.4 227/312] sched/preempt: Fix preempt_count manipulations Date: Fri, 8 May 2020 14:33:38 +0200 Message-Id: <20200508123140.416041207@linuxfoundation.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200508123124.574959822@linuxfoundation.org> References: <20200508123124.574959822@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: stable-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: stable@vger.kernel.org From: Peter Zijlstra commit 2e636d5e66c35dfcbaf617aa8fa963f6847478fe upstream. Vikram reported that his ARM64 compiler managed to 'optimize' away the preempt_count manipulations in code like: preempt_enable_no_resched(); put_user(); preempt_disable(); Irrespective of that fact that that is horrible code that should be fixed for many reasons, it does highlight a deficiency in the generic preempt_count manipulators. As it is never right to combine/elide preempt_count manipulations like this. Therefore sprinkle some volatile in the two generic accessors to ensure the compiler is aware of the fact that the preempt_count is observed outside of the regular program-order view and thus cannot be optimized away like this. x86; the only arch not using the generic code is not affected as we do all this in asm in order to use the segment base per-cpu stuff. Reported-by: Vikram Mulukutla Tested-by: Vikram Mulukutla Signed-off-by: Peter Zijlstra (Intel) Cc: Linus Torvalds Cc: Peter Zijlstra Cc: Thomas Gleixner Fixes: a787870924db ("sched, arch: Create asm/preempt.h") Link: http://lkml.kernel.org/r/20160516131751.GH3205@twins.programming.kicks-ass.net Signed-off-by: Ingo Molnar Signed-off-by: Greg Kroah-Hartman --- include/asm-generic/preempt.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) --- a/include/asm-generic/preempt.h +++ b/include/asm-generic/preempt.h @@ -7,10 +7,10 @@ static __always_inline int preempt_count(void) { - return current_thread_info()->preempt_count; + return READ_ONCE(current_thread_info()->preempt_count); } -static __always_inline int *preempt_count_ptr(void) +static __always_inline volatile int *preempt_count_ptr(void) { return ¤t_thread_info()->preempt_count; }