Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp3818778pxb; Wed, 13 Oct 2021 13:41:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx0ysFXppBMUJnmeJIVXMRXQycsBfVZjaea5KAoCy1+VYfPf/uDJY6mNLsCopZKneZdv1Oo X-Received: by 2002:a17:906:3784:: with SMTP id n4mr1734618ejc.129.1634157712070; Wed, 13 Oct 2021 13:41:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1634157712; cv=none; d=google.com; s=arc-20160816; b=SkavfIF9lY8kjJwZD1YO7c9eTGukHMn8G9HOGjjjN+WHoG53qbf2+/xefIh6u7Doou czh1LhtAWY0Ua/n+JtDSskx1gW/pJOwgQbTPe/lLkaOn2D8BdVw6Y2txHHVaAImYoi3Q Kbm9J8vOGqAu0jDJ00ZTMc8/v0IRfjKOhhhzBFjzzZgErVS+xqzGfw9HY6p/XZ07xVRe 3+mW2sTmGoA5x9AEboSHGMq290kdVJ8NTHLWJbmVbz9XTZbph5CBdvn3XLcLN9ntuh0n 7s1rNRysh5jkNo0/uhug7/Sg9/RHgKlpOEZif1SLC04xAHQbeQ1Q6lXWf7XNs36vlzMT AWdA== 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=UdI4k1G2xXQGGaDcm9O/XqTUCkeBotStzWD8zREaWSs=; b=zPlumojOHmGY+uP7WBxrK7oOLTXf9War8HtE9A9mSBzm0fjy5HjexDH1kyglRL+tMV q5A2/QDTIra9DaR/oGnrm+luJwE0kIrKRJoQlVXHpZc2EIsSinMQ3c9EdrA5IhyvcPgm TP1D5ztlNTfS3YpQOrO6UTFklOKXhl1BlYlqlynjIERIZIQ1rYeVbnLZoHohHAQgUwA6 0CGaBMJo4r/hQciDOfpaAa3h+dwcrtWRXV1P00dDh5r2MPXz8GQy2uip/Za+kwFopOhk J29SXK3iYtL0qPFxscVYgODfWYs2WNKh/Scl6ts2c2b0N5UNMYVjtz3/puwJXMSKO+pA XCZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MObN1WaA; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f5si928296ejf.660.2021.10.13.13.41.28; Wed, 13 Oct 2021 13:41:52 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=MObN1WaA; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229569AbhJMUlg (ORCPT + 99 others); Wed, 13 Oct 2021 16:41:36 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:60008 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229496AbhJMUlg (ORCPT ); Wed, 13 Oct 2021 16:41:36 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1634157572; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=UdI4k1G2xXQGGaDcm9O/XqTUCkeBotStzWD8zREaWSs=; b=MObN1WaAyaxvL79IOUUfjItTzDMzkGhrXcNKMSJvQ9uvVBSxf2Kggu9p5H0C1quK4deUSv n9L6gVqCbDkFEZTA0P1gcjTByrn7Y5yYUnFNvzhBafk41u8Mxwx01Vh3weMw+ZiiiQmxd0 ITsVfj4KF1qIIM7L71PetQwWT9jpQKk= Received: from mail-oo1-f70.google.com (mail-oo1-f70.google.com [209.85.161.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-317-gln0uujhMdGHxtAF8WZbmw-1; Wed, 13 Oct 2021 16:39:30 -0400 X-MC-Unique: gln0uujhMdGHxtAF8WZbmw-1 Received: by mail-oo1-f70.google.com with SMTP id u1-20020a4a6141000000b002b6d25c0103so1710017ooe.2 for ; Wed, 13 Oct 2021 13:39:30 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=UdI4k1G2xXQGGaDcm9O/XqTUCkeBotStzWD8zREaWSs=; b=u/kGCA6kJCudZUin2/BBAIGgByVgGBxJOr3eUZGe9IMymbA6aC4Cig9o+HuHFHEZQK bnzGXHX9z7fs1OLpaQNZd+DHHn2236U+8TG+yROaxuFiG3TU+GxDZD5aliXaq3892j3X qvJ45e+A0lrN2BekvgeC3vay2nDOYkGUpFr0hYS+xa746Nj4YSa+agJfOv3v50j9GZsv MI9b2apuuA8kPpEUaikLF4VnbANF/qKFISvHTYwQNp+zySD9Bk5EoPdWDD7kMYv0edv1 BgHn9clFl5ONjQLkTEjEnJgkJSGa3tYb1lL252+EdN8cJEHDsOwXBy6uaG2Jd8kZt27l RYcw== X-Gm-Message-State: AOAM531hyMdGWTC7jVrEY1xRhP+AUj5dTYlJ48QS6P5CaGaXDDIL38fz YIXn7mfoyvD6kk+7Wo81/6AsHyHhnG6905eoruR3xf+YHOvBWppIKmvc3o+WynZYYxmkSv9C0iY EDR0FM6XHJWI5bpkC7IUrX0DE X-Received: by 2002:a9d:3e4a:: with SMTP id h10mr1202464otg.147.1634157569987; Wed, 13 Oct 2021 13:39:29 -0700 (PDT) X-Received: by 2002:a9d:3e4a:: with SMTP id h10mr1202447otg.147.1634157569760; Wed, 13 Oct 2021 13:39:29 -0700 (PDT) Received: from treble ([2600:1700:6e32:6c00::15]) by smtp.gmail.com with ESMTPSA id o8sm127626otk.76.2021.10.13.13.39.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Oct 2021 13:39:29 -0700 (PDT) Date: Wed, 13 Oct 2021 13:39:27 -0700 From: Josh Poimboeuf To: Peter Zijlstra Cc: x86@kernel.org, andrew.cooper3@citrix.com, linux-kernel@vger.kernel.org, alexei.starovoitov@gmail.com, ndesaulniers@google.com Subject: Re: [PATCH 4/9] x86/alternative: Implement .retpoline_sites support Message-ID: <20211013203927.zbruy2ux7dug6ljk@treble> References: <20211013122217.304265366@infradead.org> <20211013123645.002402102@infradead.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: <20211013123645.002402102@infradead.org> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Oct 13, 2021 at 02:22:21PM +0200, Peter Zijlstra wrote: > +static int patch_retpoline(void *addr, struct insn *insn, u8 *bytes) > +{ > + void (*target)(void); > + int reg, i = 0; > + > + if (cpu_feature_enabled(X86_FEATURE_RETPOLINE)) > + return -1; Better to do this check further up the call stack in apply_retpolines() before looping through all the call sites? > + > + target = addr + insn->length + insn->immediate.value; > + reg = (target - &__x86_indirect_thunk_rax) / > + (&__x86_indirect_thunk_rcx - &__x86_indirect_thunk_rax); > + > + if (WARN_ON_ONCE(reg & ~0xf)) > + return -1; It would be more robust and less magical to just have a basic lookup table array which converts a thunk address to a reg. Then you can just avoid all the safety checks because it's no longer insane ;-) -- Josh