lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Y1/Gvs0xkk/W0Nro@hirez.programming.kicks-ass.net>
Date:   Mon, 31 Oct 2022 13:59:42 +0100
From:   Peter Zijlstra <peterz@...radead.org>
To:     Liang Yan <lyan@...italocean.com>,
        Ravi Bangoria <ravi.bangoria@....com>
Cc:     Ingo Molnar <mingo@...hat.com>,
        Arnaldo Carvalho de Melo <acme@...nel.org>,
        Mark Rutland <mark.rutland@....com>,
        Alexander Shishkin <alexander.shishkin@...ux.intel.com>,
        Jiri Olsa <jolsa@...nel.org>,
        Namhyung Kim <namhyung@...nel.org>,
        Thomas Gleixner <tglx@...utronix.de>,
        Borislav Petkov <bp@...en8.de>,
        Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
        "H. Peter Anvin" <hpa@...or.com>, linux-perf-users@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] arch/x86/events/amd/core.c: Return -ENODEV when CPU does
 not have PERFCTL_CORE bit

On Thu, Oct 27, 2022 at 09:35:11AM -0400, Liang Yan wrote:
> After disabling cpu.perfctr_core in qemu, I noticed that the guest kernel
> still loads the pmu driver while the cpuid does not have perfctl_core.
> 
> The test is running on an EPYC Rome machine.
> root@...ntu-s-4vcpu-8gb-amd-nyc1-01:~# lscpu | grep perfctl
> root@...ntu-s-4vcpu-8gb-amd-nyc1-01:~#
> root@...ntu-s-4vcpu-8gb-amd-nyc1-01:~# dmesg | grep PMU
> [    0.732097] Performance Events: AMD PMU driver.
> 
> By further looking,
> 
> ==> init_hw_perf_events
>     ==> amd_pmu_init
>         ==> amd_core_pmu_init
>             ==>
>                 if (!boot_cpu_has(X86_FEATURE_PERFCTR_CORE))
> 			return 0;
> 
> With returning 0, it will bypass amd_pmu_init and return 0 to
> init_hw_perf_events, and continue the initialization.
> 
> I am not a perf expert and not sure if it is expected for AMD PMU,
> otherwise, it would be nice to return -ENODEV instead.
> 
> New output after the change:
> root@...ntu-s-4vcpu-8gb-amd-nyc1-01:~# dmesg | grep PMU
> [    0.531609] Performance Events: no PMU driver, software events only.
> 
> Signed-off-by: Liang Yan <lyan@...talocean.com>

Looks about right, Ravi?

> ---
>  arch/x86/events/amd/core.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/arch/x86/events/amd/core.c b/arch/x86/events/amd/core.c
> index 8b70237c33f7..34d3d2944020 100644
> --- a/arch/x86/events/amd/core.c
> +++ b/arch/x86/events/amd/core.c
> @@ -1335,7 +1335,7 @@ static int __init amd_core_pmu_init(void)
>  	int i;
>  
>  	if (!boot_cpu_has(X86_FEATURE_PERFCTR_CORE))
> -		return 0;
> +		return -ENODEV;
>  
>  	/* Avoid calculating the value each time in the NMI handler */
>  	perf_nmi_window = msecs_to_jiffies(100);
> -- 
> 2.34.1
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ