Received: by 2002:a25:ca44:0:0:0:0:0 with SMTP id a65csp800561ybg; Sun, 26 Jul 2020 23:01:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvTtwXlh+ob1iOA/NiCT00ODG01qtB7eWeyZhhERJvOzK76LunVF3bAe1GJthJ7z7e6aj9 X-Received: by 2002:a05:6402:1ca6:: with SMTP id cz6mr19007397edb.171.1595829682423; Sun, 26 Jul 2020 23:01:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595829682; cv=none; d=google.com; s=arc-20160816; b=TlOJWgVSGArfQ+1VoxnhGW2QNwcCt+IdKm1Zcz86Il+PoKs+82VO4QbNMTTzfMnpuT PioAObkhocVsD2YJ4HS3f6sKlPALy36Y0xjH6QEz+e1iYB5EoEUVxNJlvtkn3r83eIU9 a0WA35fVyQGBhpACZfnvqxXjBRe/9WCm2rVvPwz7CfjFbSM0JndoA91XIkn0Q/J0mh3M Ic161cjQzWa3DKZuGgiMwkV8q+3DQKGTm67kaVIq4E2aWXDvs+4ff5oxjPoeKMwzaq0U 9HX8PbSQnqfdSvg+q7u3aRiejnTIC0s0Gsgg0mKdbwEWm6j8cg+C5au3wTTQwfcIR28a jIKA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:from:cc:to:subject :content-transfer-encoding:mime-version:references:in-reply-to :user-agent:date:dkim-signature:dkim-filter; bh=7ZJ+HouPgYEW8yiE/LlDG0NoGA+OpyGJKIgsOqzZVVo=; b=fyzl3+Pjxj7cCiuZ8I5h1SMUaiUswq5MFIQscp9MhLnC2PjAQekCq1DuodBWPka0B0 q/2p3iiRSEc+h+zjZkN02+O8wyVrYpuTQPY2lcGnQVyrE84NxGZ2v3qgRSWmF5KTwkxH 37ZHhWCGlGDQefPM4dpZIQFZXy6sD1BqY0i6ew5rkwWxB7hWD6HROG68BRqVEo8CYE/r 2WAugubylVILJclGNmlAlAO8l2L8rrYRvzgG1PN+Gj4IQ4a71djR4CvLmFsIkMZZaEMH WBGRi/e950UMEndrAZfNT47ntnfPCRqkVDUxz8GfkRWSZqs4wkDnK6yGtW3KTgUJV3+6 iuBQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@zytor.com header.s=2020072401 header.b=KvHChYHV; 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=zytor.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id w6si3398380ejf.470.2020.07.26.23.01.00; Sun, 26 Jul 2020 23:01:22 -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=fail header.i=@zytor.com header.s=2020072401 header.b=KvHChYHV; 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=zytor.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726163AbgG0GAs (ORCPT + 99 others); Mon, 27 Jul 2020 02:00:48 -0400 Received: from terminus.zytor.com ([198.137.202.136]:37393 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726006AbgG0GAs (ORCPT ); Mon, 27 Jul 2020 02:00:48 -0400 Received: from [IPv6:2601:646:8600:3281:d01e:b6c6:1a24:9007] ([IPv6:2601:646:8600:3281:d01e:b6c6:1a24:9007]) (authenticated bits=0) by mail.zytor.com (8.15.2/8.15.2) with ESMTPSA id 06R60erA1896045 (version=TLSv1.3 cipher=TLS_AES_128_GCM_SHA256 bits=128 verify=NO); Sun, 26 Jul 2020 23:00:40 -0700 DKIM-Filter: OpenDKIM Filter v2.11.0 mail.zytor.com 06R60erA1896045 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=zytor.com; s=2020072401; t=1595829640; bh=7ZJ+HouPgYEW8yiE/LlDG0NoGA+OpyGJKIgsOqzZVVo=; h=Date:In-Reply-To:References:Subject:To:CC:From:From; b=KvHChYHVfL0eFt8kwhYWOEWit5bUKLOzOmF5TipbW3aUH9IH0jSxQ0G/9uITl/CLv bMlYvnZN6dN905twqBfvtRJUClC/BF5fz8rwdl7dIjCzWUnOBtUQ72Lj3yZo8IyHUQ wEIoXD3M2LghykG8/lJHX6lYFRDqd/b78G0b9LAiAJw3A7JqexQOW0xCDLtl5RAewo i7q07r2nCsNH73rUXpr6oICjkX8Zn3+BP8PfMie+WQ93YfpLeWGEfnuTJK7r0hfe2A PwBFsztVz5rpJ+xlDmolRx62lRm4x63Tr6G4anZCm2GcIGNOT012aXnOYeGV1MAgQa M7lVstsboyCVw== Date: Sun, 26 Jul 2020 23:00:33 -0700 User-Agent: K-9 Mail for Android In-Reply-To: References: <20200727043132.15082-1-ricardo.neri-calderon@linux.intel.com> <20200727043132.15082-5-ricardo.neri-calderon@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PATCH 4/4] x86/cpu: Use SERIALIZE in sync_core() when available To: Ricardo Neri , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Andy Lutomirski , x86@kernel.org CC: Dave Hansen , Tony Luck , Cathy Zhang , Fenghua Yu , Kyung Min Park , "Peter Zijlstra (Intel)" , "Ravi V. Shankar" , Sean Christopherson , linux-kernel@vger.kernel.org, Ricardo Neri , Dave Hansen , linux-edac@vger.kernel.org From: hpa@zytor.com Message-ID: Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On July 26, 2020 10:55:15 PM PDT, hpa@zytor=2Ecom wrote: >On July 26, 2020 9:31:32 PM PDT, Ricardo Neri > wrote: >>The SERIALIZE instruction gives software a way to force the processor >>to >>complete all modifications to flags, registers and memory from >previous >>instructions and drain all buffered writes to memory before the next >>instruction is fetched and executed=2E Thus, it serves the purpose of >>sync_core()=2E Use it when available=2E >> >>Use boot_cpu_has() and not static_cpu_has(); the most critical paths >>(returning to user mode and from interrupt and NMI) will not reach >>sync_core()=2E >> >>Cc: Andy Lutomirski >>Cc: Cathy Zhang >>Cc: Dave Hansen >>Cc: Fenghua Yu >>Cc: "H=2E Peter Anvin" >>Cc: Kyung Min Park >>Cc: Peter Zijlstra >>Cc: "Ravi V=2E Shankar" >>Cc: Sean Christopherson >>Cc: linux-edac@vger=2Ekernel=2Eorg >>Cc: linux-kernel@vger=2Ekernel=2Eorg >>Reviwed-by: Tony Luck >>Suggested-by: Andy Lutomirski >>Signed-off-by: Ricardo Neri >>--- >>--- >> arch/x86/include/asm/special_insns=2Eh | 5 +++++ >> arch/x86/include/asm/sync_core=2Eh | 10 +++++++++- >> 2 files changed, 14 insertions(+), 1 deletion(-) >> >>diff --git a/arch/x86/include/asm/special_insns=2Eh >>b/arch/x86/include/asm/special_insns=2Eh >>index 59a3e13204c3=2E=2E0a2a60bba282 100644 >>--- a/arch/x86/include/asm/special_insns=2Eh >>+++ b/arch/x86/include/asm/special_insns=2Eh >>@@ -234,6 +234,11 @@ static inline void clwb(volatile void *__p) >>=20 >> #define nop() asm volatile ("nop") >>=20 >>+static inline void serialize(void) >>+{ >>+ asm volatile("=2Ebyte 0xf, 0x1, 0xe8"); >>+} >>+ >> #endif /* __KERNEL__ */ >>=20 >> #endif /* _ASM_X86_SPECIAL_INSNS_H */ >>diff --git a/arch/x86/include/asm/sync_core=2Eh >>b/arch/x86/include/asm/sync_core=2Eh >>index fdb5b356e59b=2E=2Ebf132c09d61b 100644 >>--- a/arch/x86/include/asm/sync_core=2Eh >>+++ b/arch/x86/include/asm/sync_core=2Eh >>@@ -5,6 +5,7 @@ >> #include >> #include >> #include >>+#include >>=20 >> #ifdef CONFIG_X86_32 >> static inline void iret_to_self(void) >>@@ -54,7 +55,8 @@ static inline void iret_to_self(void) >> static inline void sync_core(void) >> { >> /* >>- * There are quite a few ways to do this=2E IRET-to-self is nice >>+ * Hardware can do this for us if SERIALIZE is available=2E Otherwise, >>+ * there are quite a few ways to do this=2E IRET-to-self is nice >> * because it works on every CPU, at any CPL (so it's compatible >> * with paravirtualization), and it never exits to a hypervisor=2E >> * The only down sides are that it's a bit slow (it seems to be >>@@ -75,6 +77,12 @@ static inline void sync_core(void) >> * Like all of Linux's memory ordering operations, this is a >> * compiler barrier as well=2E >> */ >>+ >>+ if (boot_cpu_has(X86_FEATURE_SERIALIZE)) { >>+ serialize(); >>+ return; >>+ } >>+ >> iret_to_self(); >> } >>=20 > >Any reason to not make sync_core() an inline with alternatives? > >For a really overenginered solution, but which might perform >unnecessary poorly on existing hardware: > >asm volatile("1: =2Ebyte 0xf, 0x1, 0xe8; 2:" > _ASM_EXTABLE(1b,2b)); (and : : : "memory" of course=2E) --=20 Sent from my Android device with K-9 Mail=2E Please excuse my brevity=2E