Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1491425pxp; Thu, 10 Mar 2022 06:32:04 -0800 (PST) X-Google-Smtp-Source: ABdhPJx0b5ygXMXMeELR43zYfzlN4D0p8WHGYmW5aO3TNEWa3AlmtCP5R9MnaAlQF/qFuiu1RpYT X-Received: by 2002:a05:6402:409:b0:416:ad7e:88dc with SMTP id q9-20020a056402040900b00416ad7e88dcmr3553229edv.283.1646922724406; Thu, 10 Mar 2022 06:32:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646922724; cv=none; d=google.com; s=arc-20160816; b=zffbKeBhBYgVwVuliXfkhF+AvnqVhCL9ypT1cgY3Jmue4WZmcM4pDlRqHnsIf8M0OT TTgGPX26TvYAMqZxH32JVCXXSIsDNkAS3wLpAK2tLl2LaNcjY/YpdWypIZKJl2qYYBtn Q0qFW5teLVj+d6sethfYHl1Aiho0bEXcpFYBcRAraBFousPpG56qyehtj4RmXtTMTpLs LqNClzpNUX0ohTF2BHB7HGRB9Ul6/eqT9vtlPGF4vWauy7pAfVObz13TqvwJF7tOplyN ng8FkZl4r8fEOn6rv3VSpq7BR2MpN0kb3SnRPQyLDuWQWv8jG2Ylqr9pDz+AjTLdozik 3mdw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=asZaKof/Ycf9Yl/IenjXZLrN7xJYPH+zuWKph/YnaGE=; b=l7MQpHIe3lPw/IhVpfqCZoBsDQDixcLVT2joWdUviXucX3WgElEw+xa0wyhNBbjv0F GyHuj4WJapREamc8LhMH8exIDesAjsBOFmqGsKNzKBKjU2IktwVvretSq+T7FZG0MvMS A+0lp1OfFt0ennIzuQHEeOgn9WBB1uEgnN7btr6OaV/vOpWvpqpTGd3YUZtZBr//vnEa MRIBHYu/+EUQADsPBxNEca+SGKUeX31lN0grR2d3Od3qavhE4nOg6awgSlL6X6Fz6/L9 w4oH7NZYCR/Z8MW6BsT+Tqj/PziuEaAPHmni4SmoUgJxog4a1pElt25ZNl1f09QnOCqU glVA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=mPNMJ1Y4; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id v2-20020a170906488200b006db76365af6si2354897ejq.431.2022.03.10.06.31.40; Thu, 10 Mar 2022 06:32:04 -0800 (PST) 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=@infradead.org header.s=casper.20170209 header.b=mPNMJ1Y4; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240601AbiCJJGg (ORCPT + 99 others); Thu, 10 Mar 2022 04:06:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43810 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233760AbiCJJGf (ORCPT ); Thu, 10 Mar 2022 04:06:35 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4F069137768; Thu, 10 Mar 2022 01:05:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=asZaKof/Ycf9Yl/IenjXZLrN7xJYPH+zuWKph/YnaGE=; b=mPNMJ1Y4nU566VAWE+/NYgv08b fnoUNB++Yh/YKvbCQYGfC8U772Xr6Xf6cRnvIb/1RPGfBQ+7ctL/m6ntNGPUbgCz+7y8MEzVM8vTX AadX+R+AmeKWwfoeS+z2TK2R7SJ7VcVvWpIuf42dJ69D2Ws1aeq3t4asGj4pZv0Aj3/YjpMFFSPD3 i/rW8D4rdjYC9pHvANvFG0HJJTAzLZR6cb8sOdvF+OJPZh/OoMwUu8tYjcPF5WT6Ys/vHywQDhZKc 5tFCASSZpCD/LLA1tyKH5+S7oUWSmBwbGmLjiu5EPiCx2HFyXRO/vnxoFuEAe7SHVJioEAx4hxOgs bFD5LLxw==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by casper.infradead.org with esmtpsa (Exim 4.94.2 #2 (Red Hat Linux)) id 1nSEjK-000Mm2-EX; Thu, 10 Mar 2022 09:05:06 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 1367430041D; Thu, 10 Mar 2022 10:05:05 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id E86EC264E62B6; Thu, 10 Mar 2022 10:05:04 +0100 (CET) Date: Thu, 10 Mar 2022 10:05:04 +0100 From: Peter Zijlstra To: Nick Desaulniers Cc: Alexei Starovoitov , x86@kernel.org, joao@overdrivepizza.com, hjl.tools@gmail.com, jpoimboe@redhat.com, andrew.cooper3@citrix.com, linux-kernel@vger.kernel.org, keescook@chromium.org, samitolvanen@google.com, mark.rutland@arm.com, alyssa.milburn@intel.com, mbenes@suse.cz, rostedt@goodmis.org, mhiramat@kernel.org, daniel@iogearbox.net, andrii@kernel.org, bpf@vger.kernel.org, llvm@lists.linux.dev Subject: Re: [PATCH v4 00/45] x86: Kernel IBT Message-ID: References: <20220308153011.021123062@infradead.org> <20220308200052.rpr4vkxppnxguirg@ast-mbp.dhcp.thefacebook.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE,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 On Wed, Mar 09, 2022 at 04:30:28PM -0800, Nick Desaulniers wrote: > I observed the following error when building with > CONFIG_LTO_CLANG_FULL=y enabled: > > ld.lld: error: ld-temp.o :7:2: symbol 'ibt_selftest_ip' is > already defined > ibt_selftest_ip: > ^ > > Seems to come from > commit a802350ba65a ("x86/ibt: Add IBT feature, MSR and #CP handling") > > Commenting out the label in the inline asm, I then observed: > vmlinux.o: warning: objtool: identify_cpu()+0x6d0: sibling call from > callable instruction with modified stack frame > vmlinux.o: warning: objtool: identify_cpu()+0x6e0: stack state > mismatch: cfa1=4+64 cfa2=4+8 > These seemed to disappear when I kept CONFIG_LTO_CLANG_FULL=y but then > disabled CONFIG_X86_KERNEL_IBT. (perhaps due to the way I hacked out > the ibt_selftest_ip label). Urgh.. I'm thikning this is a clang bug :/ The code in question is: void ibt_selftest_ip(void); /* code label defined in asm below */ DEFINE_IDTENTRY_ERRORCODE(exc_control_protection) { /* ... */ if (unlikely(regs->ip == (unsigned long)ibt_selftest_ip)) { regs->ax = 0; return; } /* ... */ } bool ibt_selftest(void) { unsigned long ret; asm (" lea ibt_selftest_ip(%%rip), %%rax\n\t" ANNOTATE_RETPOLINE_SAFE " jmp *%%rax\n\t" "ibt_selftest_ip:\n\t" UNWIND_HINT_FUNC ANNOTATE_NOENDBR " nop\n\t" : "=a" (ret) : : "memory"); return !ret; } There is only a single definition of that symbol, the one in the asm. The other is a declaration, which is used in the exception handler to compare against regs->ip. So what this code does is trigger an explicit #CP and special case that in the handler. For that the handler needs to know the special IP that will trigger the failure, this is cummunicated with that symbol. > Otherwise defconfig and CONFIG_LTO_CLANG_THIN=y both built and booted > in a vm WITHOUT IBT support. > > Any idea what's the status of IBT emulation in QEMU, and if it exists, > what's the necessary `-cpu` flag to enable it? I have a very ugly kvm patch that goes with a very ugly qemu patch to make it work. I would very much not recommend those getting merged. Someone with some actual kvm/qemu foo should do one. The complicating factor is that IA32_S_CET also contains SHSTK enable bits, so a straight passthrough like I use relies on the guest never setting those bits or keeping the pieces. It either needs to filter the MSR or implement the full CET mess.