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 2B931E7717F for ; Mon, 16 Dec 2024 12:50:37 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 828226B0082; Mon, 16 Dec 2024 07:50:36 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D6D66B0088; Mon, 16 Dec 2024 07:50:36 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6772E6B0089; Mon, 16 Dec 2024 07:50:36 -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 4A28B6B0082 for ; Mon, 16 Dec 2024 07:50:36 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id E1848140DC7 for ; Mon, 16 Dec 2024 12:50:35 +0000 (UTC) X-FDA: 82900805190.24.D546441 Received: from mail-wm1-f48.google.com (mail-wm1-f48.google.com [209.85.128.48]) by imf19.hostedemail.com (Postfix) with ESMTP id 2ADE61A0019 for ; Mon, 16 Dec 2024 12:50:02 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=kyX2Kwld; spf=pass (imf19.hostedemail.com: domain of olsajiri@gmail.com designates 209.85.128.48 as permitted sender) smtp.mailfrom=olsajiri@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1734353420; 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=mYTu620PtRa9BvXXAMLUJ30SROoCXOvfv0ERCSXsRn4=; b=FXDVtlRXXSmqw2E3lE7EkJXH60E2BFSNqk/xRIxc8FCFQF6VcNJh4nuHSrMNXpt/OJZNQp 2ZRUwuC3uIXPFTdeRFnKhFbAfAjQ2Ry394vrcqe/l3FvADMkFBFjirlPbL+pdLm79V2jiq YHVYklhwsDjE9e5Z4XVZ3BQcz37xkWM= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b=kyX2Kwld; spf=pass (imf19.hostedemail.com: domain of olsajiri@gmail.com designates 209.85.128.48 as permitted sender) smtp.mailfrom=olsajiri@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1734353420; a=rsa-sha256; cv=none; b=NOza4vh3gF4hrYcregpY7ZdRMjDK5oxMIzVCobbWh6lb+c2VuYGZgRoRB7VtYSNwB2wc/j iGs3oAZBnXF/i8h/WSbbms3EnqJidlY92MSh566uH0+D/gcLcEJ2GIwQAHCfS9JJ/OIgCV yugwhG6aYnqCRUpV6uQxAWhvVarS05Y= Received: by mail-wm1-f48.google.com with SMTP id 5b1f17b1804b1-4362bae4d7dso20360345e9.1 for ; Mon, 16 Dec 2024 04:50:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1734353432; x=1734958232; darn=kvack.org; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:from:to:cc:subject:date:message-id:reply-to; bh=mYTu620PtRa9BvXXAMLUJ30SROoCXOvfv0ERCSXsRn4=; b=kyX2KwldpYDAeGth8oUk+Xzo7U1zlBDvNV03WcLNfx9o/OM+T8oLJ8KuX59SJicbcG NddvNlKa4g0V/xjP6eYfGoXHJFVm1wd+5TUnPRj1mQHOid2pmjZENYpyFFLB3Jvo6gC5 MSopIgjlATAsvQ73TH2RCvNZmJCb94M2+wAS8T6IN7l3fvmEIti/GuuxKXpJCdSurJc6 MkDudcQbnjuSzgbHJ8fP4xyE9w399UoMJIewbH7X1hNw9FPkvqNmH5PRMN+66K1RAW8K Uq2I2JZOcQcEvJgqdzAShHgYtHdrWruITMNwkQwLpQjIM1IO/2iQOf6Nd1Uq4zGnSNRz qckQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1734353432; x=1734958232; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:date:from:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=mYTu620PtRa9BvXXAMLUJ30SROoCXOvfv0ERCSXsRn4=; b=nF+mWbdw7o7ugQ2rb8hpjYkqUwx7KFuN848TUvfp+Kv5LcY+TIzDRPxs5TTFZAPVtX ezoHuggFRH8Nf3D//mY3GDUDL9yLXFb3hyAnMjiRCwxqISDqLv4+un/qF2jVvNvhzuqk WkBhEle1Mfnaee4JvpH2xfJPaoD9AVaSimhZrFf4f2QjWBUrem9LyBBpS5xklUvEICIv sz4fLPulSPMe5W85YUD+a2n0yLBQV6tRIlzfINsTvtsBkmfeUOj2DEwIIdQaked8/fmC HADr+3y4WWRLiBi/oW6yI2h181CiP3/cHEwh6Syu/XmPvjBun5djdpJHYnBsHd67t+NK yoWQ== X-Forwarded-Encrypted: i=1; AJvYcCXwfAR1F3Y+7zVnWq0o9Ahmj+h6N5dSSYxuUEEGbyR2QsPVIC3U7Jrh6sM2eEX8jIYVcn8her2o/g==@kvack.org X-Gm-Message-State: AOJu0Yyk75Z9w+9SZ8zquIPb0WEOcog/47wszGoZdgNuB+RZmvUNQbQM 6otKPFC5xdElUAM8jJBSFXl2uRZKVlj2ldbtltXVf8YCp7hs8Em+ X-Gm-Gg: ASbGncsjSLJ0riHDNoyU6lAjG03RuRrEZ4+nD0JqaOsKvBNHHaTvgFF2yW96NaUt2en PkOeO5fjObvv0oVqRz9BvUPx07gmH1mtX61qTXzTGIeDocbjKbHydFStikTzq4wDOxI49s1RYfy xY7eu8WWXLdHlsHit4ovoXNd6IwDedKnruf0tFn2OZBpj3DFOsP/ubKh/avhV8xgXCMaWP00lqD Zp9ZK/o6vAMELKbRshZPNXe6ZiuXZPFRbwgNQBUrGHGsI9CcuSyBx4j0hg8uwP0mjakaTn3de6G VdEkwQpdWoUraHCkCrUpPhP/10SQqQ== X-Google-Smtp-Source: AGHT+IF5dpqJH0p9aEAMRZspfaq9uP28+SF1CA67w0e4bAkAr12nBBB6F2bhj6gzq/tBsTk7BKwXhQ== X-Received: by 2002:a5d:5984:0:b0:385:fc32:1ec6 with SMTP id ffacd0b85a97d-3888e0c081bmr9033638f8f.50.1734353431975; Mon, 16 Dec 2024 04:50:31 -0800 (PST) Received: from krava (2001-1ae9-1c2-4c00-726e-c10f-8833-ff22.ip6.tmcz.cz. [2001:1ae9:1c2:4c00:726e:c10f:8833:ff22]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-43625706588sm142177595e9.29.2024.12.16.04.50.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 16 Dec 2024 04:50:31 -0800 (PST) From: Jiri Olsa X-Google-Original-From: Jiri Olsa Date: Mon, 16 Dec 2024 13:50:29 +0100 To: Oleg Nesterov Cc: David Laight , "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: 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> <20241216122204.GB374@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20241216122204.GB374@redhat.com> X-Rspamd-Queue-Id: 2ADE61A0019 X-Stat-Signature: nd5ixpmgpwu9x7a6zabgoqo8zt9eizbd X-Rspam-User: X-Rspamd-Server: rspam11 X-HE-Tag: 1734353402-788065 X-HE-Meta: U2FsdGVkX18sEor7asxWv7iuu/BFec4ON2MUeBRwuPz/mb2E1ld07hnkivlPxncSgqm4bLOST2DLIuBGlXOi3fTg9pAsnJZzWX6VJF9aKmatuxIpi7bRkUTa1RRk24WQQjxneBESbBDcRY36ww04CvfuUYiuyOxIx8xUqqHU+KhVe40MpucCaMo+RaKOXi6q0D6DOHNJOQpY3x2wbpnDH0t6skg0Gh9UVKAFIgwZxGWSlgCf4OHNc4Qi5IqSjKyJj2/d6eLmR4f+P+hcsXvZTczvhL9yFZmXhqKTl9UZHVeM4M4COaR6CrJo1h0HkE5tCMmsactQho5UE1/IypdOV/RwdBa/KNWsuYUMNZCnOA/P4TKfJJ+zJJE6/Ig5lHo8E7qSF8FbXsFQY8+irGxSmLbYBefAple33xC/Lb0hkhMCz7lw3LbmgF3roe3yxUZy8LPA2OJ7Tun2fZwL2Xx9Z0Qj2PwJ9WD4NHqNz+P20gReI1tuWqhcveAr0WGHg/TMefyGmHptc8ET/VGq+svYzH+x5PcLx4XmZ8Fux4DZFxZm8WG2sDG5v70Yqke12/tamGPhSFmGohqsw2fOXq/r/huosgLS9g9GIzT1nEboGOTqXxicIiclGUalH0HA5XcnmtYt1L3SSw/tiELLeaXyjQbndSTJse0qD8lv7WD65tZEPfBxXbSLJX5YfQVTwz45+bbwA9RXH7jpn9uT9WGK8I1b/juv9f8MD6zzWuD+ZK/Dd7B+MzJwqd0eIfMNSEHfb0Yp8goTjtQQXJJxPfFkHSE8AByC9F9tnanIzh9xx/F/e2T/XY2TdWPe3NpOHhroO3QrxYadnJycxApQYBLOEInv0USj5mjpgGrPhDHCV5A6EwLXLP0OCdFmtbDYAiboetDyocF2seRP6egXVL8iRCw47lxUMVK9//GxJPMScneEnS/FIz9VHkgTNVoWcF55FUTv3XY2+/6AFJjWr2q dJLU91pS hWoB929471b+ynsRGyWhnbsx9ixYqyvnqpLKISw93xEfniFsOB+QNxfy74cly5NDuJDftG432Ab/kjKdcpHDptZUycYo/R8ZnzK8EE1iLNk+qU2DUWJ/eGTrXo5Wcqr83/QCXgafIHclS5qGTKIpz60jMd0KId84VAha0E8KAGY7GDTwNO43HKK1892ENWVr/pygHG4vVL+sW98OkQUoddIR97gmNuKmwjEts81Svxc7LSthVmtSGMjJk6qe67jZewSsi3KOgYGY89MfzAcutiJ3+8eDURb8ii/i8lP/+zs4oLsYggzDE8lNoNIm8jHCmJMD28fTwRjuWZWp/JyruBkcW76S/7d3ZAvsZR7dNAKBnHCfqmJGsiiIMBbC6SnUJRgVmBsOiOTWFXOJyNTX0CmakM+A7bCNGETOTd9Mw3horBsTOTRL9hOlzU+b2XNqGUhUpSP5PPNsY1TKES8rMer7XzlWSbcvoegLv9aVkdM5y6WA= X-Bogosity: Ham, tests=bogofilter, spamicity=0.081805, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Mon, Dec 16, 2024 at 01:22:05PM +0100, Oleg Nesterov wrote: > 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. if 5 byte update would be a problem, I guess we could workaround that through partial updates using int3 like we do in text_poke_bp_batch? - changing nop5 instruction to 'call xxx' - write int3 to first byte of nop5 instruction - have poke_int3_handler to emulate nop5 if int3 is triggered - write rest of the call instruction to nop5 last 4 bytes - overwrite first byte of nop5 with call opcode similar update from 'call xxx' -> 'nop5' thanks, jirka > > > > 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) > > >