Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp4083970pxu; Mon, 30 Nov 2020 17:29:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJxVBqCV4PjnXoCIaTAZrqoYdeEgeyq+dHDlzw+1AoXUHQ5qe4KHXynWp6CcWkGQwUZ4C1oF X-Received: by 2002:a17:906:4712:: with SMTP id y18mr627315ejq.495.1606786170222; Mon, 30 Nov 2020 17:29:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606786170; cv=none; d=google.com; s=arc-20160816; b=No0xi3pUkv1qKXI6JbseFt6VoFgDtOki9e+D8XWAZNYRt8ch6qWWC5GDSTfoVeX192 gl0cx26+EGjF4FeE5FUK8JkWNuhSTKc1TELdmkH5z/QZJDquCoWx90VnCrupcGlllan2 mIFHOtI63sQ5H39kSvmKAJWsCy0+LM4ojRkC6m7OELeZcPLwvlZTA7XEq+GQZ5c4RUrS MIaqek4OYVCGplAxg792OCw1MGVa4JVMmmK+C4xqXQoLxsW1NrbAPoU6NkHBx6q3ctqv Ul89fcm2CdwxieShhuRre56XMyEn8WVx6HV8oXXYw1D0UIjwvwg15FAWm4k1Bb+YFR1G E8Og== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-language:content-transfer-encoding :in-reply-to:mime-version:user-agent:date:message-id:from:references :cc:to:subject:ironport-sdr:ironport-sdr; bh=p98Pw4Xs4AKM01LIlYXzBf/btswFSeX7KapwK/XVfW8=; b=Bfu5lk/oLc7G1oRaIKeXIg+6Jk2MSSAkPQp5479Na1S5aICXKB/G1BxHccv0ooEAkX 4/XJiRnxxYhPF0wMAV2nXMhcm+E6s7PAWqdcoRFUTH74M6qiw4gIC9Mg2T6sVo9vGMme bX92i+W5u5IuClQwPn4m8Z5BycpDv7kusSvcOTKEfFSN0X9HyER0hR96yRaMamkEmbxv 1N2Yl+rPYsBLWJHxcahrVvj1I/VIZJjG6VzI+KZ2teT5TnntpIcneV0ZkYCNys5o8kgW bqBaA9LSij+q1g4Axt7FtJgfvQQYBncPc205+Zzc90pCrgF8HwTlLk7l/8v9xs/0zLmO ue+Q== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x8si231291edl.492.2020.11.30.17.29.06; Mon, 30 Nov 2020 17:29:30 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731125AbgLAB0S (ORCPT + 99 others); Mon, 30 Nov 2020 20:26:18 -0500 Received: from mga05.intel.com ([192.55.52.43]:61065 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730037AbgLAB0S (ORCPT ); Mon, 30 Nov 2020 20:26:18 -0500 IronPort-SDR: LFYbiZ/PEyua4oe1WzzSIc5sZElrTRXEOel3At7VHFPpYtBfPRNfqynAM35aeP7Lz49UqFTOss i7F6HyntJcfQ== X-IronPort-AV: E=McAfee;i="6000,8403,9821"; a="257452991" X-IronPort-AV: E=Sophos;i="5.78,382,1599548400"; d="scan'208";a="257452991" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga004.jf.intel.com ([10.7.209.38]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2020 17:25:37 -0800 IronPort-SDR: qJWgCtexdRDgL0abS9F/Mc757eplyHZlRPL8TtkC34L3iut3muWe84Cd/8TNTilIDhQyeeytPr mmKONjc+7wbw== X-IronPort-AV: E=Sophos;i="5.78,382,1599548400"; d="scan'208";a="480886177" Received: from likexu-mobl1.ccr.corp.intel.com (HELO [10.238.4.107]) ([10.238.4.107]) by orsmga004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 30 Nov 2020 17:25:31 -0800 Subject: Re: [PATCH v2 04/17] perf: x86/ds: Handle guest PEBS overflow PMI and inject it to guest To: Peter Zijlstra Cc: Like Xu , "Kleen, Andi" , Paolo Bonzini , kvm@vger.kernel.org, Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Kan Liang , luwei.kang@intel.com, Thomas Gleixner , wei.w.wang@intel.com, Tony Luck , Stephane Eranian , Mark Gross , Srinivas Pandruvada , linux-kernel@vger.kernel.org References: <20201109021254.79755-1-like.xu@linux.intel.com> <20201109021254.79755-5-like.xu@linux.intel.com> <20201117143529.GJ3121406@hirez.programming.kicks-ass.net> <20201118180721.GA3121392@hirez.programming.kicks-ass.net> <682011d8-934f-4c76-69b0-788f71d91961@intel.com> <20201130104935.GN3040@hirez.programming.kicks-ass.net> From: "Xu, Like" Message-ID: <7739a926-8da8-32c5-650d-2ee46ddab1ed@intel.com> Date: Tue, 1 Dec 2020 09:25:29 +0800 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.5.0 MIME-Version: 1.0 In-Reply-To: <20201130104935.GN3040@hirez.programming.kicks-ass.net> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Peter, On 2020/11/30 18:49, Peter Zijlstra wrote: > On Fri, Nov 27, 2020 at 10:14:49AM +0800, Xu, Like wrote: > >>> OK, but the code here wanted to inspect the guest DS from the host. It >>> states this is somehow complicated/expensive. But surely we can at the >>> very least map the first guest DS page somewhere so we can at least >>> access the control bits without too much magic. >> We note that the SDM has a contiguous present memory mapping >> assumption about the DS save area and the PEBS buffer area. >> >> Therefore, we revisit your suggestion here and move it a bit forward: >> >> When the PEBS is enabled, KVM will cache the following values: >> - gva ds_area (kvm msr trap) >> - hva1 for "gva ds_area" (walk guest page table) >> - hva2 for "gva pebs_buffer_base" via hva1 (walk guest page table) > What this [gh]va? Guest/Host Virtual Address? I think you're assuming I > know about all this virt crap,.. I don't. Oh, my bad and let me add it: gva: guest virtual address gpa: guest physical address gfn: guest frame number hva: host virtual adderss hpa: host physical address In the KVM, we get hva from gva in the following way: gpa = kvm_mmu_gva_to_gpa_system(vcpu, gva, NULL); gfn = gpa >> PAGE_SHIFT; slot = gfn_to_memslot(kvm, gfn); hva = gfn_to_hva_memslot_prot(slot, gfn, NULL); > >> if the "gva ds_area" cache hits, > what? Sorry, it looks a misuse of terminology. I mean KVM will save the last used "gva ds_area" value and its hva in the extra fields, if the "gva ds_area" does not change this time, we will not walk the guest page table to get its hva again. I think it's the main point in your suggestion, and I try to elaborate it. >> - access PEBS "interrupt threshold" and "Counter Reset[]" via hva1 >> - get "gva2 pebs_buffer_base" via __copy_from_user(hva1) > But you already had hva2, so what's the point? hva1 is for for "gva ds_area" hva2 is for "gva pebs_buffer_base" The point is before using the last save hva2, we need to make sure that "gva pebs_buffer_base" is not changed to avoid that some malicious drivers may change it without changing ds_area. > >> if the "gva2 pebs_buffer_base" cache hits, > What? > >> - we get "gva2 pebs_index" via __copy_from_user(hva2), > pebs_index is in ds_are, which would be hva1 Yes, we get "gva2 pebs_index" via __copy_from_user(hva1). > >> - rewrite the guest PEBS records via hva2 and pebs_index >> >> If any cache misses, setup the cache values via walking tables again. >> >> I wonder if you would agree with this optimization idea, >> we look forward to your confirmation for the next step. > I'm utterly confused. I really can't follow. Generally, KVM will save hva1 (gva1 ds_area) and hva2 (for gva2 pebs_buffer_base) in the first round of the guest page table walking and reuse them if they're not changed in subsequent use. I think this approach is feasible, and please complain if you are still confused or disagree. Thanks, Like Xu