Received: by 2002:a05:6a10:8a4d:0:0:0:0 with SMTP id dn13csp876763pxb; Fri, 13 Aug 2021 08:14:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwvqJBTZEK8VXtMbENu95GdLyq87P56ONHutlGkF0BoD3GBZGvB9LcUSVgQRpvYN/its3TA X-Received: by 2002:a17:906:9241:: with SMTP id c1mr2928914ejx.125.1628867694323; Fri, 13 Aug 2021 08:14:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1628867694; cv=none; d=google.com; s=arc-20160816; b=nPZentNGvEoAAl1sais+lb4EHSvcG5un2dMstjao68Wrha+D/vSrAgUe0TUvLypAZR rhrkeE6edt87ZkNPG4ZPnmYxSrok7UHh+aZ0VMxNPSu3e7Qtvd+eHx9cNozIHtmFC1YQ fIWkC1iBWHaQVcJe5hl59cdK1hTywkscaqcEOEMCEsfhIbXL2nxt/GzRyCFdUQjqLgYz mkhNhU1B2ncThkkkyI7fez7FcS+hdqH+NnYtJ0hnC6u5zSjg4jMR7sBwX3A+foeNyU/9 CiK070ZGRgF30qRK2XWDGOjSpYf24y1YFhrxp25NlpSea8vyrK9Ih+8PpPL4ZTmYfCz6 okXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lhxHKrhuj0yeCcFyUDJY61NNxXJrm4C++F3ycvmlUlQ=; b=f6SQfB/CthJsknSyfqAfixfSpaaigtkLdEah2F0W6ayAkaKG0szU9nt8hh8by8LjeB HXmxywJlDrXhk8I8qvQXXLeTvHkNdiSn8z+k7bL6NO3w8QWN7cgmmqza3Xbxaemg79Q/ zP+hLs5TdhFtc9Cn8b75b74w8kaFVCIFHxGAgoCNOpQWKEaz7B0P+PKSfqfUNo3irr58 bCgxgvjBWezVuuVXsbAe9Lb2fXkbW6rV56RtGBEo4+gr4XclFwC8fR/GiXnwmDyiPQct CCd6avXgsiaeEEnNiYDnNuhY3suhRde3huh6pwa7lva5vToyT6YEUzSD3kIB7iP+5xQs d+nA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2DBWfR2k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id nb19si2452648ejc.45.2021.08.13.08.14.29; Fri, 13 Aug 2021 08:14:54 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=2DBWfR2k; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241627AbhHMPKm (ORCPT + 99 others); Fri, 13 Aug 2021 11:10:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:53344 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241573AbhHMPKJ (ORCPT ); Fri, 13 Aug 2021 11:10:09 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 7DE30610A5; Fri, 13 Aug 2021 15:09:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1628867383; bh=e+YRVIdHzRFLaCX0tRqJ4nxfDt8VW/X3YHwVokcTYrk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=2DBWfR2kX//nhi6VellI83EsuaxFXuqC+EVB7s9EvGxWg8VDhDdWQxVYMLgqcD5Wm vUV7vFyY6HHcCSb2SZ369tRZzhluIOl996JQwkKQ+RC2G0x0QblLc3IFtK8TuOSmkW oZu3VWDjGNymlGFJsqfu6EaX1dOZU9sUs1J4pz2E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Like Xu , "Peter Zijlstra (Intel)" , Liam Merwick , Kim Phillips Subject: [PATCH 4.9 22/30] perf/x86/amd: Dont touch the AMD64_EVENTSEL_HOSTONLY bit inside the guest Date: Fri, 13 Aug 2021 17:06:50 +0200 Message-Id: <20210813150523.150423972@linuxfoundation.org> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210813150522.445553924@linuxfoundation.org> References: <20210813150522.445553924@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Like Xu commit df51fe7ea1c1c2c3bfdb81279712fdd2e4ea6c27 upstream. If we use "perf record" in an AMD Milan guest, dmesg reports a #GP warning from an unchecked MSR access error on MSR_F15H_PERF_CTLx: [] unchecked MSR access error: WRMSR to 0xc0010200 (tried to write 0x0000020000110076) at rIP: 0xffffffff8106ddb4 (native_write_msr+0x4/0x20) [] Call Trace: [] amd_pmu_disable_event+0x22/0x90 [] x86_pmu_stop+0x4c/0xa0 [] x86_pmu_del+0x3a/0x140 The AMD64_EVENTSEL_HOSTONLY bit is defined and used on the host, while the guest perf driver should avoid such use. Fixes: 1018faa6cf23 ("perf/x86/kvm: Fix Host-Only/Guest-Only counting with SVM disabled") Signed-off-by: Like Xu Signed-off-by: Peter Zijlstra (Intel) Reviewed-by: Liam Merwick Tested-by: Kim Phillips Tested-by: Liam Merwick Link: https://lkml.kernel.org/r/20210802070850.35295-1-likexu@tencent.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/events/perf_event.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) --- a/arch/x86/events/perf_event.h +++ b/arch/x86/events/perf_event.h @@ -771,9 +771,10 @@ void x86_pmu_stop(struct perf_event *eve static inline void x86_pmu_disable_event(struct perf_event *event) { + u64 disable_mask = __this_cpu_read(cpu_hw_events.perf_ctr_virt_mask); struct hw_perf_event *hwc = &event->hw; - wrmsrl(hwc->config_base, hwc->config); + wrmsrl(hwc->config_base, hwc->config & ~disable_mask); } void x86_pmu_enable_event(struct perf_event *event);