Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp693829imu; Fri, 11 Jan 2019 07:29:41 -0800 (PST) X-Google-Smtp-Source: ALg8bN7edOvWCRFuasw3w3DQvpkNm1ZBLqaIoygxRx3cl1dtL2/Lt6P8/eXPfI2tk5a2peA0nbrs X-Received: by 2002:a63:d904:: with SMTP id r4mr13797069pgg.207.1547220581149; Fri, 11 Jan 2019 07:29:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547220581; cv=none; d=google.com; s=arc-20160816; b=LUDL1LyLAyj1oczAvjKcDS9lKYqCXKQ5pugcbW6nNUc+4YjFZuooKmnAut9nLOa3Lu mOyig5yxz08gKc8Sv+ssCAyWipydfMFEqxeSz2KS0kCkJJw/kskdBFYsEKnHSXobGkMk Q6Wu4KOLntFEtvEtzUhtfu9guki/PwX/6IczaKAumsHDnPlSUcjtrGrmVjYCtxpF0hNZ 1wBDduffhE8/Ctz128RLgow7QYiSCy3JvA/5t09woCL754p61VXFOqm/Su12FkGoK5yA dwFILK4cZbWTXFTz0SOudKIb8UNiNWmH+Zrf3K0mSJtXA0rZEGfmG8X9q0P+XM8Rpwm0 3VTA== 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-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=BDpVTge91rbbVCvD275duSkboe6y72vWed7oV9X05L8=; b=gCECwazUy88gTmM9UGdNS8PBKIjTz9CgGSMx7hhOvCDgl/tqvFK/wjnUeo9fjzMrZ3 fPr+MnSQHwikBnS2bAkSbAmE7xQ+ZagD/rKR0EGkRRopcY66/qrftPcXIFuBkl7w8CC7 1JOZZwDvItgdVF8o6TxrYyknS+cGSpzxMpwKnS7rjzd0kr7ySpLIfsp3+yRRePFUR5ZL 3KnJDbzHntu418aWTdqi9dRs5tvKiA270ef7ApdzWZdfjsWmhZbEXOlH37rFGBj+v+Kx SX5CNjKgbQCaL4/PMvfMm53vFoBG4Mj7b/D3Tx2VhkoPl53cyTlOMgz9SevEkk8nCKa0 /VyQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c9si6855056pll.439.2019.01.11.07.29.25; Fri, 11 Jan 2019 07:29:41 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1733199AbfAKP2S (ORCPT + 99 others); Fri, 11 Jan 2019 10:28:18 -0500 Received: from mx1.redhat.com ([209.132.183.28]:37033 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728958AbfAKP2S (ORCPT ); Fri, 11 Jan 2019 10:28:18 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 457B94E93F; Fri, 11 Jan 2019 15:28:17 +0000 (UTC) Received: from treble (ovpn-122-231.rdu2.redhat.com [10.10.122.231]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 5C3BA5C689; Fri, 11 Jan 2019 15:28:11 +0000 (UTC) Date: Fri, 11 Jan 2019 09:28:09 -0600 From: Josh Poimboeuf To: Alexandre Chartre Cc: Sean Christopherson , Steven Rostedt , Nadav Amit , X86 ML , LKML , Ard Biesheuvel , Andy Lutomirski , Peter Zijlstra , Ingo Molnar , Thomas Gleixner , Linus Torvalds , Masami Hiramatsu , Jason Baron , Jiri Kosina , David Laight , Borislav Petkov , Julia Cartwright , Jessica Yu , "H. Peter Anvin" , Rasmus Villemoes , Edward Cree , Daniel Bristot de Oliveira Subject: Re: [PATCH v3 5/6] x86/alternative: Use a single access in text_poke() where possible Message-ID: <20190111152809.ejutcmqrx4ud3fli@treble> References: <279b8003f7f0a6831d090ab822d37bc958f974de.1547073843.git.jpoimboe@redhat.com> <8138A1EE-359D-4CD2-8E96-5BF00313AB3B@vmware.com> <20190110172004.wuh45xoafynfm2df@treble> <20190110123243.3b9e0856@gandalf.local.home> <20190110174257.GE16556@linux.intel.com> <20190110125757.1c8d2870@gandalf.local.home> <20190110180428.GG16556@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20180716 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Fri, 11 Jan 2019 15:28:17 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 11, 2019 at 01:10:52PM +0100, Alexandre Chartre wrote: > To avoid any issue with live patching the call instruction, what about > toggling between two call instructions: one would be the currently active > call, while the other would currently be inactive but to be used after a > change is made. You can safely patch the inactive call and then toggle > the call flow (using a jump label) between the active and inactive calls. > > So instead of having a single call instruction: > > call function > > You would have: > > STATIC_JUMP_IF_TRUE label, key > call function1 > jmp done > label: > call function2 > done: > > If the key is set so that function1 is currently called then you can > safely update the call instruction for function2. Once this is done, > just flip the key to make the function2 call active. On a next update, > you would, of course, have to switch and update the call for function1. What about the following race? CPU1 CPU2 static key is false, doesn't jump task gets preempted before calling function1 change static key to true start patching "call function1" task resumes, sees inconsistent call instruction -- Josh