Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp1358569rwd; Thu, 1 Jun 2023 14:29:56 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ6PSMOGUEj7zEk1jAAzmCzQjdSoZshOhh7MlwcT1QEuCEifXOp2jN29mGhYHcSYr+hNixdV X-Received: by 2002:a05:6a21:33a8:b0:f0:50c4:4c43 with SMTP id yy40-20020a056a2133a800b000f050c44c43mr3592941pzb.5.1685654996482; Thu, 01 Jun 2023 14:29:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685654996; cv=none; d=google.com; s=arc-20160816; b=ILrcK1XxOI8PGOiJoxj7jNb2ziSeEDjp31UZxVuUT9KiDTAlu8QPxqLEuYh9k5iB40 by+krgnPF7vfDmV0AV5keDzQwY5cJJJ4aYVrPR86ll/GsrYjf0k3FplPzNXvn8jVQiKe 0H378fPu+hTqKEvL9+LZ8P4DNCJ49M9bMvbvAjKsVpRNwGL0ta/Gv6YRZS35RZS8upVi F6aLZyETw9eGfeRKSbNv7QiUkA3rpKhR2kcnUGImEbEr1k+GAGl+C0M/YGrYCTA9yjIr 5solNlNenD2FIQ98g6WE2510rY2mHq3NzJ/uRU1rRnm4Hs/s/eM0/OdnDL8/VKWhjKWF zZhA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=+anUQPQ5nwJea5x9S41SzUJzVAZ4hONAhzugoJuW63k=; b=byAmO6Xgr5/StDiIlIK/vqR2nXPvMX9GwRqP9ERYZDURBGXJZN2QXyJN+LJ97zlMbo lDn9QxPzP7kKa/LvVmMcTbnbdJ+Y+LegBKGwX9XYyOPst0H535+I0rk6nzgAoTOpAPSb 8ciGQaTUQ6PDYO+be7yvl4S1tsAUpQBg6lm/O1wksdLpRIZWkBxwD7JQvCvg7+tYEACQ OA7UOWUIzxArgFxZqGdsRrpRbN62aNumW4rJlySdTvFWCEVWJ6IXBBbpXujXlYxY5oMi C4vMISmy0z4qSdaOenp+QYWwTmzCBRORl+hGZEfmYO+rySHU+2LcVu1hPRmqxLwVwpYM PM5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=gf+KwotD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id f14-20020aa7968e000000b0063f032d78efsi6069548pfk.269.2023.06.01.14.29.42; Thu, 01 Jun 2023 14:29:56 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=gf+KwotD; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231383AbjFAVXn (ORCPT + 99 others); Thu, 1 Jun 2023 17:23:43 -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-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 X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham 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 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.