Received: by 2002:a05:7412:b101:b0:e2:908c:2ebd with SMTP id az1csp2661717rdb; Wed, 15 Nov 2023 07:14:17 -0800 (PST) X-Google-Smtp-Source: AGHT+IEbV+6UY4RanI2WLvGqofv76Blh71lyHcKmWSEm6rgRFmNUUQQ0Tryy+dqAfi8TZHcgplUZ X-Received: by 2002:a17:902:8ecb:b0:1ce:802:da9 with SMTP id x11-20020a1709028ecb00b001ce08020da9mr4788607plo.64.1700061256901; Wed, 15 Nov 2023 07:14:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1700061256; cv=none; d=google.com; s=arc-20160816; b=JbAkbtlEc8X8DzdtgaNKG8oW7lydvzMS/wKtEabXzRelH/+xQfXSzKuiKgJ+a3pxjr ehMXjtzse2827MFx/L3QpS3lIefz19j7pKgBG1lTAQisPjJNB/tt2PFdTIwxQ4fpr/7h mxz31yNetFBPEhztkhkCTdVQLet4YeOOS4549uQs2eVWSNWGfg27cyevShA04v0WzGdj /0lU9ZYF1Ngg6WII7EfyOJJzpr0Qptp62SSKWzyqgNH0Ka+arss9EYZ8BsdZDxfJV/Fl ENSEQhGkfU2JCjd1z9L0yRl8Mnfas5bJwJnv6V7K8FKEJ2K4NK7oqHUQPa9dS9sOEaLE xkAQ== 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=F5lUzxHfaNesVyYRc0R+gV6kFKpLiNtDbMpY3t1srrk=; fh=vOxJ5zAh/ByOGHIIhVBN1rQVKUP9RG+2PkGMcshoCBs=; b=HKWCQmpnmWVxqIHVUY0QQWDYloiewIhLuSXA0nZEI9l4hsam6nzJlqMpbHadCtvBLJ xIpe/3/WEtERycARD2TZ0YGn0uBSugst466C5vsUr4/0i44B+cHCx+nz26fNQ7xuAK3T /nY08GC3+WM6uHPvx76xrMPMSigp+TcQ/2J8oveV8rBux7S5NkOKUeGrLo6OjPKWN/kJ jLwaTGuS2ooEsyomRODrdsB42CHO1ED4d4ffFrcYkBJ5vQcqSbteCXjgupHroIpaFHDL nIhhDvXj+0qMTPv9ahOumRHrbtk5ts+J1lIJanYyqtrgxBSBFTW4Lzy//5wc6vYZ/79k MvMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i5OSOvr+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id n16-20020a170903111000b001bb8e3f3475si11252116plh.52.2023.11.15.07.14.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 15 Nov 2023 07:14:16 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=i5OSOvr+; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 7B6A081DD7CF; Wed, 15 Nov 2023 07:14:15 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.11 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1344389AbjKOPOM (ORCPT + 99 others); Wed, 15 Nov 2023 10:14:12 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344468AbjKOPOE (ORCPT ); Wed, 15 Nov 2023 10:14:04 -0500 Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6ED45D41 for ; Wed, 15 Nov 2023 07:14:01 -0800 (PST) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B9651C433CA; Wed, 15 Nov 2023 15:13:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1700061240; bh=CGc4yN675I1g1HtS2yRFvKBFqp1N2IpYVLKrHGqJRhc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=i5OSOvr+26OB70bGr8parKnbffR+qe+cbu6cntwePyetORAYqXomqnEf+fL9pK1nA oil1YHr0Ngj4yeGAdJjXSgqCzf8HyyZtltBVN7hrWyy5TY4NJBonMHGbhwVNGYME+h cfwWz8A4lZ6utJQNakqG1cT/t6t1aOb4N1PnGxbvfRag/XsbyQcu13wz8fAtMNlhGu +30WIPYtzl4OUvZvcFZgCYAU00jt01npgmCgwmDV+3cc5oXnM1FHxsLKs2ITAFFryn 7Mt+n70WFKOhDEQKJhwn8+i92ASJo9pZ0RVp+XGD/esOsLCDE5v3zC0qY5wne766bW Zh76QhVKMQPBQ== From: Frederic Weisbecker To: LKML Cc: Frederic Weisbecker , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , Peter Zijlstra , x86@kernel.org, "Rafael J . Wysocki" Subject: [PATCH 1/4] x86: Add a comment about the "magic" behind shadow sti before mwait Date: Wed, 15 Nov 2023 10:13:22 -0500 Message-ID: <20231115151325.6262-2-frederic@kernel.org> X-Mailer: git-send-email 2.42.1 In-Reply-To: <20231115151325.6262-1-frederic@kernel.org> References: <20231115151325.6262-1-frederic@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.2 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,T_SCC_BODY_TEXT_LINE 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-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 15 Nov 2023 07:14:15 -0800 (PST) Add a note to make sure we never miss and break the requirements behind it. Acked-by: Rafael J. Wysocki Signed-off-by: Frederic Weisbecker --- 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(); -- 2.42.1