Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp151361lqb; Tue, 4 Jun 2024 07:40:16 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWnlLsd1pKP420sHWPD5tG3KxPOMYQ2K0jR0NDxcEnAAJ9m75nokjX1YwdTibX5IKNfMoCkOtIxIVlLJ5sihaN0IqPfB7GgyEosaAx8Gw== X-Google-Smtp-Source: AGHT+IEzoGuNn9t6ufBuTJ5Zp/E8mZNmoMxRI+7bB9c16U4WUYttHi7OeJM2vypicT5HJk/LySo0 X-Received: by 2002:a9d:5d13:0:b0:6f9:410f:1ecc with SMTP id 46e09a7af769-6f9410f2c60mr537253a34.0.1717512016670; Tue, 04 Jun 2024 07:40:16 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717512016; cv=pass; d=google.com; s=arc-20160816; b=q2sEldt/E4FfDKwGhBCWywdAsQaEy67RCOSihpDQaVSNDEWDK79suxNghSsOBNBbg7 754QoVIKw+aaj/oNXVE6mKKytt7+4O3o66YHrEHO0oHB6i2TnIL8DEJzHg/z9VK8YHJR 320HX8WFkQ67y8M6hXTiCtooUR3rYOCyANsQB5WolhKy4seABcm0BCS2P+JV8DhsJwzq oNtIB2uDIHDnrAtnOvsARtRdMVpg2qBBxeCPET8XNJbLzIRBx7BEgNPWWfOJHdk+HTWq bpRcNzdF0b1F7QbIpzroSrDeAJIwiW0dMTvAH4t9e6S2kjovz15UBYMoUPM1sG6tICpJ Uo0w== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date:dkim-signature; bh=WH8AS3lVorPueuVFarM2V4L81baIisvkBg5pdJlXfEI=; fh=VuNOSI19EqBBCPWPWmDZ+T5hlnY1akS/4FqZPGFzXSU=; b=0VawQUs5DpX6dKGt5tv1Hj/OwODodXPGh7RUmMTTJuN19c7MNgCiXiDADw8kg1JTH9 pBEX/bXXo5/AxreX/3iqJnGAzsM/gzYa989En1XrpeMAaRXJioTr+JzmHvnK3LtgJsCZ 8PDGIWlSPL0540Ywct+H6mNNbjJ837MwapGOuwAwym0UPT+uQz56zTbkXPxw5cac9C7C ftaTyNFP7D5SkM75XMUnXB2MC17gf3DdTVY4mGQzICIfyv4zh1VUCucCK2w7d8BcShdy yx9wmnEFxZuGhwKlVXHul5BN4b++kIWyNnB9Gpyx0SlWgxBYPX5dlkUxv9TP5scmNfa4 iobQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=R+hWca0I; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-200851-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200851-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id d75a77b69052e-43ff25b6f85si112141031cf.765.2024.06.04.07.40.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 07:40:16 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-200851-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=R+hWca0I; arc=pass (i=1 spf=pass spfdomain=redhat.com dkim=pass dkdomain=redhat.com dmarc=pass fromdomain=redhat.com); spf=pass (google.com: domain of linux-kernel+bounces-200851-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-200851-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 572261C20B1E for ; Tue, 4 Jun 2024 14:40:16 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 95EF413D27F; Tue, 4 Jun 2024 14:37:42 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="R+hWca0I" Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 314AC1494A1 for ; Tue, 4 Jun 2024 14:37:40 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717511861; cv=none; b=eV/pqr2tfuJsB3RWlQPycbRE5kVe0DAkV+H0eS+UY6DcxBX849lQqgAGzWnjVDTmj9eZrTaa56u36tsawOmMVnbkl/rAzzVdsbP7yScr4jA/3kkb0OBSAOtMXF7+yphtRWui5O4zwdNWb4mZuRASq0vUA+LWtGnMG2lLkU6dUaU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717511861; c=relaxed/simple; bh=GSe0K72YrdDKsD9ccEAxSP2G9RITqEcmzRd91s6iNuY=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iRdqijo+HizTpkRFx0ID3RFBiE6dtMX8uktr49UXSc6E1RQqnw5dFOP2lV3uEsbZFGd1i2VTPe1RYP/ifywofZQ7304rNhyFeIsPM+L4lz/bp5rnrIrjeqawiaA0R219hKAAG3c2fIqY8l/ClHVZHlELmvdviHeJb7QN6my+5VU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=R+hWca0I; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1717511859; 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=WH8AS3lVorPueuVFarM2V4L81baIisvkBg5pdJlXfEI=; b=R+hWca0IJDg6a8uT0Nrk+wMnv8K9cXJyIqzNa6QxPgWZ3R4qn9YReIrgIQahEJ3zAWqOEg mnvMsBPTL51NeyYFyFrfCInN5pxPHxHa6+Y3kGghDtdqjWKBkeWcDIXpXeS8502wF76ssX /wcogWnCj0vHKi3SSY1Tc297Mg8j1HQ= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-125-DCICH841MYyBgLkbsaYwQQ-1; Tue, 04 Jun 2024 10:37:33 -0400 X-MC-Unique: DCICH841MYyBgLkbsaYwQQ-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (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 mimecast-mx02.redhat.com (Postfix) with ESMTPS id A8963101A521; Tue, 4 Jun 2024 14:37:32 +0000 (UTC) Received: from redhat.com (unknown [10.22.32.74]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 440661C1CEAB; Tue, 4 Jun 2024 14:37:32 +0000 (UTC) Date: Tue, 4 Jun 2024 10:37:30 -0400 From: Joe Lawrence To: zhang warden Cc: Miroslav Benes , Josh Poimboeuf , Jiri Kosina , Petr Mladek , live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH] livepatch: introduce klp_func called interface Message-ID: References: <20240520005826.17281-1-zhangwarden@gmail.com> <4DE98E35-2D1F-4A4E-8689-35FD246606EF@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4DE98E35-2D1F-4A4E-8689-35FD246606EF@gmail.com> X-Scanned-By: MIMEDefang 3.4.1 on 10.11.54.7 On Tue, Jun 04, 2024 at 04:14:51PM +0800, zhang warden wrote: > > > > On Jun 1, 2024, at 03:16, Joe Lawrence wrote: > > > > Adding these attributes to livepatch sysfs would be expedient and > > probably easier for us to use, but imposes a recurring burden on us to > > maintain and test (where is the documentation and kselftest for this new > > interface?). Or, we could let the other tools handle all of that for > > us. > How this attribute imposes a recurring burden to maintain and test? > Perhaps "responsibility" is a better description. This would introduce an attribute that someone's userspace utility is relying on. It should at least have a kselftest to ensure a random patch in 2027 doesn't break it. > > Perhaps if someone already has an off-the-shelf script that is using > > ftrace to monitor livepatched code, it could be donated to > > Documentation/livepatch/? I can ask our QE folks if they have something > > like this. > > My intention to introduce this attitude to sysfs is that user who what to see if this function is called can just need to show this function attribute in the livepatch sysfs interface. > > User who have no experience of using ftrace will have problems to get the calling state of the patched function. After all, ftrace is a professional kernel tracing tools. > > Adding this attribute will be more easier for us to show if this patched function is called. Actually, I have never try to use ftrace to trace a patched function. Is it OK of using ftrace for a livepatched function? > If you build with CONFIG_SAMPLE_LIVEPATCH=m, you can try it out (or with one of your own livepatches): # Convenience variable $ SYSFS=/sys/kernel/debug/tracing # Install the livepatch sample demo module $ insmod samples/livepatch/livepatch-sample.ko # Verify that ftrace can filter on our functions $ grep cmdline_proc_show $SYSFS/available_filter_functions cmdline_proc_show livepatch_cmdline_proc_show [livepatch_sample] # Turn off any existing tracing and filter functions $ echo 0 > $SYSFS/tracing_on $ echo > $SYSFS/set_ftrace_filter # Set up the function tracer and add the kernel's cmdline_proc_show() # and livepatch-sample's livepatch_cmdline_proc_show() $ echo function > $SYSFS/current_tracer $ echo cmdline_proc_show >> $SYSFS/set_ftrace_filter $ echo livepatch_cmdline_proc_show >> $SYSFS/set_ftrace_filter $ cat $SYSFS/set_ftrace_filter cmdline_proc_show livepatch_cmdline_proc_show [livepatch_sample] # Turn on the ftracing and force execution of the original and # livepatched functions $ echo 1 > $SYSFS/tracing_on $ cat /proc/cmdline this has been live patched # Checkout out the trace file results $ cat $SYSFS/trace # tracer: function # # entries-in-buffer/entries-written: 2/2 #P:8 # # _-----=> irqs-off/BH-disabled # / _----=> need-resched # | / _---=> hardirq/softirq # || / _--=> preempt-depth # ||| / _-=> migrate-disable # |||| / delay # TASK-PID CPU# ||||| TIMESTAMP FUNCTION # | | | ||||| | | cat-254 [002] ...2. 363.043498: cmdline_proc_show <-seq_read_iter cat-254 [002] ...1. 363.043501: livepatch_cmdline_proc_show <-seq_read_iter The kernel docs provide a lot of explanation of the complete ftracing interface. It's pretty power stuff, though you may also go the other direction and look into using the trace-cmd front end to simplify all of the sysfs manipulation. Julia Evans wrote a blog [1] a while back that provides a some more examples. [1] https://jvns.ca/blog/2017/03/19/getting-started-with-ftrace/ -- Joe