Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp4192482imm; Mon, 14 May 2018 04:08:33 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo2KazeXNcODqhUzpZv1R1mx91ZP9kunhxMEKQ94FqkdvXCzIE4L9npjgJjmZ377YKQ89za X-Received: by 2002:aa7:83c7:: with SMTP id j7-v6mr10034842pfn.50.1526296113604; Mon, 14 May 2018 04:08:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1526296113; cv=none; d=google.com; s=arc-20160816; b=vGUUe9iStM8q8emTGOXIJDNFMJxtpiEQAL+W1lknxgr18sPM3o0Bwu7+Op88Imd/rv QATZ2Tdf3gHaOhHr097LSuAHHX0vUnQOWaHo/8T2OLBp50RBSJvmcR3J7VsnLsBdinCp cfOn+sYdGbWs47IyGbbVX3MPD/boxBcHTq6HO8WRtAqd8KImoKhc41/dUrXPBBrXZ4w9 6TRImMASA2MBr4tOrdpFLx558Yv/Pckon2Bfas91vu17yx1qptK+qtZwXRldqQnb/Aor 6jTd3gg9XTj0PTJvnYgfmHoyMtBSnP9MmuAAqOAA1/h85nUOnP+B+GNrea2U8Q+X0+X+ mbkg== 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:arc-authentication-results; bh=qq6U1AEHxjk4WiON0u9WzUu6RTuQ+9u6T6eQyOnJc6k=; b=EUTBt8L/icDVSI8lKD4x5vSxbbacnkA1q58oNKB3qzoh7Oa0Ht4FmgOuX4OrvfLyWp gRomQvM/ilBv4vcs1bHyk80tS9W4oG2hQyyNAtosHuFHZQgi8OSS8nOM+LXjSGeYoHLD CiTUH74NnaGSW4nP4tHub0v9St1ZOkfrV4XWV3PxfYFTqswzItnNZGb9W5J8r0dGYUY4 UX+tLCKNTMrbOFMnUe/9RpyeNjFvnZNvEy7YU7mfYivKIIMkTnqbr9ERNqLnvlX/KzE8 8k1QYMCfCmYkcaOEQ7shbuHRPqszDY5+yQgTdXifkVxrRVAYtBPWXH58V4oe9c/yfVqn d2Ug== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a127-v6si7347241pgc.619.2018.05.14.04.08.18; Mon, 14 May 2018 04:08:33 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752649AbeENLGK convert rfc822-to-8bit (ORCPT + 99 others); Mon, 14 May 2018 07:06:10 -0400 Received: from terminus.zytor.com ([198.137.202.136]:49235 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752260AbeENLGI (ORCPT ); Mon, 14 May 2018 07:06:08 -0400 Received: from wld62.hos.anvin.org (c-24-5-245-234.hsd1.ca.comcast.net [24.5.245.234] (may be forged)) (authenticated bits=0) by mail.zytor.com (8.15.2/8.15.2) with ESMTPSA id w4EB5cUj707628 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Mon, 14 May 2018 04:05:39 -0700 Date: Mon, 14 May 2018 04:05:31 -0700 User-Agent: K-9 Mail for Android In-Reply-To: <83866d054b27419c9d9dd97d9c66c3de@AcuMS.aculab.com> References: <20180507213755.GA32406@avx2> <20fb84fd5eef4c45b2d38d0290235d5d@AcuMS.aculab.com> <5c6762fe-5cbe-42ed-ac4e-a7144b8ef7ad@zytor.com> <83866d054b27419c9d9dd97d9c66c3de@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8BIT Subject: RE: [PATCH] x86: pad assembly functions with INT3 To: David Laight , "'Alexey Dobriyan'" , "tglx@linutronix.de" , "mingo@redhat.com" CC: "linux-kernel@vger.kernel.org" , "x86@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 May 14, 2018 2:04:38 AM PDT, David Laight wrote: >From: H. Peter Anvin >> Sent: 11 May 2018 19:54 >> >> On 05/10/18 09:39, David Laight wrote: >> > From: Alexey Dobriyan >> >> Sent: 07 May 2018 22:38 >> >> >> >> Use INT3 instead of NOP. All that padding between functions is >> >> an illegal area, no legitimate code should jump into it. >> >> >> >> I've checked x86_64 allyesconfig disassembly, all changes looks >sane: >> >> INT3 is only used after RET or unconditional JMP. >> > >> > I thought there was a performance penalty (on at least some cpu) >> > depending on the number of and the actual instructions used for >padding. >> > >> > I believe that is why gcc generates a small number of very long >'nop' >> > instructions when padding code. >> > >> >> There is a performance penalty for using NOP instructions *in the >> fallthrough case.* In the case where the padding is never supposed >to >> be executed, which is what we're talking about here, it is >irrelevant. > >Not completely irrelevant, the instructions stream gets fetched and >decoded >beyond the jmp/ret at the end of the function. >At some point the cpu will decode the jmp/ret and fetch/decode from the >target address. >I guess it won't try to speculatively execute the 'pad' instructions >- but you can never really tell! > > David The CPU doesn't speculate down past an unconditional control transfer. Doing so would be idiotic. -- Sent from my Android device with K-9 Mail. Please excuse my brevity.