From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Cyrus-Session-Id: sloti22d1t05-511455-1516231552-2-6941465233761548263 X-Sieve: CMU Sieve 3.0 X-Spam-known-sender: no X-Spam-score: 0.0 X-Spam-hits: BAYES_00 -1.9, HEADER_FROM_DIFFERENT_DOMAINS 0.25, ME_NOAUTH 0.01, RCVD_IN_DNSWL_HI -5, T_RP_MATCHES_RCVD -0.01, LANGUAGES en, BAYES_USED global, SA_VERSION 3.4.0 X-Spam-source: IP='209.132.180.67', Host='vger.kernel.org', Country='US', FromHeader='com', MailFrom='org', XOriginatingCountry='CA' X-Spam-charsets: plain='utf-8' X-Resolved-to: greg@kroah.com X-Delivered-to: greg@kroah.com X-Mail-from: linux-api-owner@vger.kernel.org ARC-Seal: i=1; a=rsa-sha256; cv=none; d=messagingengine.com; s=arctest; t=1516231551; b=nq2/det88J3vuUZy39K42TaV9usVIMaKBM1QPbn17Fj0odN 6LYIK18n0+gt5IXitTVLmsyZ+M3Zo4VU36n5ysoF8mwulhYmVM4dgr+V+NkrRTo1 eGKJmsyxJWoR6DXEHqrur5Ayfg0yPvviPqW6Bn/ZkQkY+ciXXvhKzdvQP5eNw19g lQ5syu3EG5falF+1dCRg7cmS1z1eoofNNTHP21pgsg0H5zQx9XfYg21vac/aH/rl rpMJEVEeQ52zdOhsaZrEYwmKhcUO6L2chgrZ1h3rmfJ+aNv8WLXYdfyk8fQe2DzW gx9VOhwuMWKOn7LOphCXqUQLtSacQVr3nRrebtQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=date:from:to:cc:message-id:in-reply-to :references:subject:mime-version:content-type :content-transfer-encoding:sender:list-id; s=arctest; t= 1516231551; bh=amgLWGmtg4LVS1/1iMdi1jbvPJ8FpDt/zB1y+A5Bq5c=; b=h 5t7TWVpWeLh/ExGTsftvXFp9A1HCf2b9HgdShYQ/rxZ0aMc5GNoNHRMnBIPoTatg 5V7TH6UZHQJ7bAln6OGtkeBzy3Z6UkCF6qma53da3K4AdQZYUOeCA+w4LR7cFE0v FvbCqBeX/w4GvZgv3vbApABipLgDQhzpRa3+tafXNztUcHpMUk6G4UYPwYqsWVGx jYnza76+/43ZQ5P1hx6TtoJ5tkCcUK9Tp5afKitn+2Xj454FtN8VvX1iJ1bBrjg+ kGo9qr/wCLrd2PcoKVjV7Vvdl2OpXLe1xjH703vPKKqCeqdI3wzF8NlnwuBJeHFH vxPE1xF+Z0ut87s2q8FRA== ARC-Authentication-Results: i=1; mx5.messagingengine.com; arc=none (no signatures found); dkim=none (no signatures found); dmarc=none (p=none,has-list-id=yes,d=none) header.from=efficios.com; iprev=pass policy.iprev=209.132.180.67 (vger.kernel.org); spf=none smtp.mailfrom=linux-api-owner@vger.kernel.org smtp.helo=vger.kernel.org; x-aligned-from=fail; x-ptr=pass x-ptr-helo=vger.kernel.org x-ptr-lookup=vger.kernel.org; x-return-mx=pass smtp.domain=vger.kernel.org smtp.result=pass smtp_org.domain=kernel.org smtp_org.result=pass smtp_is_org_domain=no header.domain=efficios.com header.result=pass header_is_org_domain=yes Authentication-Results: mx5.messagingengine.com; arc=none (no signatures found); dkim=none (no signatures found); dmarc=none (p=none,has-list-id=yes,d=none) header.from=efficios.com; iprev=pass policy.iprev=209.132.180.67 (vger.kernel.org); spf=none smtp.mailfrom=linux-api-owner@vger.kernel.org smtp.helo=vger.kernel.org; x-aligned-from=fail; x-ptr=pass x-ptr-helo=vger.kernel.org x-ptr-lookup=vger.kernel.org; x-return-mx=pass smtp.domain=vger.kernel.org smtp.result=pass smtp_org.domain=kernel.org smtp_org.result=pass smtp_is_org_domain=no header.domain=efficios.com header.result=pass header_is_org_domain=yes Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753390AbeAQXZh (ORCPT ); Wed, 17 Jan 2018 18:25:37 -0500 Received: from mail.efficios.com ([167.114.142.141]:51966 "EHLO mail.efficios.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753031AbeAQXZg (ORCPT ); Wed, 17 Jan 2018 18:25:36 -0500 Date: Wed, 17 Jan 2018 23:25:32 +0000 (UTC) From: Mathieu Desnoyers To: Andy Lutomirski Cc: Ingo Molnar , Peter Zijlstra , Thomas Gleixner , linux-kernel , linux-api , "Paul E. McKenney" , Boqun Feng , Andrew Hunter , maged michael , Avi Kivity , Benjamin Herrenschmidt , Paul Mackerras , Michael Ellerman , Dave Watson , "H. Peter Anvin" , Andrea Parri , "Russell King, ARM Linux" , Greg Hackmann , Will Deacon , David Sehr , Linus Torvalds , x86 , linux-arch Message-ID: <80094124.4887.1516231532603.JavaMail.zimbra@efficios.com> In-Reply-To: References: <20180117165458.13330-1-mathieu.desnoyers@efficios.com> <20180117165458.13330-8-mathieu.desnoyers@efficios.com> <712464074.4666.1516212636860.JavaMail.zimbra@efficios.com> Subject: Re: [PATCH for 4.16 07/11] x86: Implement sync_core_before_usermode (v3) MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [167.114.142.141] X-Mailer: Zimbra 8.7.11_GA_1854 (ZimbraWebClient - FF52 (Linux)/8.7.11_GA_1854) Thread-Topic: x86: Implement sync_core_before_usermode (v3) Thread-Index: edBDbez0k6lGRkStk2AoqFsKGg0Pbg== Sender: linux-api-owner@vger.kernel.org X-Mailing-List: linux-api@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-Mailing-List: linux-kernel@vger.kernel.org List-ID: ----- On Jan 17, 2018, at 1:13 PM, Andy Lutomirski luto@kernel.org wrote: > On Wed, Jan 17, 2018 at 10:10 AM, Mathieu Desnoyers > wrote: >> ----- On Jan 17, 2018, at 12:53 PM, Andy Lutomirski luto@kernel.org wrote: >> >>> On Wed, Jan 17, 2018 at 8:54 AM, Mathieu Desnoyers >>> wrote: >>>> Ensure that a core serializing instruction is issued before returning to >>>> user-mode. x86 implements return to user-space through sysexit, sysrel, >>>> and sysretq, which are not core serializing. >>>> >>>> Signed-off-by: Mathieu Desnoyers >>>> Reviewed-by: Thomas Gleixner >>>> CC: Peter Zijlstra >>>> CC: Andy Lutomirski >>>> CC: Paul E. McKenney >>>> CC: Boqun Feng >>>> CC: Andrew Hunter >>>> CC: Maged Michael >>>> CC: Avi Kivity >>>> CC: Benjamin Herrenschmidt >>>> CC: Paul Mackerras >>>> CC: Michael Ellerman >>>> CC: Dave Watson >>>> CC: Ingo Molnar >>>> CC: "H. Peter Anvin" >>>> CC: Andrea Parri >>>> CC: Russell King >>>> CC: Greg Hackmann >>>> CC: Will Deacon >>>> CC: David Sehr >>>> CC: Linus Torvalds >>>> CC: x86@kernel.org >>>> CC: linux-arch@vger.kernel.org >>>> --- >>>> Changes since v1: >>>> - Fix prototype of sync_core_before_usermode in generic code (missing >>>> return type). >>>> - Add linux/processor.h include to sched/core.c. >>>> - Add ARCH_HAS_SYNC_CORE_BEFORE_USERMODE to init/Kconfig. >>>> - Fix linux/processor.h ifdef to target >>>> CONFIG_ARCH_HAS_SYNC_CORE_BEFORE_USERMODE rather than >>>> ARCH_HAS_SYNC_CORE_BEFORE_USERMODE. >>>> - Move empty static inline in processor.h to generic patch. >>>> --- >>>> arch/x86/Kconfig | 1 + >>>> arch/x86/include/asm/processor.h | 10 ++++++++++ >>>> 2 files changed, 11 insertions(+) >>>> >>>> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig >>>> index 20da391b5f32..0b44c8dd0e95 100644 >>>> --- a/arch/x86/Kconfig >>>> +++ b/arch/x86/Kconfig >>>> @@ -61,6 +61,7 @@ config X86 >>>> select ARCH_HAS_SG_CHAIN >>>> select ARCH_HAS_STRICT_KERNEL_RWX >>>> select ARCH_HAS_STRICT_MODULE_RWX >>>> + select ARCH_HAS_SYNC_CORE_BEFORE_USERMODE >>>> select ARCH_HAS_UBSAN_SANITIZE_ALL >>>> select ARCH_HAS_ZONE_DEVICE if X86_64 >>>> select ARCH_HAVE_NMI_SAFE_CMPXCHG >>>> diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h >>>> index d3a67fba200a..3257d34dbb40 100644 >>>> --- a/arch/x86/include/asm/processor.h >>>> +++ b/arch/x86/include/asm/processor.h >>>> @@ -722,6 +722,16 @@ static inline void sync_core(void) >>>> #endif >>>> } >>>> >>>> +/* >>>> + * Ensure that a core serializing instruction is issued before returning >>>> + * to user-mode. x86 implements return to user-space through sysexit, >>>> + * sysrel, and sysretq, which are not core serializing. >>>> + */ >>>> +static inline void sync_core_before_usermode(void) >>>> +{ >>> >>> /* With PTI, we unconditionally serialize before running user code. */ >>> if (static_cpu_has(X86_FEATURE_PTI)) >>> return; >> >> One issue I'm facing with this change is header dependency: >> sync_core_before_usermode() is currently implemented in >> arch/x86/include/asm/processor.h, but arch/x86/include/asm/cpufeature.h >> is needed for static_cpu_has, and it happens to include >> asm/processor.h. >> >> I'm facing a similar issue for adding a (in_irq() || in_nmi()) check. >> >> Should we move sync_core_before_usermode() to a different header, and if >> so, any suggestion ? > > tlbflush.h, maybe? Core serialization seems to be unrelated to TLB flushing though. I'm considering to create those new header files: include/asm-generic/sync_core.h (empty function) arch/x86/include/asm/sync_core.h for the sync_core_before_usermode() static inlines. Any better idea ? Thanks, Mathieu > >> >> Thanks, >> >> Mathieu >> >> >> >>> >>>> + sync_core(); >>>> +} >>> >>> --Andy >> >> -- >> Mathieu Desnoyers >> EfficiOS Inc. > > http://www.efficios.com -- Mathieu Desnoyers EfficiOS Inc. http://www.efficios.com