Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp571700pxb; Mon, 7 Feb 2022 19:18:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJwynIXwa5UZzSUSDymDy6/aao1VjqmuiWOuiF3MR0ppakCxrpHQVrNVeN7/uIPJTDgi27nv X-Received: by 2002:a17:907:6d9b:: with SMTP id sb27mr1299753ejc.85.1644290323115; Mon, 07 Feb 2022 19:18:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644290323; cv=none; d=google.com; s=arc-20160816; b=xziERCp1IHzIl4L7Nfr9wJOp6lNLHVL/sOcvSHrlPtpR+z7xjvmi2LVmIjDuhjZCJu DNxti4TaEku7jwLP2b/DOioeptEVxnniqfWcJTpJcTiMjMUqAKYG6U8iAg2xvg4K5LJr KET62v0p+yzeA6Kas/pLF/JtZpxRA/JgQiVQUDBfFwmLQNmC0ruIFoCb5l+YXX3Ufetw v4ASwNfjtXurYkUE3MCcEo5o+FSWdWHDOx07+WeB3bEuxqch8d0edABDv3QYsmCxaIyI iv93L1kZnJAv3NjFfy5sZXZ7mLhcE74Zl/serqvKeY1N11Wf9yGehAzmRUINkk2Ga40M 4NuQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=Dexw4mp88eho1hqWPLMgXA0V6dq/NOSshXT4P+meRXI=; b=KRmZEK6TmqPmQpR4Inzka1QcIGX5WD4Ui6mSU2jsJ4AM6uyd6NYBu1lGvDq+Zgyvm/ 88wN47uHh11tcf9vURNUSVuIjR6F1HXfIexGQSKBCOeZBqoUJrID0/mCRksi3fciHj1m st2jL+ZhoEE6liijc83JPGifgKRe8ZxwSUZ7TEKQrhsC4ETtkvslPoiY55ztcRSXNERD T53T8s9gsOVpBFGcWLZZPwZkWvmKtPEmhv6Lwhe2+umNjA0fqJrZ0BUi8c/wGFSPweaV r0OK2sVGCfnURYXgW0oHsbuc9maPkX6Jl2oDXBUIwnvBfaApj2XeBOixEngZCfAC2JTF DuYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=I5tbVd2t; 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 13si7956703eje.262.2022.02.07.19.18.18; Mon, 07 Feb 2022 19:18:43 -0800 (PST) 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=20210112 header.b=I5tbVd2t; 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 S245482AbiBHBGB (ORCPT + 99 others); Mon, 7 Feb 2022 20:06:01 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232070AbiBGXxb (ORCPT ); Mon, 7 Feb 2022 18:53:31 -0500 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C8026C061355 for ; Mon, 7 Feb 2022 15:53:30 -0800 (PST) Received: by mail-pf1-x433.google.com with SMTP id r19so45741pfh.6 for ; Mon, 07 Feb 2022 15:53:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Dexw4mp88eho1hqWPLMgXA0V6dq/NOSshXT4P+meRXI=; b=I5tbVd2tNRwEgyv1OaBRfTc0g38c7M8Uvsss+AWjzCTWD7GPF/2/a4fc+2QjbgPw+s zVIC/jUvUMoaybysLG+yUXMp0YXxZxpS73gAIiOKOptsX4M/AJS7xVXvSDaREWoFtK7r S//J2YHVt8vV0k7hhWfB2g9rvTPTmG1RMaTGXSadAV0JQrV4HPNtFG3Ms0KvfoeMiyoT BEVjmOEZvFoQyHEvULInwQL2z5RWYRs//wuIeNnwjpxAkaBaDx0cDRTqnK+7IkAAzjRC alRg+EZmzsHtpYroe8e+vGm4xUB0MB3da2u+YbGfPEXYjQGk1QN1tLvtiCgjUOpQ4H6F FGqA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Dexw4mp88eho1hqWPLMgXA0V6dq/NOSshXT4P+meRXI=; b=PKh1/qIfZ1ZqQXuEHyiUyvFbrboSytw4P4NeN53vk1TpRyl3u/FDsaOZILee8/XtIY TTkWmGfxB+B76FQRV+SjBfY9Y1oOBMCS4bSNMuv/o6UBEUi5Va/8ygEYW5sbewF5Q/FA CDoXY3uw2lst9hYI73aB2tLkx+QgGwIComAmvHOWAz+3a6CF9zFGzMWuTjQ1EbC+0LOo KxnvLIwzH8Tu2xpzkThpaoT0WqymDzfCS9oc4vkdgUDGmKNz7dsQslc8K6+oj2+UTP/r zQILpdzpbS04q2rubkuaZby0emVffQytsd+y86FLXDCvVUApSWqsd5Ci2xpUMp+k3JIV Yp+w== X-Gm-Message-State: AOAM532VaOVeKMmsJHsTfWzbhl0kpMYte+W+X4m/SFm7ZnyhP60Ew8MP +LrVvfXyXh24WFJ+TCrhfnkLCkxTiHns6oJpWiG0hFHM9I8= X-Received: by 2002:a65:5943:: with SMTP id g3mr1447475pgu.3.1644278010062; Mon, 07 Feb 2022 15:53:30 -0800 (PST) MIME-Version: 1.0 References: <20220204115718.14934-1-pbonzini@redhat.com> In-Reply-To: From: David Matlack Date: Mon, 7 Feb 2022 15:53:03 -0800 Message-ID: Subject: Re: [PATCH 00/23] KVM: MMU: MMU role refactoring To: Sean Christopherson Cc: Paolo Bonzini , LKML , kvm list , Vitaly Kuznetsov Content-Type: text/plain; charset="UTF-8" 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 Mon, Feb 7, 2022 at 3:27 PM Sean Christopherson wrote: > > On Mon, Feb 07, 2022, David Matlack wrote: > > On Fri, Feb 04, 2022 at 06:56:55AM -0500, Paolo Bonzini wrote: > > > The TDP MMU has a performance regression compared to the legacy > > > MMU when CR0 changes often. This was reported for the grsecurity > > > kernel, which uses CR0.WP to implement kernel W^X. In that case, > > > each change to CR0.WP unloads the MMU and causes a lot of unnecessary > > > work. When running nested, this can even cause the L1 to hardly > > > make progress, as the L0 hypervisor it is overwhelmed by the amount > > > of MMU work that is needed. > > > > > > The root cause of the issue is that the "MMU role" in KVM is a mess > > > that mixes the CPU setup (CR0/CR4/EFER, SMM, guest mode, etc.) > > > and the shadow page table format. Whenever something is different > > > between the MMU and the CPU, it is stored as an extra field in struct > > > kvm_mmu---and for extra bonus complication, sometimes the same thing > > > is stored in both the role and an extra field. > > > > > > So, this is the "no functional change intended" part of the changes > > > required to fix the performance regression. It separates neatly > > > the shadow page table format ("MMU role") from the guest page table > > > format ("CPU role"), and removes the duplicate fields. > > > > What do you think about calling this the guest_role instead of cpu_role? > > There is a bit of a precedent for using "guest" instead of "cpu" already > > for this type of concept (e.g. guest_walker), and I find it more > > intuitive. > > Haven't looked at the series yet, but I'd prefer not to use guest_role, it's > too similar to is_guest_mode() and kvm_mmu_role.guest_mode. E.g. we'd end up with > > static union kvm_mmu_role kvm_calc_guest_role(struct kvm_vcpu *vcpu, > const struct kvm_mmu_role_regs *regs) > { > union kvm_mmu_role role = {0}; > > role.base.access = ACC_ALL; > role.base.smm = is_smm(vcpu); > role.base.guest_mode = is_guest_mode(vcpu); > role.base.direct = !____is_cr0_pg(regs); > > ... > } > > and possibly > > if (guest_role.guest_mode) > ... > > which would be quite messy. Maybe vcpu_role if cpu_role isn't intuitive? I agree it's a little odd. But actually it's somewhat intuitive (the guest is in guest-mode, i.e. we're running a nested guest). Ok I'm stretching a little bit :). But if the trade-off is just "guest_role.guest_mode" requires a clarifying comment, but the rest of the code gets more readable (cpu_role is used a lot more than role.guest_mode), it still might be worth it.