From patchwork Fri Aug 11 17:00:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Frederic Weisbecker X-Patchwork-Id: 134618 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b824:0:b0:3f2:4152:657d with SMTP id z4csp1254681vqi; Fri, 11 Aug 2023 10:41:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG8uAmoR2UXOj0gCUIG7uFMQ8V8EtzLUZ3dC3f44YSh3uYP7iU7v5H5vF1eee/kuUsH9QXp X-Received: by 2002:a17:903:22cb:b0:1b8:a720:f513 with SMTP id y11-20020a17090322cb00b001b8a720f513mr2757864plg.30.1691775698073; Fri, 11 Aug 2023 10:41:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691775698; cv=none; d=google.com; s=arc-20160816; b=KL0DwMPV4PDoMNcP9IwVLq38aGXUbNl5XrmLhrBRWBPmJ++fAII5gimZl8XjUyBXyx /AwYd6ItoSAnw9rpfDI1l8mqYiS+6Nbk6qrnMRZCMYjzp8cV9iImo5hSfpZmw2x9NLWB MuJAfLCmCUclflWuJj7LTaXJIny33veVhHvG3Kz+/ldsKenuNloDaAkgw+4gJckRhIRf xlf0ltUkoQvsplOtH7+QvfffhHNTAO0Kv6ebkvznm3mrpAehf92D4utK7+yleOda7lTb NFWxqwoR4SWGrbcCDHcHUtGd+idJoqo3gUHMBLYN2ZjxhYzd92ytFKlyxowUaKI+I7GV pMtQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=1KIWZtD6Y5wj0lSHAnbM5Pjjl10GiUETFG+MrqYmCQU=; fh=K1m6n+brToPLMsYko3rtXKxC+lCostu9M84onRqB7cU=; b=ET2RyqOPf32KpSbTAYi+24G/aJZbmyNIsTKEwXaj8s6fpuQEPbCn69WOMaUHn16w7N iJk5BtZfQWuaeHuPKJY71iFIricTpRILOQLjwKKujI7QjxaXtaE1dwIlfF7QTneplUzE eYsmqH+JhR58FRSdZ1LTTzzStEuMl7WFX8jdT4VnhiMBrzX92UWaizdgDhHH1g7WncN4 RcQogGfYHFZh6NSg5JmGK3P8LLYNpu9hzem2KDVfy7BeNqWVYsEsYKQpRuzdqVrQIfb4 BBUZC4vtkHJnTBfUFNvIA1QeQ9jG0EjDm69lPvMX5GRfy+2rPpKGSsjKoaYsIpJ2Kzr1 9F1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KedcF9hv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id o5-20020a170902d4c500b001b25ade9ea3si3802367plg.337.2023.08.11.10.41.24; Fri, 11 Aug 2023 10:41:38 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=KedcF9hv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236088AbjHKRBA (ORCPT + 99 others); Fri, 11 Aug 2023 13:01:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55898 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235273AbjHKRA6 (ORCPT ); Fri, 11 Aug 2023 13:00:58 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6A7811FE3 for ; Fri, 11 Aug 2023 10:00:58 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 0313565816 for ; Fri, 11 Aug 2023 17:00:58 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id C5BF6C433CC; Fri, 11 Aug 2023 17:00:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1691773257; bh=erurmBk6eYQvncO35/wgAhKngMgxH6cwdYjQXfYK+oY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=KedcF9hvhoiTuwvwmjKJlSSKEawCZwEKWmHJ6+4HPVPxmFuWODvSihQVsIlxVDdEK j2eFLIFuxieQuQL/D8VMiGtY9AAsI2NsHptzs0cFPjhp+flYNfGCrgFHvOjD8dsuMw 2J0E7jS4x3RebYPuezSCYxWADvoWlaqUTpY0MB/Rlo7acpO0mmH8SI/mn8qOE+e62S bLdD7ZjPSZlxKPEIv78y+xLAt0R3Q4ihSud4LIcd2pshg2vEDyWcZjN1gTdncJO7l7 fUj4hhvlQqUI93iJ9lb8c+sm1IPpcregD/9taiXt9gWl3FroW81kFREy2WF9fa1atG 8oJo73E1HIvVA== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Peter Zijlstra , "Rafael J . Wysocki" , Daniel Lezcano , Thomas Gleixner , Anna-Maria Behnsen Subject: [PATCH 01/10] x86: Add a comment about the "magic" behind shadow sti before mwait Date: Fri, 11 Aug 2023 19:00:40 +0200 Message-Id: <20230811170049.308866-2-frederic@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230811170049.308866-1-frederic@kernel.org> References: <20230811170049.308866-1-frederic@kernel.org> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1773955394436187691 X-GMAIL-MSGID: 1773955394436187691 Add a note to make sure we never miss and break the requirements behind it. Signed-off-by: Frederic Weisbecker Acked-by: Rafael J. Wysocki --- arch/x86/include/asm/mwait.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/arch/x86/include/asm/mwait.h b/arch/x86/include/asm/mwait.h index 778df05f8539..341ee4f1d91e 100644 --- a/arch/x86/include/asm/mwait.h +++ b/arch/x86/include/asm/mwait.h @@ -87,6 +87,15 @@ static __always_inline void __mwaitx(unsigned long eax, unsigned long ebx, :: "a" (eax), "b" (ebx), "c" (ecx)); } +/* + * Re-enable interrupts right upon calling mwait in such a way that + * no interrupt can fire _before_ the execution of mwait, ie: no + * instruction must be placed between "sti" and "mwait". + * + * This is necessary because if an interrupt queues a timer before + * executing mwait, it would otherwise go unnoticed and the next tick + * would not be reprogrammed accordingly before mwait ever wakes up. + */ static __always_inline void __sti_mwait(unsigned long eax, unsigned long ecx) { mds_idle_clear_cpu_buffers();