From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00461E7717F for ; Mon, 16 Dec 2024 12:22:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7476D6B0089; Mon, 16 Dec 2024 07:22:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6F7E76B008A; Mon, 16 Dec 2024 07:22:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5E63A6B008C; Mon, 16 Dec 2024 07:22:47 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 41E7C6B0089 for ; Mon, 16 Dec 2024 07:22:47 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id E7626160CD6 for ; Mon, 16 Dec 2024 12:22:46 +0000 (UTC) X-FDA: 82900735680.14.13340C6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf22.hostedemail.com (Postfix) with ESMTP id 24F3EC0008 for ; Mon, 16 Dec 2024 12:22:13 +0000 (UTC) Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Y69r+eSr; spf=pass (imf22.hostedemail.com: domain of oleg@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=oleg@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734351733; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=5IyPoQnMUSRrw4hzgNLn0p2ekpsZi83fqnwbnPuf+9Q=; b=dWMVZMZIOJJ9NAUiuKY+qdWLy97Gf2nAiW3BrcNx54gsBcnF8Qn2eLGFyYUnXYTBwKUAUD ziFn/9vw8sXAOpb7QLzxvU7vekxvx8vxnYT3ey3SSaryZurUrmLMAkgS6ZUtfbiIMH/VHv PDybdM6DVzoSXygmmRy4m0SZOcvjz4k= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734351733; a=rsa-sha256; cv=none; b=vsJwuR06jTRohN/F4z/HpQ8VWOdYJNI0QQjrOXJXo/ZnOecN7f+Lht6RgcXCN6/BPjI13S WilMZ3Lxh2Zly8LGUXSo48EO5UNm2jWsfKiylO0vXbgzpKJHT0icKJWp6zI+p9MohtYun8 FGGjA1Bwl/+4DQXee9qGmh7pKuGTMrw= ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=Y69r+eSr; spf=pass (imf22.hostedemail.com: domain of oleg@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=oleg@redhat.com; dmarc=pass (policy=none) header.from=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1734351764; 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=5IyPoQnMUSRrw4hzgNLn0p2ekpsZi83fqnwbnPuf+9Q=; b=Y69r+eSruyTuNnBh0mWF5TZViRYjatr/vi04v1O3f42782wGNpJaz9QU2UXEXvrXKUVgMt H3YPbpIo8Gay9ofQHYhK55diO2qDwD26TgGsZwcnEDZBsqgjQ4S4I58gpbKKCa8DmB4THU S7YlJcdaNtMXJm+hDDIcPqe4cyHU6DQ= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-625-V8jxa8ICOk6dUpSsE9D0xg-1; Mon, 16 Dec 2024 07:22:37 -0500 X-MC-Unique: V8jxa8ICOk6dUpSsE9D0xg-1 X-Mimecast-MFC-AGG-ID: V8jxa8ICOk6dUpSsE9D0xg Received: from mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.12]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 233061955F56; Mon, 16 Dec 2024 12:22:35 +0000 (UTC) Received: from dhcp-27-174.brq.redhat.com (unknown [10.45.225.224]) by mx-prod-int-03.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with SMTP id 0D90E19560A2; Mon, 16 Dec 2024 12:22:29 +0000 (UTC) Received: by dhcp-27-174.brq.redhat.com (nbSMTP-1.00) for uid 1000 oleg@redhat.com; Mon, 16 Dec 2024 13:22:11 +0100 (CET) Date: Mon, 16 Dec 2024 13:22:05 +0100 From: Oleg Nesterov To: David Laight Cc: "linux-mm@kvack.org" , 'Jiri Olsa' , Peter Zijlstra , Andrii Nakryiko , "bpf@vger.kernel.org" , Song Liu , Yonghong Song , John Fastabend , Hao Luo , Steven Rostedt , Masami Hiramatsu , Alan Maguire , "linux-kernel@vger.kernel.org" , "linux-trace-kernel@vger.kernel.org" Subject: Re: [PATCH bpf-next 08/13] uprobes/x86: Add support to optimize uprobes Message-ID: <20241216122204.GB374@redhat.com> References: <20241211133403.208920-1-jolsa@kernel.org> <20241211133403.208920-9-jolsa@kernel.org> <1521ff93bc0649b0aade9cfc444929ca@AcuMS.aculab.com> <20241215141412.GA13580@redhat.com> <20241216101258.GA374@redhat.com> <0916e24539ba4bae9fb729198b033bd7@AcuMS.aculab.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <0916e24539ba4bae9fb729198b033bd7@AcuMS.aculab.com> User-Agent: Mutt/1.5.24 (2015-08-30) X-Scanned-By: MIMEDefang 3.0 on 10.30.177.12 X-Rspamd-Queue-Id: 24F3EC0008 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: omcj7oi7p4wgsd9rf3c5c51a1iuguto3 X-HE-Tag: 1734351733-673213 X-HE-Meta: U2FsdGVkX1//hsM8htEpk8p7TVYk7PG7BlbdbN/GuZAaDuplGPqNox6YoASr0nXG/X6ycv/z8x/wg3/ufqced1awI/G1cGbWu1Eo7PJ11VWOKgmdUIS25T10bFSA7zQz9TTBGuFRrxtBAxOa1+jIS8nxwPdk32gARuYkQ+7KMswtJdjFf3PvJV3gw+ESPIHX497wqaGYxKO/hX4uoGy1qqlkyGZzjxmSh7lMVgO9wIk9s1vq2/SaGbsnx5CxbbAg5lCRl07eMr69B9JMRV1eOTwcbfrgYvPB/JTjriOhESlgNpNuMDYVOPdPww2Y4GGMPYMu9Th2J88pF4wo2QJZDF+VXeb8gYGtJegl1gSmaDI3IsRf9oItkekjNJMuyqHf+JalPcvzDitya0BVp4Dy8dPW2bdmfj5ucMGU9oQ1HHfhzfY+kO4cBv4er2powgK9nlZs5R0ihAgBpowM3JDz3dalL9fJKaca6hzLABgQQlqFVKt3lEH31niY/PcPrV4UztynnwwHOW3EH2oPgayOzrs2q76xJyeKy51T4i2gqGXaWYeO0nsk7BJ0OVhJdLDlH/scoptmihZw5mDit6t4F5H+Mt3N4yrEsseqqMPGfA+1jRKcnbZtEpda9ajGf1NEDWhvlxRqF08YkLJje5o/e2+MBbFlrtibQCVumcQVpZ17w/twzHGBVnfa7+uehXIrsTizrWtM/7pzQkA/chBhb1R954hs/Q5IumQ8fWA8faBN4FmyiGo1WximH4/IGXIbUp4y53QFdqtx+Y+i6eDKMrgVHxESpfZ+G6ALLfVbZkN/OD8Je9vSHKA+zOKQ98pGblT6znET3GRQMyFZ8GfswIkENp09m5dMb0KQ5/e07GH2ELyAmWFlZhZ38CKHzyRVMu8Puq71M8LoLaqtiitPFf6Mr+060ejFe7lGbYv1hMYlC9efSO8FJn+Zd3MwTSBzLbQm3N7x4hU3SRedkZ9 Q5DxExNF iaTrTIhmqxALyb4dQL8N9PNNk4vncsq9G8sI1QRbED/Z/xL+2cf/6LFHlJWmIVBp9ffn0eTW4AStWrKYM37sLZmNqkvC9h17IeYyN1i40/UVsUUD1NqhnsMKyxuIKjgyyxIvNdPctF50q5OhHbBiQlAeHxeWX2CZVzGI8pfbrM/UeuRNS81NfPQmb8mR3rJNXuZaemSqDNWeQVqK452r1b1dh2YQqc+IMoe5GCPGQvz2ym0V8spqv2hs+pWcCVPJ+pBoc9OrAIfb2wX1mYr71ASRIjJ4Lxs9hJ5eJmccsogXjBOBrfv0iMMA3x4Jkb1SHUalv15ZIjg584Dfp4ye3Q8D/L4ZhcYeV+Pz4xoWDxxMI9TXgq4G8wmw5Nd7CG0BS5/NFZgpSLO/PYRjz4VeElZrKVFnydSvSIXElqyUGAfE4s2Y= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000001, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: OK, thanks, I am starting to share your concerns... Oleg. On 12/16, David Laight wrote: > > From: Oleg Nesterov > > Sent: 16 December 2024 10:13 > > > > David, > > > > let me say first that my understanding of this magic is very limited, > > please correct me. > > I only (half) understand what the 'magic' has to accomplish and > some of the pitfalls. > > I've copied linux-mm - someone there might know more. > > > On 12/16, David Laight wrote: > > > > > > It all depends on how hard __replace_page() tries to be atomic. > > > The page has to change from one backed by the executable to a private > > > one backed by swap - otherwise you can't write to it. > > > > This is what uprobe_write_opcode() does, > > And will be enough for single byte changes - they'll be picked up > at some point after the change. > > > > But the problems arise when the instruction prefetch unit has read > > > part of the 5-byte instruction (it might even only read half a cache > > > line at a time). > > > I'm not sure how long the pipeline can sit in that state - but I > > > can do a memory read of a PCIe address that takes ~3000 clocks. > > > (And a misaligned AVX-512 read is probably eight 8-byte transfers.) > > > > > > So I think you need to force an interrupt while the PTE is invalid. > > > And that need to be simultaneous on all cpu running that process. > > > > __replace_page() does ptep_get_and_clear(old_pte) + flush_tlb_page(). > > > > That's not enough? > > I doubt it. As I understand it. > The hardware page tables will be shared by all the threads of a process. > So unless you hard synchronise all the cpu (and flush the TLB) while the > PTE is being changed there is always the possibility of a cpu picking up > the new PTE before the IPI that (I presume) flush_tlb_page() generates > is processed. > If that happens when the instruction you are patching is part-read into > the instruction decode buffer then you'll execute a mismatch of the two > instructions. > > I can't remember the outcome of discussions about live-patching kernel > code - and I'm sure that was aligned 32bit writes. > > > > > > Stopping the process using ptrace would do it. > > > > Not an option :/ > > Thought you'd say that. > > David > > > > > Oleg. > > - > Registered Address Lakeside, Bramley Road, Mount Farm, Milton Keynes, MK1 1PT, UK > Registration No: 1397386 (Wales) >