Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3103484imu; Sun, 13 Jan 2019 18:42:52 -0800 (PST) X-Google-Smtp-Source: ALg8bN5p/NaHHwlTaJyvxkuPZMeTiYHK3wcelSdoGbAYTeVRx3Da9HqbzS63w61bfEQinCbxgBal X-Received: by 2002:a62:c302:: with SMTP id v2mr23832218pfg.155.1547433772493; Sun, 13 Jan 2019 18:42:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547433772; cv=none; d=google.com; s=arc-20160816; b=m0MoO4DwH8GrSen1RSFsCXRTbAeGWWSUeQxFyf+X+9zDHOdtG6KCr9ft6LEIZ3ncC5 vApttzv4sYENpV301R93WUqwmUH8hBhNPdpZ3r3kYule5Q75jRtV2oHwGW0oM5cjxuxb E9Jb4AORFU6jSONHVm2KN9OaNzOrBCPd+MxFqJgcaWZn4KQs+XPBtADDbxm0lrcG2if0 GKGFx2vU0O2Hms+IvHYtDASg51SMBUpj6jSGCxcMArwEJqYhjpW0jMvZj+C/myQzj4Jy 1gJNrWb9eFEq7ihLXHKRvZZEmriF/s2JUoKyEfvyFwpPc/580K9Q7P+SmRwp1VazdmLd t+Nw== 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 :content-language:in-reply-to:mime-version:user-agent:date :message-id:references:cc:to:from:subject; bh=LpaQd23yGDnWHjfjkiZ82pqA/QXocpORc46EvRiS4uo=; b=Rk43H0ZuEHbG4s0LyRx6BeaJaOMMN38ngG05DnHktNwmHyyDZFtYsg4kVVtYtHBEKR nkHoYgegWf7O/1bDxCK7l+j3z3pUxFI8FdNPnXeRoH5PyXUWLDV+TLguLwf3z2sCSk7L a+7Wcv0wGd9/HbFzX3uAJlO2dtjQ93hTmyAx3bEZvEO+HYkNpXRsyK9o1Vce3dWkauzJ UaXilFfZSbNbGN5a0d/mCu+bHZTgeLVYpRHi4q4foYnYdS12XO4X548AGAJaIWPy8AEz 6QR2lg94S9/vwunM7SCU5g7ZYWqEhl0JTnnzEsA178zfpM9zFb6YNmznSE+KjQHaHLyp Ii6A== 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 p185si40946727pfg.112.2019.01.13.18.42.37; Sun, 13 Jan 2019 18:42:52 -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 S1726704AbfANClf (ORCPT + 99 others); Sun, 13 Jan 2019 21:41:35 -0500 Received: from terminus.zytor.com ([198.137.202.136]:43627 "EHLO mail.zytor.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726677AbfANClf (ORCPT ); Sun, 13 Jan 2019 21:41:35 -0500 Received: from carbon-x1.hos.anvin.org (c-24-5-245-234.hsd1.ca.comcast.net [24.5.245.234] (may be forged)) (authenticated bits=0) by mail.zytor.com (8.15.2/8.15.2) with ESMTPSA id x0E2eht61850475 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NO); Sun, 13 Jan 2019 18:40:43 -0800 Subject: Re: [PATCH v3 0/6] Static calls From: "H. Peter Anvin" To: Jiri Kosina Cc: Linus Torvalds , Josh Poimboeuf , Nadav Amit , Andy Lutomirski , Peter Zijlstra , the arch/x86 maintainers , Linux List Kernel Mailing , Ard Biesheuvel , Steven Rostedt , Ingo Molnar , Thomas Gleixner , Masami Hiramatsu , Jason Baron , David Laight , Borislav Petkov , Julia Cartwright , Jessica Yu , Rasmus Villemoes , Edward Cree , Daniel Bristot de Oliveira References: <20190110203023.GL2861@worktop.programming.kicks-ass.net> <20190110205226.iburt6mrddsxnjpk@treble> <20190111151525.tf7lhuycyyvjjxez@treble> <12578A17-E695-4DD5-AEC7-E29FAB2C8322@zytor.com> <5cbd249a-3b2b-6b3b-fb52-67571617403f@zytor.com> Message-ID: <207c865e-a92a-1647-b1b0-363010383cc3@zytor.com> Date: Sun, 13 Jan 2019 18:40:38 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <5cbd249a-3b2b-6b3b-fb52-67571617403f@zytor.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 1/13/19 6:31 PM, H. Peter Anvin wrote: > > static cpumask_t text_poke_cpumask; > > static void text_poke_sync(void) > { > smp_wmb(); > text_poke_cpumask = cpu_online_mask; > smp_wmb(); /* Should be optional on x86 */ > cpumask_clear_cpu(&text_poke_cpumask, smp_processor_id()); > on_each_cpu_mask(&text_poke_cpumask, text_poke_sync_cpu, NULL, false); > while (!cpumask_empty(&text_poke_cpumask)) { > cpu_relax(); > smp_rmb(); > } > } > > static void text_poke_sync_cpu(void *dummy) > { > (void)dummy; > > smp_rmb(); > cpumask_clear_cpu(&poke_bitmask, smp_processor_id()); > /* > * We are guaranteed to return with an IRET, either from the > * IPI or the #BP handler; this provides serialization. > */ > } > The invariants here are: 1. The patching routine must set each bit in the cpumask after each event that requires synchronization is complete. 2. The bit can be (atomically) cleared on the target CPU only, and only in a place that guarantees a synchronizing event (e.g. IRET) before it may reaching the poked instruction. 3. At a minimum the IPI handler and #BP handler needs to clear the bit. It *is* also possible to clear it in other places, e.g. the NMI handler, if necessary as long as condition 2 is satisfied. -hpa