[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH 1/3] xen/pv: allow pmu msr accesses to cause GP


  • To: Juergen Gross <jgross@xxxxxxxx>
  • From: Jan Beulich <jbeulich@xxxxxxxx>
  • Date: Mon, 26 Sep 2022 17:29:32 +0200
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=suse.com; dmarc=pass action=none header.from=suse.com; dkim=pass header.d=suse.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9HY0O8rOWHJgE2ypf8yinz4Uk0wsWLwEPUUlPrIlZH4=; b=COUzUNS4rLD1+8MSy5iC3R7tSAR2VDbrAWJWEHlVxM60uHyz7gR7IFXRLhilphVIlpvb2xl7SgFWoZuyVbJa2pEEiTT129xp54jy+7H4xYkxyNt0UR6GufFfgy8HFrE9/6IRAPGehIl7AZmibKlkK2W/wR9+foRVREXUXGcn/DvowT+2EXm/iarxubGB/ebW7QOLVbGdTcpquXtBsgTBLfzBb/1V2rlhCRjjk4wIHCWoNBSVDIammcveSG+ValpGCyKOmUbCMynyQ7YRiCx5FWlDwbhE5Ulj5xDa1MO4crog8jyJ56kPCxAqbowEweoCHcyyeKJnsZpZzNvHr+RZtA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jx40fp2TjTvmwnsQfkkBSJnHWYCX2fA/LVM2UvbKY+HNwbuMF3zQTv5bjpo0iSO0rUJcdce5Okw6CsDwCWAERPcGqk1ZB2M/NeLyTnc8Y/C1fKN4m9F7a1WUQHhHuuVw3oa/6a/3Yjc9/6JDn7uAM7jjbXHubP9UcbTj8Tjs4kBhjeayOqB2U2FcPKYlWKlG8dUYGWT7LtghLRg6GsUMkz2ELHFeEs7JiFyr2mSbN9J561yBol0qXRM910e5QXK2Kh3tFw2fv0b9j49afMK/DMf1xBRAOaL0dh1RCqEovU1d+8teJUuk8LgybuO5zT3AErFfQKiXtSIMqANZgrhJsA==
  • Authentication-results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=suse.com;
  • Cc: Boris Ostrovsky <boris.ostrovsky@xxxxxxxxxx>, Thomas Gleixner <tglx@xxxxxxxxxxxxx>, Ingo Molnar <mingo@xxxxxxxxxx>, Borislav Petkov <bp@xxxxxxxxx>, Dave Hansen <dave.hansen@xxxxxxxxxxxxxxx>, "H. Peter Anvin" <hpa@xxxxxxxxx>, xen-devel@xxxxxxxxxxxxxxxxxxxx, x86@xxxxxxxxxx, linux-kernel@xxxxxxxxxxxxxxx
  • Delivery-date: Mon, 26 Sep 2022 15:29:42 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>

On 26.09.2022 16:18, Juergen Gross wrote:
> Today pmu_msr_read() and pmu_msr_write() fall back to the safe variants
> of read/write MSR in case the MSR access isn't emulated via Xen. Allow
> the caller to select the potentially faulting variant by passing NULL
> for the error pointer.

Maybe make this "the sole caller" or some such? Because if there were
multiple, they might easily disagree on what the best meaning of passing
NULL is.

> --- a/arch/x86/xen/pmu.c
> +++ b/arch/x86/xen/pmu.c
> @@ -293,22 +293,24 @@ static bool xen_amd_pmu_emulate(unsigned int msr, u64 
> *val, bool is_read)
>  bool pmu_msr_read(unsigned int msr, uint64_t *val, int *err)
>  {
>       if (boot_cpu_data.x86_vendor != X86_VENDOR_INTEL) {
> -             if (is_amd_pmu_msr(msr)) {
> -                     if (!xen_amd_pmu_emulate(msr, val, 1))
> -                             *val = native_read_msr_safe(msr, err);
> -                     return true;
> +             if (!is_amd_pmu_msr(msr))
> +                     return false;
> +             if (!xen_amd_pmu_emulate(msr, val, 1)) {
> +                     *val = err ? native_read_msr_safe(msr, err)
> +                                : native_read_msr(msr);
>               }
> +             return true;

Minor remark: Fold this and ...

>       } else {
>               int type, index;
>  
> -             if (is_intel_pmu_msr(msr, &type, &index)) {
> -                     if (!xen_intel_pmu_emulate(msr, val, type, index, 1))
> -                             *val = native_read_msr_safe(msr, err);
> -                     return true;
> +             if (!is_intel_pmu_msr(msr, &type, &index))
> +                     return false;
> +             if (!xen_intel_pmu_emulate(msr, val, type, index, 1)) {
> +                     *val = err ? native_read_msr_safe(msr, err)
> +                                : native_read_msr(msr);
>               }
> +             return true;

... this by moving them ...

>       }
> -
> -     return false;
>  }

... above here? You might even de-duplicate the native_read_msr{,_safe}()
invocations by moving them out of the if/else ...

Jan



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.