Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp2791243ybi; Mon, 17 Jun 2019 10:31:46 -0700 (PDT) X-Google-Smtp-Source: APXvYqxxmUbeBX1jpY6a7BndGiYEZrKBulI5h+Ic3/U63rhSiRDH//dVpsLApWGpDrSWL+jTzC9T X-Received: by 2002:a17:90a:cf0d:: with SMTP id h13mr26434124pju.63.1560792370014; Mon, 17 Jun 2019 10:26:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1560792370; cv=none; d=google.com; s=arc-20160816; b=zXyT12GsKW5Toqk+PTFtHe+X98WYql1muH/ayI6JdQeE15Wq9Mp2G3EKdBLDt6tATp wnFXT4CY4w3biLpuEsYOJ3pZNV2oHVGoUmQPV7oRF40sSqizGNQw4TrRn8k5lEcrsdPW xpi5mXCrUwtpNnwkXTzap89qUWTrKy7NTdbzNlxlas9N/5MTfyJNzEq6cnr+m+xgAmmo /35frDXgiOAYl4qdSw1bHWKHG8gP63171RrTzMuf2nQznY/ZLfFN19TdIk9D8svg+d05 OMFzFwK6rtXQL5CA/IcL0UkuqvZNyqeLWTl1Tl61q5VisFs0yBdAzNpykz6aRwaTZ+pv fEKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=ElwqsrnTw8otIZtRyoe18XqvdEm0zgnnuQFkxhNWSa0=; b=LeCfJLFR9CKSvjvB8v9iEIYUNuaBMq+gFaCWClipJCIbZz2I+LATHfg1Z/c/E9vmnZ wXiSyxdXV9/q4C0hipQPSIvzu+FMLnYDZr0N9nJQn5h+S00m6m52cXQOf+Kl1iI3OehX WWOq/cgI13+IIQB/gcNPxXC53rQQSKpPh9142Sj/YNM1ZYkkpN3f/QqgmAAlFfbrD6vz LndXuZXJwooHv6Vqsnl2Vshisol6USIrdrrLdiTsX3aPGCk5JY+QejMV7IzwhL7555kf ZURpygiijb7EClsl9gDQzPbc79IsDmtuPLt+clNmwCv9LAEZ9KM0CIWu8k4znrIFsKBH 8KVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=PKt2zXLp; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 206si12014830pga.414.2019.06.17.10.25.54; Mon, 17 Jun 2019 10:26:09 -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; dkim=pass header.i=@kernel.org header.s=default header.b=PKt2zXLp; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727959AbfFQRZn (ORCPT + 99 others); Mon, 17 Jun 2019 13:25:43 -0400 Received: from mail.kernel.org ([198.145.29.99]:58426 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726004AbfFQRZn (ORCPT ); Mon, 17 Jun 2019 13:25:43 -0400 Received: from mail-wr1-f41.google.com (mail-wr1-f41.google.com [209.85.221.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 2FB892133F for ; Mon, 17 Jun 2019 17:25:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1560792342; bh=h7nODaHm/maT/oL6I7QneckfiHzF1jLenKdtuPjYT9U=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=PKt2zXLpyCIfV2w2LDOTyKIoRCmmNs27L8rG8xFX2tCYT25poy4GrUEYVHLsuGUY5 px9FZ0xMkMQjS1QxEUEd149ThWvALWk+cqw/O3AAgTiX5xGN99+Odn9FzJ7qPeiu+v 8GoDdP3UgNwWBjsU5W3N7vP/z6dAs9ulmUVjcaGQ= Received: by mail-wr1-f41.google.com with SMTP id p11so10867946wre.7 for ; Mon, 17 Jun 2019 10:25:42 -0700 (PDT) X-Gm-Message-State: APjAAAXJlALcYsXWhXZSJy57by/hW2t58CxVZUFxl6PRogdtw82bM2ha TdaLbfFO40+6OGF12oYdFZMEB8J4o0Oka25oO2ZG1A== X-Received: by 2002:adf:a443:: with SMTP id e3mr24484700wra.221.1560792338770; Mon, 17 Jun 2019 10:25:38 -0700 (PDT) MIME-Version: 1.0 References: <20190605130753.327195108@infradead.org> <20190605131945.005681046@infradead.org> <20190608004708.7646b287151cf613838ce05f@kernel.org> <20190607173427.GK3436@hirez.programming.kicks-ass.net> <3DA961AB-950B-4886-9656-C0D268D521F1@amacapital.net> <20190611080307.GN3436@hirez.programming.kicks-ass.net> <20190611112254.576226fe@gandalf.local.home> <20190611155537.GB3436@hirez.programming.kicks-ass.net> <20190617144213.GE3436@hirez.programming.kicks-ass.net> In-Reply-To: <20190617144213.GE3436@hirez.programming.kicks-ass.net> From: Andy Lutomirski Date: Mon, 17 Jun 2019 10:25:27 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH 08/15] x86/alternatives: Teach text_poke_bp() to emulate instructions To: Peter Zijlstra Cc: Nadav Amit , Steven Rostedt , Masami Hiramatsu , "the arch/x86 maintainers" , LKML , Ard Biesheuvel , Andy Lutomirski , Ingo Molnar , Thomas Gleixner , Linus Torvalds , Jason Baron , Jiri Kosina , David Laight , Borislav Petkov , Julia Cartwright , Jessica Yu , "H. Peter Anvin" , Rasmus Villemoes , Edward Cree , Daniel Bristot de Oliveira Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Jun 17, 2019 at 7:42 AM Peter Zijlstra wrote= : > > On Wed, Jun 12, 2019 at 07:44:12PM +0000, Nadav Amit wrote: > > > I have run into similar problems before. > > > > I had two problematic scenarios. In the first case, I had a =E2=80=9Cca= ll=E2=80=9D in the > > middle of the patched code-block, but this call was always followed by = a > > =E2=80=9Cjump=E2=80=9D to the end of the potentially patched code-block= , so I did not have > > the problem. > > > > In the second case, I had an indirect call (which is shorter than a dir= ect > > Longer, 6 bytes vs 5 if I'm not mistaken. > > > call) being patched into a direct call. In this case, I preceded the > > indirect call with NOPs so indeed the indirect call was at the end of t= he > > patched block. > > > > In certain cases, if a shorter instruction should be potentially patche= d > > into a longer one, the shorter one can be preceded by some prefixes. If > > there are multiple REX prefixes, for instance, the CPU only uses the la= st > > one, IIRC. This can allow to avoid synchronize_sched() when patching a > > single instruction into another instruction with a different length. > > > > Not sure how helpful this information is, but sharing - just in case. > > I think we can patch multiple instructions provided: > > - all but one instruction are a NOP, > - there are no branch targets inside the range. > > By poking INT3 at every instruction in the range and then doing the > machine wide IPI+SYNC, we'll trap every CPU that is in-side the range. How do you know you'll trap them? You need to IPI, serialize, and get them to execute an instruction. If the CPU is in an interrupt and RIP just happens to be pointed to the INT3, you need them to execute a whole lot more than just one instruction.