From mboxrd@z Thu Jan 1 00:00:00 1970 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=-0.6 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 664C4C433DF for ; Fri, 22 May 2020 09:31:59 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2D51D206C3 for ; Fri, 22 May 2020 09:31:59 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="GS7WZ35r" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2D51D206C3 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=infradead.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id C254080008; Fri, 22 May 2020 05:31:58 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id BD66C80007; Fri, 22 May 2020 05:31:58 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AC56980008; Fri, 22 May 2020 05:31:58 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0213.hostedemail.com [216.40.44.213]) by kanga.kvack.org (Postfix) with ESMTP id 92BC880007 for ; Fri, 22 May 2020 05:31:58 -0400 (EDT) Received: from smtpin27.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 30E79BF0B for ; Fri, 22 May 2020 09:31:58 +0000 (UTC) X-FDA: 76843838316.27.teeth97_8586945de9d02 X-HE-Tag: teeth97_8586945de9d02 X-Filterd-Recvd-Size: 4595 Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) by imf05.hostedemail.com (Postfix) with ESMTP for ; Fri, 22 May 2020 09:31:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.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=c7wce+6/DBIYjkCyqWElBhrfpiCn+9+Nidad9WAJ8xQ=; b=GS7WZ35rrw0FFrzlc9tBdIUrEc AC2C2hlrz0cbztdEX4e2704LmbeAVy9pVGEPBw33HfOWw08qBCBsFN0bCz8z+oo2ai1Q4hju/u5kC tw+XLZ4f0z0bp/Kjy+0wnCvH/76psO0MEjhDNjeeRD2lrS00xG8UJzaByqHXOhfh5KN+DsoVq6Dd2 s1fM00t3BMT8n1ZTxUZVwC7wzHtxDNL7RT9cy7pE1wzgY/alhkhOLrT4mRCQLSfjr90gEwqGb7Plc 7JebFJB3UubdvwK8Zw34xPkJJ3vNBbm/yr1X2BeCRF8NYlRwlnDLHMgOP6bZZJIJ85kgE9dGQVfg2 v3FyyN+A==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1jc3z8-0004uu-Qs; Fri, 22 May 2020 09:28:59 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id C481530018B; Fri, 22 May 2020 11:28:48 +0200 (CEST) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id B428D212820ED; Fri, 22 May 2020 11:28:48 +0200 (CEST) Date: Fri, 22 May 2020 11:28:48 +0200 From: Peter Zijlstra To: Yu-cheng Yu Cc: x86@kernel.org, "H. Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H.J. Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Randy Dunlap , "Ravi V. Shankar" , Vedvyas Shanbhogue , Dave Martin , Weijiang Yang Subject: Re: [RFC PATCH 5/5] selftest/x86: Add CET quick test Message-ID: <20200522092848.GJ325280@hirez.programming.kicks-ass.net> References: <20200521211720.20236-1-yu-cheng.yu@intel.com> <20200521211720.20236-6-yu-cheng.yu@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20200521211720.20236-6-yu-cheng.yu@intel.com> X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, May 21, 2020 at 02:17:20PM -0700, Yu-cheng Yu wrote: > +#pragma GCC push_options > +#pragma GCC optimize ("O0") > +void ibt_violation(void) > +{ > +#ifdef __i386__ > + asm volatile("lea 1f, %eax"); > + asm volatile("jmp *%eax"); > +#else > + asm volatile("lea 1f, %rax"); > + asm volatile("jmp *%rax"); > +#endif > + asm volatile("1:"); > + result[test_id] = -1; > + test_id++; > + setcontext(&ucp); > +} > + > +void shstk_violation(void) > +{ > +#ifdef __i386__ > + unsigned long x = 0; > + > + ((unsigned long *)&x)[2] = (unsigned long)stack_hacked; > +#else > + unsigned long long x = 0; > + > + ((unsigned long long *)&x)[2] = (unsigned long)stack_hacked; > +#endif > +} > +#pragma GCC pop_options This is absolutely atrocious. The #pragma like Kees already said just need to go. Also, there's absolutely no clue what so ever what it attempts to achieve. The __i386__ ifdeffery is horrible crap. Splitting an asm with #ifdef like that is also horrible crap. This is not how you write code. Get asm/asm.h into userspace and then write something like: void ibt_violation(void) { asm volatile("lea 1f, %" _ASM_AX "\n\t" "jmp *%" _ASM_AX "\n\t" "1:\n\t" ::: "a"); WRITE_ONCE(result[test_id], -1); WRITE_ONCE(test_id, test_id+1); setcontext(&ucp); } void shstk_violation(void) { unsigned long x = 0; WRITE_ONCE(x[2], stack_hacked); }