From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5A77FC7EE23 for ; Thu, 1 Jun 2023 21:23:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231415AbjFAVXo (ORCPT ); Thu, 1 Jun 2023 17:23:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44708 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229497AbjFAVXm (ORCPT ); Thu, 1 Jun 2023 17:23:42 -0400 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2222E1A1 for ; Thu, 1 Jun 2023 14:23:38 -0700 (PDT) Received: by mail-pl1-x630.google.com with SMTP id d9443c01a7336-1ae64580e9fso11435ad.1 for ; Thu, 01 Jun 2023 14:23:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1685654617; x=1688246617; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=+anUQPQ5nwJea5x9S41SzUJzVAZ4hONAhzugoJuW63k=; b=gf+KwotDEfn2Fr2bIkJVU9msFMj7Tcqe5rtZDxlimO0mw8cHxo22Jb+YfIPoUB9LYv /pK/q/mTyV2kXEzJPwjaaSdv7GykOoP7OYogZUwsYcASZfdXHizPtCeqmMRkSeFHAgf4 rzgG2JUoD9vvh/S6yWJh51kJFXJqyDrvY226RrtE4mzVZPpyC/0zN/GXLT3EeQRfZxiq QgfJyK2Q/vOPRM4kKY26Weoc49CkImkvPQ2y5BYn6fd4LwYski73cWMHgGx/NoRFGllq Y5C58ftBUm8J2I0f2DRxdz8+7T+d0U+zdpRyzBX9LRD2oKKzHtSsieH3AeQu7hOcq6Yr R8/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685654617; x=1688246617; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+anUQPQ5nwJea5x9S41SzUJzVAZ4hONAhzugoJuW63k=; b=IHRIxvilxX9UC0zkQCanAea63twoViv0SWlu+PJGZYzZAD9IRARIsu/B//6GPDLryv OdZkMNo7Lop27Eh3hnALONT+FnTR0t0TJgC7bf43G9dAcqNp0mH9Og2N3Rl0htQPe0n/ PLRBPZ93ddT2B0GsTmEXVgNs8ToDSfig7DmUFvqAVRk+gwFmPV6qzAsCCjbLLWDiPd3h AJv1Rcegk0cZl3gThUoAi9gdXgUVFvMoNMBibRocIJlYYG2mRQAeTdArjBPjJBlmgvqy 6Xbn91y3ANtVOusOOYybkZVqQHB6ZtWTG3H1yo/GYhVtR/JmNQPy/HgmFvfFVliixhMm GCCA== X-Gm-Message-State: AC+VfDy0Jm2bzWsxZ4SDXh0QKzNsJHjZb0YAd6HDc9iiDGzdVNAv/lMC Io0pGYELrVcY7sabNdJq4s1Uu94zFnDHlWwGlF5tNw== X-Google-Smtp-Source: ACHHUZ49YwOiHVnPivj1UlyMIXNWd6YKixq9CTGwvl1CukOZ51h+EvZAq/xgXhV/G4Xc9X7W+TPvgiN5RNIO70s97v4= X-Received: by 2002:a17:903:27c7:b0:1b0:5304:5b6b with SMTP id km7-20020a17090327c700b001b053045b6bmr62185plb.20.1685654617442; Thu, 01 Jun 2023 14:23:37 -0700 (PDT) MIME-Version: 1.0 References: <9d37ab07-97c6-5245-6939-9c1090b4b3a9@redhat.com> <3cb96907-0d58-ba60-ed0e-6c17c69bd0f8@redhat.com> <623EC08D-A755-4520-B9BF-42B0E72570C1@nutanix.com> <658D3EF0-B2D3-4492-A2A1-FC84A58B201D@nutanix.com> In-Reply-To: From: Jim Mattson Date: Thu, 1 Jun 2023 14:23:26 -0700 Message-ID: Subject: Re: [PATCH v4] KVM: VMX: do not disable interception for MSR_IA32_SPEC_CTRL on eIBRS To: Sean Christopherson Cc: Jon Kohler , Waiman Long , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "x86@kernel.org" , "H. Peter Anvin" , Josh Poimboeuf , Kees Cook , Andrea Arcangeli , "kvm@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Josh Poimboeuf Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Jun 1, 2023 at 1:35=E2=80=AFPM Sean Christopherson wrote: > > On Thu, Jun 01, 2023, Jim Mattson wrote: > > On Thu, Jun 1, 2023 at 12:28=E2=80=AFPM Jon Kohler wr= ote: > > > > diff --git a/arch/x86/kvm/x86.h b/arch/x86/kvm/x86.h > > > > index c544602d07a3..454bcbf5b543 100644 > > > > --- a/arch/x86/kvm/x86.h > > > > +++ b/arch/x86/kvm/x86.h > > > > @@ -492,7 +492,31 @@ static inline void kvm_machine_check(void) > > > > > > > > void kvm_load_guest_xsave_state(struct kvm_vcpu *vcpu); > > > > void kvm_load_host_xsave_state(struct kvm_vcpu *vcpu); > > > > + > > > > int kvm_spec_ctrl_test_value(u64 value); > > > > + > > > > +static inline bool kvm_account_msr_spec_ctrl_write(struct kvm_vcpu= *vcpu) > > > > +{ > > > > + if ((vcpu->stat.exits - vcpu->arch.spec_ctrl_nr_exits_snapsho= t) < 20) > > > > I think you mean 200 here. If it's bad to have more than 1 > > WRMSR(IA32_SPEC_CTRL) VM-exit in 20 VM-exits, then more than 10 such > > VM-exits in 200 VM-exits represents sustained badness. > > No? The snapshot is updated on every write, i.e. this check is whether o= r not > the last wrmsr(SPEC_CTRL) was less than 20 cycles ago. > > if ((vcpu->stat.exits - vcpu->arch.spec_ctrl_nr_exits_snapshot) < = 20) > vcpu->arch.nr_quick_spec_ctrl_writes++; > else > vcpu->arch.nr_quick_spec_ctrl_writes =3D 0; Okay, then maybe this else clause is too aggressive. Just because we went 21 VM-exits without seeing a WRMSR(IA32_SPEC_CTRL), we don't want to clobber all of our history. > vcpu->arch.spec_ctrl_nr_exits_snapshot =3D vcpu->stat.exits; <=3D= new snapshot > > return vcpu->arch.nr_quick_spec_ctrl_writes >=3D 10; > > > (Although, as Sean noted, these numbers are just placeholders.) > > And the logic is very off-the-cuff, e.g. it may be better to have a rolli= ng 200-exit > window instead of 10 somewhat independent 20-exit windows.