Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp996244imu; Fri, 11 Jan 2019 12:58:24 -0800 (PST) X-Google-Smtp-Source: ALg8bN7+QkOsnrvidi5SxNKrUBhFaH0w8mNvhfQrbAo+v75KWHz49NOUS9tiSMtLsLYWZjSm5Ncc X-Received: by 2002:a17:902:bb86:: with SMTP id m6mr16356936pls.315.1547240304142; Fri, 11 Jan 2019 12:58:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1547240304; cv=none; d=google.com; s=arc-20160816; b=L7P+UJlHRFdGEWry5/h4U1uA8nInXICWediLE1YkZgZC3LMpmI03FfMMc4k3vRFOFS bWdrcJrflf40tqZkzy8wcNioEApyN/+oHvrPQ/QERNuL7+pxg6Ahfd94jdi9W2pouhdM Q3xP9r4JCpuFrT1f/PQhK9p+7fnfIZwu8CAfdJkfwukVAsY+dk2T3XUWl+wyZqb/9cYd sfnuOpmxEWnCOkvEh4AXVXqKciwV94qOn25hgTuxd7K8gZz1Wd76QH7w4puOMCn/9NaD s+rLzJ8vbbaTl49PdEKuNSwgIM6IuCsmWCsdh2RFixQl9CMv7fLBaj/i273pLHZVW2p3 yhIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-id:spamdiagnosticmetadata:spamdiagnosticoutput :content-language:accept-language:in-reply-to:references:message-id :date:thread-index:thread-topic:subject:cc:to:from:dkim-signature; bh=90d7pAizvTB9OgI7oTf4PFXp+Tc2gc3Anjr4nq3hWMY=; b=sckGKB8n86Qio1nCPtwVbOq6sjaHCjh3AEY0K2IbAMvF3pdxq8ykEmUy1IBQNJPonO +BAd0axFzy7m/xa1fo5WB5Nug5LdQQnglpKCzQ3taJCXUsZvbRaVYk8dWdht28xY9d48 mE88fbg8/PtWWW8IculFYiL8k3wbbtK2aWDU9/F5/jYOQPSsiYf1BC/7deoJGTmKVVT2 NrvRv+qwyx/2ZN/ZbY2BCnIqtK1p9p9BaFukQ6Hwjoos5DswDvpxHJu45MiwpwxRVVW4 z/yXafg4F0ZNROcIem3MOgIEdosKHyUrDEkdiK+hhoL7Iq4Fe4UdcS5PcIDC09zaQrQJ eDBw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@vmware.com header.s=selector1 header.b=DcU6Adyd; 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=vmware.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c6si2121262plo.270.2019.01.11.12.58.09; Fri, 11 Jan 2019 12:58:24 -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; dkim=pass header.i=@vmware.com header.s=selector1 header.b=DcU6Adyd; 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=vmware.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387932AbfAKRyv (ORCPT + 99 others); Fri, 11 Jan 2019 12:54:51 -0500 Received: from mail-eopbgr700043.outbound.protection.outlook.com ([40.107.70.43]:45737 "EHLO NAM04-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1728616AbfAKRyt (ORCPT ); Fri, 11 Jan 2019 12:54:49 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vmware.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=90d7pAizvTB9OgI7oTf4PFXp+Tc2gc3Anjr4nq3hWMY=; b=DcU6Adyd8QgIch9b65m25EnGhoxFlD3afI4bFNgAaOFUI69yAcBedQmJ9mC7qtquPQP5g8Z5s1f70aS3mPqMgoa35WCHNxC4HQNPDH5IVULOa6EfTzRjZu/AXPkGTRaxHsfZAKh8qz3t+wpigqW+nXUvd1Y+kaKojvMb4CUFXFU= Received: from BYAPR05MB4776.namprd05.prod.outlook.com (52.135.233.146) by BYAPR05MB4600.namprd05.prod.outlook.com (52.135.233.21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.1516.9; Fri, 11 Jan 2019 17:54:43 +0000 Received: from BYAPR05MB4776.namprd05.prod.outlook.com ([fe80::35a9:ab4b:cc18:b732]) by BYAPR05MB4776.namprd05.prod.outlook.com ([fe80::35a9:ab4b:cc18:b732%2]) with mapi id 15.20.1537.013; Fri, 11 Jan 2019 17:54:43 +0000 From: Nadav Amit To: Jason Baron CC: Josh Poimboeuf , Alexandre Chartre , Sean Christopherson , Steven Rostedt , X86 ML , LKML , Ard Biesheuvel , Andy Lutomirski , Peter Zijlstra , Ingo Molnar , Thomas Gleixner , Linus Torvalds , Masami Hiramatsu , 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 Thread-Topic: [PATCH v3 5/6] x86/alternative: Use a single access in text_poke() where possible Thread-Index: AQHUqG8Wf4/RNokb7ki08kHGReVe6KWoPeeAgACCrgCAAAOIgIAAAtyAgAAEMYCAAAHSAIABL4oAgAA3H4CAABXrAIAAAyYAgAAMFgCAAAPLAA== Date: Fri, 11 Jan 2019 17:54:43 +0000 Message-ID: <73A1EC50-AF51-4035-A3B3-D989AC89B929@vmware.com> 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> <20190111152809.ejutcmqrx4ud3fli@treble> <20190111165752.z6e2dfktj2caqi4n@treble> In-Reply-To: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=namit@vmware.com; x-originating-ip: [208.91.2.1] x-ms-publictraffictype: Email x-microsoft-exchange-diagnostics: 1;BYAPR05MB4600;20:qlZkwu0YnDx8B9XzXLx3ktiiwWj1rLfrUhQu7WzAk7kpPMpLdCUmVo24P1/XkUOEhJfYt8C3bQUlsavb07+E1LXWR+DicUrGmzKqYXW6gaEr6czLOQieHo6UrUpvrIbzCH6L41zuD9HewuTi95LVV5TTFfZiwijDLn0NOW/jSJc= x-ms-office365-filtering-correlation-id: 094260b5-9e90-43f8-a520-08d677edde2b x-microsoft-antispam: BCL:0;PCL:0;RULEID:(2390118)(7020095)(4652040)(8989299)(5600109)(711020)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(2017052603328)(7153060)(7193020);SRVR:BYAPR05MB4600; x-ms-traffictypediagnostic: BYAPR05MB4600: x-microsoft-antispam-prvs: x-forefront-prvs: 09144DB0F7 x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(366004)(39860400002)(376002)(396003)(136003)(346002)(199004)(189003)(8936002)(102836004)(8676002)(71200400001)(71190400001)(25786009)(93886005)(256004)(14444005)(53546011)(5660300001)(3846002)(6116002)(186003)(7416002)(33656002)(6506007)(105586002)(106356001)(446003)(2906002)(97736004)(229853002)(6306002)(478600001)(6512007)(6486002)(4326008)(68736007)(53936002)(26005)(81156014)(82746002)(966005)(6436002)(86362001)(11346002)(54906003)(7736002)(305945005)(476003)(6246003)(486006)(6916009)(99286004)(36756003)(316002)(83716004)(14454004)(76176011)(66066001)(2616005)(81166006);DIR:OUT;SFP:1101;SCL:1;SRVR:BYAPR05MB4600;H:BYAPR05MB4776.namprd05.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1;MX:1; received-spf: None (protection.outlook.com: vmware.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: tNbbjkFsiIwUgGoyswqNkUAaGSCBOaHC4aoAf8Paq2NDT+IVXxw8bv8roSz4TeZyIHeCQcm57MbdKRSy4hr1DhjDMFt4ZrjqJxm9LBlbE4g0hhwONF+Cv4kkTor44HnX/U55MLB1wQEmx4VLFTkCBIq316IWJ74irOXEmyRP9CvMMRoJJBEuI7T2Vr4Uvc7JdYjkrJ2fmnJSCZKiYhGwQGJMYsZXxK8kS36cnd7jRLikNRs8JlMn4YY20L0pfHYRyHqyMijxpzlUqGfGKl4KmhokeyK3R128dPcCPz/ftBprjoDNV2ugzKWC6VaWqwpfy/hktiio63VpGnKQLPjdsv+tevOUxBEYkSGXd6UH/QDuiLhY6bLXHgKSRWYLlmEgRFNHjG2IqEdqOdASDumQVdF1vZQAlV+ZHFiDZXRN5II= spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-ID: Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: vmware.com X-MS-Exchange-CrossTenant-Network-Message-Id: 094260b5-9e90-43f8-a520-08d677edde2b X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Jan 2019 17:54:43.6049 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: b39138ca-3cee-4b4a-a4d6-cd83d9dd62f0 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR05MB4600 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > On Jan 11, 2019, at 9:41 AM, Jason Baron wrote: >=20 > On 1/11/19 11:57 AM, Josh Poimboeuf wrote: >> On Fri, Jan 11, 2019 at 05:46:36PM +0100, Alexandre Chartre wrote: >>> On 01/11/2019 04:28 PM, Josh Poimboeuf wrote: >>>> On Fri, Jan 11, 2019 at 01:10:52PM +0100, Alexandre Chartre wrote: >>>>> To avoid any issue with live patching the call instruction, what abou= t >>>>> toggling between two call instructions: one would be the currently ac= tive >>>>> call, while the other would currently be inactive but to be used afte= r a >>>>> change is made. You can safely patch the inactive call and then toggl= e >>>>> the call flow (using a jump label) between the active and inactive ca= lls. >>>>>=20 >>>>> So instead of having a single call instruction: >>>>>=20 >>>>> call function >>>>>=20 >>>>> You would have: >>>>>=20 >>>>> STATIC_JUMP_IF_TRUE label, key >>>>> call function1 >>>>> jmp done >>>>> label: >>>>> call function2 >>>>> done: >>>>>=20 >>>>> 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 function= 1. >>>>=20 >>>> What about the following race? >>>>=20 >>>> 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 >>>=20 >>> If the function1 call is active then it won't be changed, you will chan= ge >>> function2. However, I presume you can still have a race but if the func= tion >>> is changed twice before calling function1: >>>=20 >>> CPU1 CPU2 >>> static key is false, doesn't jump >>> task gets preempted before calling function1 >>> -- first function change= -- >>> patch "call function2" >>> change static key to tru= e >>> -- second function chang= e -- >>> start patching "call fun= ction1" >>> task resumes, sees inconsistent call instruction >>>=20 >>> So right, that's a problem. >>=20 >> Right, that's what I meant to say :-) >=20 > could you use something like synchronize_rcu_tasks() between successive > updates to guarantee nobody's stuck in the middle of the call > instruction update? Yes its really slow but the update path is slow anywa= ys. You would need to disable preemption or IRQs before the call, which is not something you want to do (when would you enable it?) Having said that, I suggested something somewhat similar things here: https://lore.kernel.org/lkml/F6735FF5-4D62-4C4E-A145-751E6469CE9E@vmware.co= m/ https://lore.kernel.org/lkml/CCF7D3C7-9D12-489B-B778-C2156D2DBF47@vmware.co= m/