Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2313473pxp; Mon, 21 Mar 2022 16:40:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlk9Ot+07WpggXPXnIvHHVT3pDv3NkXstxrsS0fKNg31y0BfKQTI8Ll8yhtyJC6zMVCw/Z X-Received: by 2002:a17:90b:4b0b:b0:1bf:764c:1bc1 with SMTP id lx11-20020a17090b4b0b00b001bf764c1bc1mr1641814pjb.85.1647906010936; Mon, 21 Mar 2022 16:40:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647906010; cv=none; d=google.com; s=arc-20160816; b=pQhlrSUYUvFg5u3+9pj4OMnceh3qWAoSoiU0GN0Hsq4M0gC1Cu2SydWBEqf3mysTBv TMTZil2P2b8YgaEt7sNcurKmwJdvKBevcl8JIfE8dtVeQbYhYgvqMhjb1gmd58K0gzK4 lMpxxgpZf07ELF6riiGhhaxVF77ThYrKHPUGT5VATAc7IMQ8Co7DJV0njIEkBW34efNV HfOCVWzKoQKmWv5+WzgnoxwHPC7kXBA5mpnFDJHsF/mVFZd+9JCIQDmZ4cXy1JP5GCbH pSrYPpU1FmdrjJ/myNqVtDr03MUg6m2O5854o7FAvapStQNdIVrfXnsw6bslkTOqIk+L 2uJg== 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:date:cc:to:from:subject :message-id:dkim-signature; bh=RMdmC49b3ZJ1Mqx/y/k2hlufZoUHk8hDl93lzACB4nw=; b=gxPWv08KPXbs8OLlMHjQxNW4PATjr0B7LaWAaEvr2XouOxFoRbDuCvhHLFLeiIC/Dg 04gyGq1M5cZMjb6W8PZMruBwFZOPdAcMYKnE1MFXyYQoy53Ijckch0DxC15T/rPnonxB NjLSC6C+F9uwsp7q29J2bAYNbTRlMi9ozwksUykV6+jUiBKaeoefsE3Y+abkyS03PeQy zP7fMSeW2RvHvZ+hAm5CKd4shZGQ55/94OlUNn0vJ3sFnVdGDGPmzFYWJd4Tmb0c9TAq rGgTZ5tlESp9cnAhH9E/6wG6OztVA92TnAv7uyeNM7G5oggK974wZ5/W6C5uQqBi3rdn tBrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=duDBEAAI; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id bq23-20020a056a000e1700b004fa916d202fsi5857234pfb.9.2022.03.21.16.40.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Mar 2022 16:40:10 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=duDBEAAI; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D6F073CE848; Mon, 21 Mar 2022 15:53:34 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230458AbiCUWyn (ORCPT + 99 others); Mon, 21 Mar 2022 18:54:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35534 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230395AbiCUWya (ORCPT ); Mon, 21 Mar 2022 18:54:30 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id D06793CE860 for ; Mon, 21 Mar 2022 15:33:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1647901990; 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=RMdmC49b3ZJ1Mqx/y/k2hlufZoUHk8hDl93lzACB4nw=; b=duDBEAAIWH6DO6efTN6IN/rCF1nvX88i0LyghSWyywNvUsqdr3SUovfWJkHBBpE9i2eY5f YfXcUbc1swf6ggMSO1g67e0pBHDZxllfk8dz/CRaEjsUsynLUGxLHmHKa+8h3iCQwkPDmh hQGCnMFp/YrDiu5lsotk9+staset3Ps= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-671-wz3tO8UnOc2-hffHDtKRqg-1; Mon, 21 Mar 2022 18:11:28 -0400 X-MC-Unique: wz3tO8UnOc2-hffHDtKRqg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 900543C14845; Mon, 21 Mar 2022 22:11:27 +0000 (UTC) Received: from starship (unknown [10.40.194.231]) by smtp.corp.redhat.com (Postfix) with ESMTP id 7F9902026D2D; Mon, 21 Mar 2022 22:11:24 +0000 (UTC) Message-ID: <8071f0f0a857b0775f1fb2d1ebd86ffc4fd9096b.camel@redhat.com> Subject: Re: [PATCH v3 4/7] KVM: x86: nSVM: support PAUSE filter threshold and count when cpu_pm=on From: Maxim Levitsky To: Jim Mattson Cc: Paolo Bonzini , kvm@vger.kernel.org, Ingo Molnar , Dave Hansen , Sean Christopherson , Borislav Petkov , "H. Peter Anvin" , Thomas Gleixner , x86@kernel.org, Vitaly Kuznetsov , Joerg Roedel , linux-kernel@vger.kernel.org, Wanpeng Li Date: Tue, 22 Mar 2022 00:11:23 +0200 In-Reply-To: References: <20220301143650.143749-1-mlevitsk@redhat.com> <20220301143650.143749-5-mlevitsk@redhat.com> <6a7f13d1-ed00-b4a6-c39b-dd8ba189d639@redhat.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 2022-03-21 at 14:59 -0700, Jim Mattson wrote: > On Mon, Mar 21, 2022 at 2:36 PM Maxim Levitsky wrote: > > On Wed, 2022-03-09 at 11:07 -0800, Jim Mattson wrote: > > > On Wed, Mar 9, 2022 at 10:47 AM Paolo Bonzini wrote: > > > > On 3/9/22 19:35, Jim Mattson wrote: > > > > > I didn't think pause filtering was virtualizable, since the value of > > > > > the internal counter isn't exposed on VM-exit. > > > > > > > > > > On bare metal, for instance, assuming the hypervisor doesn't intercept > > > > > CPUID, the following code would quickly trigger a PAUSE #VMEXIT with > > > > > the filter count set to 2. > > > > > > > > > > 1: > > > > > pause > > > > > cpuid > > > > > jmp 1 > > > > > > > > > > Since L0 intercepts CPUID, however, L2 will exit to L0 on each loop > > > > > iteration, and when L0 resumes L2, the internal counter will be set to > > > > > 2 again. L1 will never see a PAUSE #VMEXIT. > > > > > > > > > > How do you handle this? > > > > > > > > > > > > > I would expect that the same would happen on an SMI or a host interrupt. > > > > > > > > 1: > > > > pause > > > > outl al, 0xb2 > > > > jmp 1 > > > > > > > > In general a PAUSE vmexit will mostly benefit the VM that is pausing, so > > > > having a partial implementation would be better than disabling it > > > > altogether. > > > > > > Indeed, the APM does say, "Certain events, including SMI, can cause > > > the internal count to be reloaded from the VMCB." However, expanding > > > that set of events so much that some pause loops will *never* trigger > > > a #VMEXIT seems problematic. If the hypervisor knew that the PAUSE > > > filter may not be triggered, it could always choose to exit on every > > > PAUSE. > > > > > > Having a partial implementation is only better than disabling it > > > altogether if the L2 pause loop doesn't contain a hidden #VMEXIT to > > > L0. > > > > > > > Hi! > > > > You bring up a very valid point, which I didn't think about. > > > > However after thinking about this, I think that in practice, > > this isn't a show stopper problem for exposing this feature to the guest. > > > > > > This is what I am thinking: > > > > First lets assume that the L2 is malicious. In this case no doubt > > it can craft such a loop which will not VMexit on PAUSE. > > But that isn't a problem - instead of this guest could have just used NOP > > which is not possible to intercept anyway - no harm is done. > > > > Now lets assume a non malicious L2: > > > > > > First of all the problem can only happen when a VM exit is intercepted by L0, > > and not by L1. Both above cases usually don't pass this criteria since L1 is highly > > likely to intercept both CPUID and IO port access. It is also highly unlikely > > to allow L2 direct access to L1's mmio ranges. > > > > Overall there are very few cases of deterministic vm exit which is intercepted > > by L0 but not L1. If that happens then L1 will not catch the PAUSE loop, > > which is not different much from not catching it because of not suitable > > thresholds. > > > > Also note that this is an optimization only - due to count and threshold, > > it is not guaranteed to catch all pause loops - in fact hypervisor has > > to guess these values, and update them in attempt to catch as many such > > loops as it can. > > > > I think overall it is OK to expose that feature to the guest > > and it should even improve performance in some cases - currently > > at least nested KVM intercepts every PAUSE otherwise. > > Can I at least request that this behavior be documented as a KVM > virtual CPU erratum? 100%. Do you have a pointer where to document it? Best regards, Maxim Levitsky > > > Best regards, > > Maxim Levitsky > > > > > > > >