Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp699251ybl; Fri, 31 Jan 2020 06:29:44 -0800 (PST) X-Google-Smtp-Source: APXvYqwh27p6/SWefkH+9f/kpcz2WL8ia+xMrBX+x45Qv4BzljetDiGGVe9GeYe7PxZUhhdVQVNK X-Received: by 2002:aca:3f8b:: with SMTP id m133mr859140oia.51.1580480983874; Fri, 31 Jan 2020 06:29:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580480983; cv=none; d=google.com; s=arc-20160816; b=TDgsOF3dVcNhuYdmjmvCTFGnRLA3Xh6nAr+go+W2KXSSwP6RG+0EVbYIyOscA/K+QT Y/HQU5+NQFTG1LfAFCU2qSfI9YHuVf2B74F8yZKmeCEoHafzPjf0IBYWy+qPFyrL3dbn k8WAIAa7LTSzJzssMocn21fwyOTdyTXLAOykYM9o81atj2SR3RY+/Gl7CBAmG9fR03vU ZLKizEHNfSrhc4gLUB2KVoCfrr21nI0DKRqTLeg/VAQqF4AI6Dqc3ER1XwsNBWaORevz 1LCUT6VKls0OZM6kt9eSzKCDwrAuuX2xw8HJ0aN0bsTi40i8VufLfP8wQUG7+RqqgDob jIvw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=/crfkkkkEoTN/rxdDDZiVXieXnX5U8uDQ3F/1eIAXHs=; b=HaxQbAHDEVudxDBzwSdArpwptxik9feP1rJmqn5jMIFNFXb47I3r/jyageJrpUaBOP emabIP85tFYfgh4HBzSGkYBjjB+0Q9seQkOcQxEKCbwd7p8PEtIJf8WMaFWTUGVAnlU4 Vf8PaIdkgkGIgIqBu6S0VctDiAshmzGyJc4cWwfYNbV9ktvn1Xkn6rv/vBsi7RyjFcst F7UJnC+OK2gA3sb/7dVQr2+iWv4/2HB93cc75SPajNWkmmXHIe9yfvt/Jp5NKznu5Ol/ COXilYydyrQywdsHedmDsz4YyjS81UAeuZcNX1pv7Ct3mzN1Hbn063mfjvBHtLZFk4b5 MeMw== 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 v25si4838767ote.90.2020.01.31.06.29.31; Fri, 31 Jan 2020 06:29:43 -0800 (PST) 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 S1728995AbgAaO1h (ORCPT + 99 others); Fri, 31 Jan 2020 09:27:37 -0500 Received: from mx2.suse.de ([195.135.220.15]:33544 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728730AbgAaO1h (ORCPT ); Fri, 31 Jan 2020 09:27:37 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 6EC3EAB87; Fri, 31 Jan 2020 14:27:35 +0000 (UTC) Date: Fri, 31 Jan 2020 15:27:27 +0100 From: Borislav Petkov To: Linus Torvalds , Josh Poimboeuf Cc: "Luck, Tony" , Ingo Molnar , Linux Kernel Mailing List , Thomas Gleixner , Borislav Petkov , Peter Zijlstra , Andrew Morton Subject: Re: [GIT PULL] x86/asm changes for v5.6 Message-ID: <20200131142727.GB14851@zn.tnic> References: <20200129132618.GA30979@zn.tnic> <20200129170725.GA21265@agluck-desk2.amr.corp.intel.com> <20200129183404.GB30979@zn.tnic> <20200130085134.GB6684@zn.tnic> <20200130173910.GK6684@zn.tnic> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org + Josh. On Thu, Jan 30, 2020 at 10:02:54AM -0800, Linus Torvalds wrote: > Maybe with the exception that a short conditional jump inside the > alternative code itself is fine. > > Because a branch-over inside the alternative sequence (or a loop - > think inline cmpxchg loop or whatever) would be fine, since it's > unaffected by code placement. Perhaps something like the below as a start. The build becomes really noisy if the error case is hit because aborting in handle_group_alt() really messes up objtool processing but that is perhaps ok as the idea is to *see* that something's wrong. --- diff --git a/tools/objtool/check.c b/tools/objtool/check.c index 4768d91c6d68..b4dfd625842d 100644 --- a/tools/objtool/check.c +++ b/tools/objtool/check.c @@ -756,7 +771,9 @@ static int handle_group_alt(struct objtool_file *file, last_new_insn = NULL; insn = *new_insn; sec_for_each_insn_from(file, insn) { - if (insn->offset >= special_alt->new_off + special_alt->new_len) + unsigned long new_offset = special_alt->new_off + special_alt->new_len; + + if (insn->offset >= new_offset) break; last_new_insn = insn; @@ -765,8 +787,12 @@ static int handle_group_alt(struct objtool_file *file, insn->func = orig_insn->func; if (insn->type != INSN_JUMP_CONDITIONAL && - insn->type != INSN_JUMP_UNCONDITIONAL) + insn->type != INSN_JUMP_UNCONDITIONAL) { continue; + } else { + if (insn->offset > 0 && insn->offset + insn->len < new_offset) + ERROR("Subsequent JMP instructions are not alternatives-patched. Stopping."); + } if (!insn->immediate) continue; diff --git a/tools/objtool/warn.h b/tools/objtool/warn.h index cbb0a02b7480..652c7adc7650 100644 --- a/tools/objtool/warn.h +++ b/tools/objtool/warn.h @@ -40,6 +40,14 @@ static inline char *offstr(struct section *sec, unsigned long offset) return str; } +#define ERROR(format, ...) \ +({ \ + fprintf(stderr, \ + "%s: error: objtool: " format "\n", \ + objname, ##__VA_ARGS__); \ + abort(); \ +}) + #define WARN(format, ...) \ fprintf(stderr, \ "%s: warning: objtool: " format "\n", \ -- Regards/Gruss, Boris. SUSE Software Solutions Germany GmbH, GF: Felix Imendörffer, HRB 36809, AG Nürnberg