From mboxrd@z Thu Jan 1 00:00:00 1970 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 C637824A7E8 for ; Wed, 15 Jan 2025 15:03:21 +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=1736953403; cv=none; b=UEbd9i1Em4hBv7XMTDAJDwxmLqL918hodjzomlbAhxrhhHprWYK1eNhivtkenJI04kQJUFq7cAiSDfiLXjJ+RmFZQUmSFfRM84xPsCPTRY0Zt9P0cZjc7fz7mHCV6lA5AndS6WC1AL2X0f+T1TmVGq7ndiX1YV3izocJToslIps= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736953403; c=relaxed/simple; bh=/KhDQXFdx1HNLxOFKGUlHSJs6ggG4sn8IIiQrBLO5bI=; h=Message-ID:Date:MIME-Version:To:Cc:References:From:Subject: In-Reply-To:Content-Type; b=up280q6E9FPZxZdTHqpBB3GU00PQtjCoT1ALy9JLkN6/URbxdARwufx6OOXAvnXmkkW9AH0zCjXxWCbhlwAxy6h4I/Rwszsl9gf4amLIt2qgFIuaqOOOV83AiueeFU5S62cfeSdwQm2YJdepJe4pcI+9UGTRoc1H/IagMYr3oEo= 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=bcn5udG+; 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="bcn5udG+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1736953400; 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: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=0abEoGkyoE1QdfpXorZ/cAQ2SjeYoeosF/RXyM4oSu8=; b=bcn5udG+ycvjqPXCJ9N0Td2+iAnfCGdFd8cKCf4yu++DbRzmBtllH1yeM6lS43j72Obqa6 /Uo7Tzw7THVywu5lDth02TnTJ5R4bqkQDnMqgGUYQ/+UaVOKeB2lTrWC9DMsF1Ae4rs8ko xAgnTPeE1PL+MR22iLjfXA55vq4Wcz4= Received: from mail-qk1-f197.google.com (mail-qk1-f197.google.com [209.85.222.197]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-553-0TIUguN9Pj6OvS6qiA8T9w-1; Wed, 15 Jan 2025 10:03:19 -0500 X-MC-Unique: 0TIUguN9Pj6OvS6qiA8T9w-1 X-Mimecast-MFC-AGG-ID: 0TIUguN9Pj6OvS6qiA8T9w Received: by mail-qk1-f197.google.com with SMTP id af79cd13be357-7b6e5c9ef38so173317685a.1 for ; Wed, 15 Jan 2025 07:03:19 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736953399; x=1737558199; h=content-transfer-encoding:in-reply-to:subject:from:references:cc:to :content-language:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=0abEoGkyoE1QdfpXorZ/cAQ2SjeYoeosF/RXyM4oSu8=; b=eldO1klYKNdHVbga5ocbwLvUjJmMacMhStHRZd/gPktvZRNgq+KNsFGmyt592RIXBD oyVqUzDWq23m4Bz5cfI2XEHPdUxlScOn18rYmnpwdYCIUIbuWEYw+Yy0XMGelCUhKG3H DKKaGQcqn1AdzX/5Of/MQTsV7cSi1tUYjGl6BYKi2GSm0rz0z0K0CMsiG2JnFVJjFRJT +yN7CaU82/sph9sz4BTH6u3355SfAYJ9XJqpsrhfGUBB8PP6CY/8aKo4HNpByfl31jhx N3Gh3DQFaYpYp3PFN67r4wxCGrVPuoto+yFvijkJp30SwxP7GPp8DpUHy7HDvrkJU9JE buSg== X-Forwarded-Encrypted: i=1; AJvYcCXIhXL5kMPEFibLVCbQB6EpPmS9a4TiPZUTpVwxE6iS3bziFWPoFAtTJav/PMaRk8CapVbPxnHcsp5TH2g=@vger.kernel.org X-Gm-Message-State: AOJu0Yx7N8dA5UUUlw9ySjIJMCRvvFeihqJ50gfVTZoxDI2VLY+3MfSj 37l7N9R51l0fJSMxBBnIfAnu+fgHWOBM0VOPQF+MySdjK1tCQiVZMqfeFP2IWY6mDfBZMqdTVX1 vxgvBdp6e+KMS7BDSu8ymJY7/HRd2Ox1En0iYRfkT6s2xaq5BCViX0mt17k0aDA== X-Gm-Gg: ASbGncvn3ENIzMqEQWa2Sw++i1g45KJNHWKlNLouNLmy4nQnNnojQKEuct1RgirhHt/ /HZPFoqYkiXbLV7j7L/FH2CSR37EHz2USVYg1VOngPwxCinDU3r9trno2/WT12U3OdfWlKKEUnm sQJbC+/A8kjyMQ4E+Udj4O2Mk2xT95m2NzaqsxyvW+a0TxiV0mPiyVTExlGBXBA7jQpokDmKNWa Ty3R4zEweH4PUA88r8BdgNfh6qNPAVQN09NvXrL+RkGpu+ayAHCQzV6hCurfvyFt2aCcSu+fwlJ 1s15MXwyEybQCJUGptgqqj3t+ixnKivKtoZrwI4= X-Received: by 2002:a05:620a:4513:b0:7b1:4a2a:9ae0 with SMTP id af79cd13be357-7be523dac64mr554727585a.9.1736953398952; Wed, 15 Jan 2025 07:03:18 -0800 (PST) X-Google-Smtp-Source: AGHT+IEqThpU+a/wawXkrQbgAp6/dywjE1IdqD+XX/1OB0uRU6P5pD+Nm1/7o/u7tCUjar01Xr4xug== X-Received: by 2002:a05:620a:4513:b0:7b1:4a2a:9ae0 with SMTP id af79cd13be357-7be523dac64mr554718685a.9.1736953398353; Wed, 15 Jan 2025 07:03:18 -0800 (PST) Received: from [192.168.1.45] (pool-68-160-135-240.bstnma.fios.verizon.net. [68.160.135.240]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6dfad85fe81sm65591506d6.6.2025.01.15.07.03.16 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 15 Jan 2025 07:03:17 -0800 (PST) Message-ID: Date: Wed, 15 Jan 2025 10:03:15 -0500 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.15.1 Content-Language: en-US To: Marcos Paulo de Souza , Filipe Xavier , Josh Poimboeuf , Jiri Kosina , Miroslav Benes , Petr Mladek , Shuah Khan Cc: live-patching@vger.kernel.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, Felipe Xavier References: <20250111-ftrace-selftest-livepatch-v2-1-9f4ff90f251a@gmail.com> <12c6681e2d13994c2efd5d25372293b9f53a9f8a.camel@suse.com> From: Joe Lawrence Subject: Re: [PATCH v2] selftests: livepatch: test if ftrace can trace a livepatched function In-Reply-To: <12c6681e2d13994c2efd5d25372293b9f53a9f8a.camel@suse.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 1/14/25 12:18, Marcos Paulo de Souza wrote: > On Sat, 2025-01-11 at 15:42 -0300, Filipe Xavier wrote: >> This new test makes sure that ftrace can trace a >> function that was introduced by a livepatch. >> >> Signed-off-by: Filipe Xavier > > Thanks for the new test Filipe! > > I have some nits below, but these don't need to be addressed for the > test to be merged. Either way, > > Reviewed-by: Marcos Paulo de Souza > Tested-by: Marcos Paulo de Souza > > > >> --- >> Changes in v2: >> - functions.sh: added reset tracing on push and pop_config. >> - test-ftrace.sh: enabled tracing_on before test init. >> - nitpick: added double quotations on filenames and fixed some >> wording. >> - Link to v1: >> https://lore.kernel.org/r/20250102-ftrace-selftest-livepatch-v1-1-84880baefc1b@gmail.com >> --- >>  tools/testing/selftests/livepatch/functions.sh   | 14 ++++++++++ >>  tools/testing/selftests/livepatch/test-ftrace.sh | 33 >> ++++++++++++++++++++++++ >>  2 files changed, 47 insertions(+) >> >> diff --git a/tools/testing/selftests/livepatch/functions.sh >> b/tools/testing/selftests/livepatch/functions.sh >> index >> e5d06fb402335d85959bafe099087effc6ddce12..e6c13514002dae5f8d7461f90b8 >> 241ab43024ea4 100644 >> --- a/tools/testing/selftests/livepatch/functions.sh >> +++ b/tools/testing/selftests/livepatch/functions.sh >> @@ -62,6 +62,9 @@ function push_config() { >>   awk -F'[: ]' '{print "file " $1 " line " $2 >> " " $4}') >>   FTRACE_ENABLED=$(sysctl --values kernel.ftrace_enabled) >>   KPROBE_ENABLED=$(cat "$SYSFS_KPROBES_DIR/enabled") >> + TRACING_ON=$(cat "$SYSFS_DEBUG_DIR/tracing/tracing_on") >> + CURRENT_TRACER=$(cat >> "$SYSFS_DEBUG_DIR/tracing/current_tracer") >> + FTRACE_FILTER=$(cat >> "$SYSFS_DEBUG_DIR/tracing/set_ftrace_filter") >>  } >>   >>  function pop_config() { >> @@ -74,6 +77,17 @@ function pop_config() { >>   if [[ -n "$KPROBE_ENABLED" ]]; then >>   echo "$KPROBE_ENABLED" > >> "$SYSFS_KPROBES_DIR/enabled" >>   fi >> + if [[ -n "$TRACING_ON" ]]; then >> + echo "$TRACING_ON" > >> "$SYSFS_DEBUG_DIR/tracing/tracing_on" >> + fi >> + if [[ -n "$CURRENT_TRACER" ]]; then >> + echo "$CURRENT_TRACER" > >> "$SYSFS_DEBUG_DIR/tracing/current_tracer" >> + fi >> + if [[ "$FTRACE_FILTER" == *"#"* ]]; then >> + echo > "$SYSFS_DEBUG_DIR/tracing/set_ftrace_filter" >> + elif [[ -n "$FTRACE_FILTER" ]]; then >> + echo "$FTRACE_FILTER" > >> "$SYSFS_DEBUG_DIR/tracing/set_ftrace_filter" >> + fi >>  } > > I believe that this could be a separate patch, since this is new > functionality that's being added to functions.sh, and not exactly > related to the new test. > >>   >>  function set_dynamic_debug() { >> diff --git a/tools/testing/selftests/livepatch/test-ftrace.sh >> b/tools/testing/selftests/livepatch/test-ftrace.sh >> index >> fe14f248913acbec46fb6c0fec38a2fc84209d39..66af5d726c52e48e5177804e182 >> b4ff31784d5ac 100755 >> --- a/tools/testing/selftests/livepatch/test-ftrace.sh >> +++ b/tools/testing/selftests/livepatch/test-ftrace.sh >> @@ -61,4 +61,37 @@ livepatch: '$MOD_LIVEPATCH': unpatching complete >>  % rmmod $MOD_LIVEPATCH" >>   >>   >> +# - verify livepatch can load >> +# - check if traces have a patched function >> +# - unload livepatch and reset trace >> + >> +start_test "trace livepatched function and check that the live patch >> remains in effect" >> + >> +TRACE_FILE="$SYSFS_DEBUG_DIR/tracing/trace" >> +FUNCTION_NAME="livepatch_cmdline_proc_show" >> + >> +load_lp $MOD_LIVEPATCH >> + >> +echo 1 > "$SYSFS_DEBUG_DIR/tracing/tracing_on" >> +echo $FUNCTION_NAME > "$SYSFS_DEBUG_DIR/tracing/set_ftrace_filter" >> +echo "function" > "$SYSFS_DEBUG_DIR/tracing/current_tracer" >> +echo "" > "$TRACE_FILE" >> + >> +if [[ "$(cat /proc/cmdline)" != "$MOD_LIVEPATCH: this has been live >> patched" ]] ; then >> + echo -e "FAIL\n\n" >> + die "livepatch kselftest(s) failed" >> +fi >> + >> +grep -q $FUNCTION_NAME "$TRACE_FILE" >> +FOUND=$? >> + >> +disable_lp $MOD_LIVEPATCH >> +unload_lp $MOD_LIVEPATCH >> + >> +if [ "$FOUND" -eq 1 ]; then >> + echo -e "FAIL\n\n" >> + die "livepatch kselftest(s) failed" >> +fi >> + >> + >>  exit 0 > > The test works, and that's very cool. But when running locally, I find > the if we miss check_result call it doesn't add a newline after the > "ok": > > ... > # timeout set to 0 > # selftests: livepatch: test-ftrace.sh > # TEST: livepatch interaction with ftrace_enabled sysctl ... ok > # TEST: trace livepatched function and check that the live patch > remains in effect ... ok 5 selftests: livepatch: test-ftrace.sh > # timeout set to 0 > # selftests: livepatch: test-sysfs.sh > ... > > If the check_result below is added the output if sane again: > > ... > # selftests: livepatch: test-ftrace.sh > # TEST: livepatch interaction with ftrace_enabled sysctl ... ok > # TEST: trace livepatched function and check that the live patch > remains in effect ... ok > ok 5 selftests: livepatch: test-ftrace.sh > ... > > I checked and this would be the only one test without using > check_result, so maybe we should add this either way? I'm not sure what > you guys think about it. > > > diff --git a/tools/testing/selftests/livepatch/test-ftrace.sh > b/tools/testing/selftests/livepatch/test-ftrace.sh > index 66af5d726c52..135c0fb17a98 100755 > --- a/tools/testing/selftests/livepatch/test-ftrace.sh > +++ b/tools/testing/selftests/livepatch/test-ftrace.sh > @@ -93,5 +93,18 @@ if [ "$FOUND" -eq 1 ]; then > die "livepatch kselftest(s) failed" > fi > > +check_result "% insmod test_modules/$MOD_LIVEPATCH.ko > +livepatch: enabling patch '$MOD_LIVEPATCH' > +livepatch: '$MOD_LIVEPATCH': initializing patching transition > +livepatch: '$MOD_LIVEPATCH': starting patching transition > +livepatch: '$MOD_LIVEPATCH': completing patching transition > +livepatch: '$MOD_LIVEPATCH': patching complete > +% echo 0 > $SYSFS_KLP_DIR/$MOD_LIVEPATCH/enabled > +livepatch: '$MOD_LIVEPATCH': initializing unpatching transition > +livepatch: '$MOD_LIVEPATCH': starting unpatching transition > +livepatch: '$MOD_LIVEPATCH': completing unpatching transition > +livepatch: '$MOD_LIVEPATCH': unpatching complete > +% rmmod $MOD_LIVEPATCH" > + > Ah good catch, I noticed the newline, too, but didn't notice that the test wasn't using check_result(). For consistency, let's make that change before merging. Thanks, -- Joe