Received: by 2002:a25:1985:0:0:0:0:0 with SMTP id 127csp809151ybz; Wed, 29 Apr 2020 09:45:36 -0700 (PDT) X-Google-Smtp-Source: APiQypK0z/iOO0kC7EjbzoZq694iQ1SAH12vazvAckc6iHB9MltoM8DUmUDx29ntMCR+oZUaelPm X-Received: by 2002:a05:6402:1d93:: with SMTP id dk19mr3226938edb.170.1588178736804; Wed, 29 Apr 2020 09:45:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1588178736; cv=none; d=google.com; s=arc-20160816; b=tHwWNhG2H0ClBKPcLUEK0r6q+kAPuQQwlG3xktbNq877/GC7Psw0wHXm8XmNjyMb/r /IHRO7s+UXcMsD0BD/CdSheo1hgelpVFUDHRUWIIBJuiH2RVzBDNJa3L+19aXWjBgLbV XcE5SIXLsmJpBxk+R6HlT7VJ8ebkpyoPHnhbBVxER3s3vCuKN0mbwx7LlkOWpo+xZPSb iqAXkagLFy7TnfMpAFiBhQLmR1VkmRlfDItUWRsHAKfy+bPh7e6GCVVrtSOk9X3QFRM8 +b2aqVCHG32lhxpjMDOkP6ME8+om5mXITXLAqEWuuXXKgIHL/UExTar+dQ+4QYHnCFDv vQtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=Soyw9S9LJ0kEBvLxc8ho+FLJU9rBaEvvIRJw4kSECSA=; b=U3qwVG+nf7+ZJNnIZqZ8NPZBwHWUVQjmEiU/N86wBn4CFaWbjjcDuAcitiEfKRnek3 TxAGQCJGrButWrdWEOaOGpV36l0nRVekMys/UTqPLpHSmbGKndXYEbc7R9plEMvV0CX9 QQz8iaGZ1MWnxn02mIe/5GyLDbhP2nvLoZaGANiBiynK73U0qqm3CdqDp+VrMNMVRJuW nocQSk0u4uXaLg87eapQcylaT44l8i3FlRG04cdTuAikWhOi4yARkxhy+btx0UR4FzJk QYtGvyc4dzEwk4oR2Sxwa/ojK+UBJGh2R9lXOHJD+4RVPp5TNPUJnPC4+xgEENGXuCBV 1YOw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id rs10si4121336ejb.288.2020.04.29.09.45.13; Wed, 29 Apr 2020 09:45:36 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726621AbgD2Qlj (ORCPT + 99 others); Wed, 29 Apr 2020 12:41:39 -0400 Received: from mx2.suse.de ([195.135.220.15]:53460 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726493AbgD2Qli (ORCPT ); Wed, 29 Apr 2020 12:41:38 -0400 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 361E1AC69; Wed, 29 Apr 2020 16:41:36 +0000 (UTC) Date: Wed, 29 Apr 2020 18:41:36 +0200 (CEST) From: Miroslav Benes To: Peter Zijlstra cc: jpoimboe@redhat.com, alexandre.chartre@oracle.com, linux-kernel@vger.kernel.org, jthierry@redhat.com, tglx@linutronix.de, x86@kernel.org, Jann Horn Subject: Re: [PATCH v2 02/14] objtool: Fix ORC vs alternatives In-Reply-To: <20200429155109.GN13592@hirez.programming.kicks-ass.net> Message-ID: References: <20200428191101.886208539@infradead.org> <20200428191659.499074346@infradead.org> <20200429155109.GN13592@hirez.programming.kicks-ass.net> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 29 Apr 2020, Peter Zijlstra wrote: > On Wed, Apr 29, 2020 at 04:33:31PM +0200, Miroslav Benes wrote: > > On Tue, 28 Apr 2020, Peter Zijlstra wrote: > > > /* > > > + * Alternatives should not contain any ORC entries, this in turn means they > > > + * should not contain any CFI ops, which implies all instructions should have > > > + * the same same CFI state. > > > + * > > > + * It is possible to constuct alternatives that have unreachable holes that go > > > + * unreported (because they're NOPs), such holes would result in CFI_UNDEFINED > > > + * states which then results in ORC entries, which we just said we didn't want. > > > + * > > > + * Avoid them by copying the CFI entry of the first instruction into the whole > > > + * alternative. > > > + */ > > > +static void fill_alternative_cfi(struct objtool_file *file, struct instruction *insn) > > > +{ > > > + struct instruction *first_insn = insn; > > > + int alt_group = insn->alt_group; > > > + > > > + sec_for_each_insn_continue(file, insn) { > > > + if (insn->alt_group != alt_group) > > > + break; > > > + insn->cfi = first_insn->cfi; > > > + } > > > +} > > > > If I am reading this and previous patch correctly... > > > > The function would copy cfi only to "orig" alternative (its insn->alts is > > non-empty, orig_insn->alt_group differs from new_insn->alt_group), right? > > Yes. > > > Would it make sense to do the same for "new" alternative, because of the > > invariant? It seems to me it is not processed anywhere that way. > > No. > > > Am I missing something? Whenever I try to read all this alternatives > > handling in objtool, I get lost pretty soon. > > We only care about the ORC covering the original range, because that is > the range we execute code from. The memory where we store the > alternative instructions (.altinstruction section) is never executed, > that is, RIP should never point there, so we don't need ORC data covering > it. Aha, that's what I didn't realize (again). Note to myself (for the hundredth time): alternatives are not branches. Thanks Miroslav