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.133.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 9F2A7342515 for ; Thu, 30 Jul 2026 05:13:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785388410; cv=none; b=tmgM6ZU1T20AACV0M7b4U8/YHh52N4bzJjmd8vDpUtgjS5J9DNScJ/g73y+FL4mQDxL03HyPmQjt9klwyc1SNc05+lcZX71SMKC8tfmn4bY5fzc7Y0DB0rFTg8IIsLzcTyULhsYOAcy4Vp1c3SCh2xfpkP6+EQky0HpLOtiXoiA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785388410; c=relaxed/simple; bh=yWMfdWYDuY1FfFHsBcmB2dJ9pOmugvJwpi+yHE7RbCs=; h=Date:From:To:CC:Subject:In-Reply-To:References:Message-ID: MIME-Version:Content-Type; b=AIMMJMBoVIZv8NVLkIPuhlDy2+54RA+XGI2NNzDLsTbXEzurSCKFKouMaqVHpRrCrRUNN/qkKlBcUuYKcHAtrxPnOWMqyMwQ8rHoLdTcvIAiUn+S6ILTPf2nRKDxZIUEBU4BWA5BWFu4/io9nckoGAKo70tiBhIxWDoAH/9Iu8Y= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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=c9zYGw1q; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b=qudxWmkZ; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine 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="c9zYGw1q"; dkim=pass (2048-bit key) header.d=redhat.com header.i=@redhat.com header.b="qudxWmkZ" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1785388407; 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=BOEicW8D/gztHqaGk9GvfiS29jnoogsbqOZZnCb/DS0=; b=c9zYGw1q8IS6kAjMEx65chdHRAIrx+S85w8dq6AwOj5FaACWhtAsEV9dzqjE53Op3LmbZ3 bKOyvcg8mk1v4aIxjobrIwrTuKHlLy0BW8oFBVeuK87+AjG4MLCce9x8Yf64qz8JVnd9PR PxYyVxHBdp4iSlAKZV2TUJVNbVsovyE= Received: from mail-wm1-f69.google.com (mail-wm1-f69.google.com [209.85.128.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-646-vAczCNVzP4yWj0eWq3nggw-1; Thu, 30 Jul 2026 01:13:26 -0400 X-MC-Unique: vAczCNVzP4yWj0eWq3nggw-1 X-Mimecast-MFC-AGG-ID: vAczCNVzP4yWj0eWq3nggw_1785388405 Received: by mail-wm1-f69.google.com with SMTP id 5b1f17b1804b1-4955843c6cdso18014285e9.1 for ; Wed, 29 Jul 2026 22:13:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=google; t=1785388405; x=1785993205; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:message-id :references:in-reply-to:subject:cc:to:from:date:from:to:cc:subject :date:message-id:reply-to:content-type; bh=BOEicW8D/gztHqaGk9GvfiS29jnoogsbqOZZnCb/DS0=; b=qudxWmkZfzCx5SegXn28kQnJPb58VeDZJNvRaSyqmfXbDikpfDi8qlqQ9/WW8IWu3r EWDjRlpf0R7YgEa0seOYWohe2UXoWIDXjnZvsoH5bNEnHw2dZWJ9ymZ8VcK3lPlIqAcM Y36gYBCz1YU2UWMtQiTdJVBlB47L02SCn/jvWQ/YZ0lkUL3DNcAWQJyEcH1+Aj3fS1cr NqWQtUAb7ZP3Q3m6j9c99InqoPU8tGhp6TOowLA1RU6quT4Mjm0RsDKhWYT9Pb3P+jT/ KkmRJb7tfpk+s9exTS4FH/9HB10I7gHCHLatNuq5BXch2Eh9TyDzoi3Q18jTKu6s9j0v R41g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785388405; x=1785993205; h=content-transfer-encoding:content-type:mime-version:message-id :references:in-reply-to:subject:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=BOEicW8D/gztHqaGk9GvfiS29jnoogsbqOZZnCb/DS0=; b=E4qqmsfu23v099TisAL3PmO9Ff7jKcfA4TcaabC1SDoqfGQAm6IkXIpSa72yRcwqRa evaFpY7rE7tQ4uA88R95Rd+usHNxW5pPLMm0ZYgrl1eNrDNN/JrZ4BwxNbvKGxLRQayA VJBaBN/DN3cn+EX3Snb43Ziqy3J2sRJwHp9KPRLaVNnVjFSZMe+rJh/5Xh/kqHMavDDE /yWZ2eK3il/C5bPshA6+4AQNEnW0owGABocyeSbTz+lUHvcXCZ3TLoV0+ntHpg3umeBG b2FVij3zi0z8VJ1nffOSC4sqMXbh7NGZms+Uu+rv9aUwZedJi2/WsVGkWg6kDd3wEV7H W9Yw== X-Forwarded-Encrypted: i=1; AHgh+RoIVVw2YbzDg1FLZ3wDDG3C4q4yGmZICmaUJGYreUEhGVTeuLVJ4eqgBO7n3JLFEH4ghSuaJ+vCIPlg/aw=@vger.kernel.org X-Gm-Message-State: AOJu0Yy2qzTpO7OKZtGm2GTMSLTf0QA4Ilrot12iVgKB5V29YJwiF8+0 FPx/9DUYYax2niVQfxspNqAdtcMFAvElrbR+/+4Wv0bWTctp+UcgzulGWoWkkjjeqsdPiFfWIch lChK2j8/Fmdso8lSkUGt1QVr+K85CNqeV4eaOaSrA+hUtmb0ewYgNkkEEa/F6MFFeaA== X-Gm-Gg: AR+sD13AZ4R0ErY4JrbqoOFoJUSJfvTK1dGv6GakIyEnjR82qH7c2Uyme8dTtR+/L0k MySvsknSm4KaGsR7Zo91QV32UYJjO9ObisC4Ttx0/YbVH7qi09+RpJ30JnzSLWYvtjSck4F46Lf h2R0qzNs7DYhtxn0Ul9PFQU4YnkmlMDIjkJ0IZ3hpNdB6L2LuebzBrdzNwmtpBnctDbZK3GjWRf 7nmFYSnddzWZgNc5JGBEm6Ja53k/1lAQxmaaCMhKBGHJTkNZZ5m+/7wi8hp7xBvjisPxdpPWZ25 XPS2tjXPJA5HzxHeS4wHng4OgpTNWCRlbpMnx/2NEd2gUG7JtBdG7+ugTm2b2UrGgSzWEZ1eQKh zvq8hfWg2 X-Received: by 2002:a05:600c:4693:b0:496:ca1f:a428 with SMTP id 5b1f17b1804b1-49800ea1ab2mr12602595e9.19.1785388404814; Wed, 29 Jul 2026 22:13:24 -0700 (PDT) X-Received: by 2002:a05:600c:4693:b0:496:ca1f:a428 with SMTP id 5b1f17b1804b1-49800ea1ab2mr12602305e9.19.1785388404297; Wed, 29 Jul 2026 22:13:24 -0700 (PDT) Received: from ehlo.thunderbird.net ([185.168.96.228]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-498011fec37sm27120065e9.9.2026.07.29.22.13.23 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 29 Jul 2026 22:13:23 -0700 (PDT) Date: Thu, 30 Jul 2026 05:13:22 +0000 From: Gabriele Monaco To: Wen Yang , linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org, Steven Rostedt , Masami Hiramatsu CC: Nam Cao , Thomas Weissschuh , Tomas Glozar , John Kacur Subject: Re: [PATCH v5 13/17] rv: Add KUnit mock for current In-Reply-To: <38a2480b-b420-4b14-9793-5ab3d7cfb2b9@linux.dev> References: <20260723074534.43521-1-gmonaco@redhat.com> <20260723074534.43521-14-gmonaco@redhat.com> <38a2480b-b420-4b14-9793-5ab3d7cfb2b9@linux.dev> Message-ID: <0CC2C4B0-6E6A-4199-A7FA-EEDEB28866B6@redhat.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=utf-8 Content-Transfer-Encoding: quoted-printable Il 29 luglio 2026 18:17:31 UTC, Wen Yang ha scrit= to: >> +#define rv_get_current() (unlikely(kunit_get_current_test()) ? rv_get_= mock_current() : current) =20 =2E=2E=2E >> +/* >> + * rv_get_mock_current() is called only if we are running from a KUnit= test=2E >> + * This can occur from a legitimate RV test or any unrelated test runn= ing when >> + * a real RV monitor is active and triggering events=2E >> + * We assume the former case is the only one where mock_current is not= NULL and >> + * can occur only sequentially (KUnit doesn't run tests in parallel)= =2E >> + * We cannot rely on the test's context because there is no way to saf= ely >> + * understand from which test we are running and KUnit utilities requi= re >> + * locking, which is unsafe from NMI or scheduling context=2E >> + * Note that it is not possible for a real RV monitor to run when the = RV KUnit >> + * tests are running (see rv_set_testing())=2E >> + */ >> +static struct task_struct *mock_current; >> + >> +void rv_mock_current(struct task_struct *tsk) >> +{ >> + mock_current =3D tsk; >> +} >> +EXPORT_SYMBOL_IF_KUNIT(rv_mock_current); >> + >> +struct task_struct *rv_get_mock_current(void) >> +{ >> + return mock_current ?: current; >> +} >> +EXPORT_SYMBOL_GPL(rv_get_mock_current); >> #endif > >rv_mock_current() uses EXPORT_SYMBOL_IF_KUNIT, but rv_get_mock_current() = uses EXPORT_SYMBOL_GPL=2E Both are defined inside the same CONFIG_RV_MONITO= RS_KUNIT_TEST block, so rv_get_mock_current should use EXPORT_SYMBOL_IF_KUN= IT as well, otherwise it leaks a test-only symbol into production builds=2E > >With that fixed: >Reviewed-by: Wen Yang Thanks for the review=2E This was intentional however: rv_get_current() can be called by any monito= r, those don't have to be KUnit=2E Since rv_get_current() is a macro also calling rv_get_mock_current() we ne= ed to be able to link that too=2E The idea is that a "real" (non-kunit) monitor handler could be run when in= terrupting a KUnit test (not an RV one, we make sure of that)=2E In that ca= se we do call rv_get_mock_current() and return current after the function c= all=2E rv_mock_current() CANNOT be called outside of the RV KUnit test cases, it = uses a global variable (for problems I tried to explain in the comment), so= should be exported only to KUnit and called directly from the test case=2E Does it make sense to you? Thanks, Gabriele