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=-8.4 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 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 91414C5517A for ; Wed, 11 Nov 2020 13:34:00 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0C15B206D9 for ; Wed, 11 Nov 2020 13:33:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="pPB/Fynx" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0C15B206D9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.24803.52228 (Exim 4.92) (envelope-from ) id 1kcqFq-0003Nx-0N; Wed, 11 Nov 2020 13:33:42 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 24803.52228; Wed, 11 Nov 2020 13:33:41 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kcqFp-0003Nq-Ss; Wed, 11 Nov 2020 13:33:41 +0000 Received: by outflank-mailman (input) for mailman id 24803; Wed, 11 Nov 2020 13:33:41 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kcqFo-0003Nl-UP for xen-devel@lists.xenproject.org; Wed, 11 Nov 2020 13:33:40 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2c45bd74-1b41-4a82-8308-a1db739d048a; Wed, 11 Nov 2020 13:33:35 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id C96A1AD77; Wed, 11 Nov 2020 13:33:34 +0000 (UTC) Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kcqFo-0003Nl-UP for xen-devel@lists.xenproject.org; Wed, 11 Nov 2020 13:33:40 +0000 X-Inumbo-ID: 2c45bd74-1b41-4a82-8308-a1db739d048a Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 2c45bd74-1b41-4a82-8308-a1db739d048a; Wed, 11 Nov 2020 13:33:35 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1605101614; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=HTyaMP2eYC4AgPHdAHAXnPBqQiD7GG97cXDLyIP2Sps=; b=pPB/FynxFuKpSytfRaAudrr5MvhFKk402DBXEkIZKxTmDvmrE5ui+JucUfT8FIRJMqrFiA Pq7M75bF0IcnLaWLTL1Ew436M2ri3NtqPsxWhVfriSiUwZSly0iZab4AliRsayQsoxFV1P 6Z2gGWyYLNk+cGxOKI9z4fx19TMOWrg= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id C96A1AD77; Wed, 11 Nov 2020 13:33:34 +0000 (UTC) Subject: Re: [PATCH v3 5/7] x86: guard against straight-line speculation past RET To: =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= Cc: "xen-devel@lists.xenproject.org" , Andrew Cooper , Wei Liu References: <7065e2dc-f846-be79-1081-682c2295358c@suse.com> <80ceea17-958d-f409-5f39-9f353e780f5b@suse.com> <20201111111504.r4k7a53spsy7pzjq@Air-de-Roger> From: Jan Beulich Message-ID: <8ab3658f-8b69-455e-74b3-462f89f1cfe4@suse.com> Date: Wed, 11 Nov 2020 14:33:34 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.1 MIME-Version: 1.0 In-Reply-To: <20201111111504.r4k7a53spsy7pzjq@Air-de-Roger> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit On 11.11.2020 12:15, Roger Pau Monné wrote: > On Fri, Oct 23, 2020 at 10:38:04AM +0200, Jan Beulich wrote: >> Under certain conditions CPUs can speculate into the instruction stream >> past a RET instruction. Guard against this just like 3b7dab93f240 >> ("x86/spec-ctrl: Protect against CALL/JMP straight-line speculation") >> did - by inserting an "INT $3" insn. It's merely the mechanics of how to >> achieve this that differ: A set of macros gets introduced to post- >> process RET insns issued by the compiler (or living in assembly files). >> >> Unfortunately for clang this requires further features their built-in >> assembler doesn't support: We need to be able to override insn mnemonics >> produced by the compiler (which may be impossible, if internally >> assembly mnemonics never get generated), and we want to use \(text) >> escaping / quoting in the auxiliary macro. >> >> Signed-off-by: Jan Beulich >> Acked-by: Roger Pau Monné >> --- >> TBD: Would be nice to avoid the additions in .init.text, but a query to >> the binutils folks regarding the ability to identify the section >> stuff is in (by Peter Zijlstra over a year ago: >> https://sourceware.org/pipermail/binutils/2019-July/107528.html) >> has been left without helpful replies. >> --- >> v3: Use .byte 0xc[23] instead of the nested macros. >> v2: Fix build with newer clang. Use int3 mnemonic. Also override retq. >> >> --- a/xen/Makefile >> +++ b/xen/Makefile >> @@ -145,7 +145,15 @@ t2 = $(call as-insn,$(CC) -I$(BASEDIR)/i >> # https://bugs.llvm.org/show_bug.cgi?id=36110 >> t3 = $(call as-insn,$(CC),".macro FOO;.endm"$(close); asm volatile $(open)".macro FOO;.endm",-no-integrated-as) >> >> -CLANG_FLAGS += $(call or,$(t1),$(t2),$(t3)) >> +# Check whether \(text) escaping in macro bodies is supported. >> +t4 = $(call as-insn,$(CC),".macro m ret:req; \\(ret) $$\\ret; .endm; m 8",,-no-integrated-as) >> + >> +# Check whether macros can override insn mnemonics in inline assembly. >> +t5 = $(call as-insn,$(CC),".macro ret; .error; .endm; .macro retq; .error; .endm",-no-integrated-as) > > I was going over this to post a bug report to LLVM, but it seems like > gcc also doesn't overwrite ret when using the above snippet: > > https://godbolt.org/z/oqsPTv I can't see what's different from void test(void) { asm volatile (".macro ret; .error; .endm; .macro retq; .error; .endm"); } but this one produces "Error: .error directive invoked in source file" for me with both old and new gcc. Jan