Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp329402pxm; Wed, 2 Mar 2022 16:32:18 -0800 (PST) X-Google-Smtp-Source: ABdhPJxjAzMAW4r52TTE7vH5ZEGoKxjBszso54M3cKyjo9+IY9nOhaHi3Ktxz2Gr7fmYEZzdZ/C0 X-Received: by 2002:a17:90a:2f8a:b0:1be:f42e:b982 with SMTP id t10-20020a17090a2f8a00b001bef42eb982mr2439225pjd.217.1646267538667; Wed, 02 Mar 2022 16:32:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646267538; cv=none; d=google.com; s=arc-20160816; b=rDrBY1Jc9rO2kC6FB7p+rmr2L9NkwZPKePqZB1Mi8WR/68dXxaYf5n6Ua7NcP258CK w3WOLCb/hBy3ztT200z0Ay6yp5XUxnbCwA/MMZGvUg9LJNoYTAgNf77e75y2OIYax8hS fyO3smDisZxcEVs7zV6V7cF+RrMEztICUPFZOASeHh2EOsRKGAQp1JdJ6Wc9rADrSgYz o+xbwP/LBFnqyD+aLFoZ+eqGWBbRjwIJQT8NxwkF2RUUqXE3sgHigOVMqVagJEbPZIob i6KFkAApEGOMFmyiwTgKgw3fHNnJxCOsR0LB7yAdhmQF6PNDICuu6EFXjzfq9ovenSqz M5hQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=x9wMKym9S9fXqEpB7R7eZDSTX7z54wGdD8KBKn9vuvI=; b=sQnAcJaqqX8xYQRZvAZy5D0dd5LPlO5/lVp6RB/ru6lALEHjxN13+LH14FJQOuXF5U ZS+RE6q/5aIlEOotVPKyPtKl7ZEaz9DT7wKJ5KIHOXRvCekV7hON0HNf65vX+KYyK7Wb /avPq5RA6A/0CVuoV1xS6VN5G8120rRazppPtSXOIyRFcO2qHCMsumqLH3r3umRmO6CM 6CGN7YDy6P+K6YCvEWV/O2L2/bJiR2P6eKgNR+AoI+cSnXbzo4Vgq7gTFFe176Z4wxYB eEjhbIqN+vdzZ9gHr0afe5zXwdZKe8Zbr26hsqGp3n/Wfak/G/loDwahM6b4tvKGgs+l CKgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=EgHj1lPu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id il3-20020a17090b164300b001befac0f656si588284pjb.112.2022.03.02.16.32.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 16:32:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=EgHj1lPu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2C3C7238930; Wed, 2 Mar 2022 15:43:31 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229546AbiCBW5n (ORCPT + 99 others); Wed, 2 Mar 2022 17:57:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229508AbiCBW5l (ORCPT ); Wed, 2 Mar 2022 17:57:41 -0500 Received: from mail-pf1-x42d.google.com (mail-pf1-x42d.google.com [IPv6:2607:f8b0:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8A8313CEE5 for ; Wed, 2 Mar 2022 14:56:47 -0800 (PST) Received: by mail-pf1-x42d.google.com with SMTP id x18so3203373pfh.5 for ; Wed, 02 Mar 2022 14:56:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=x9wMKym9S9fXqEpB7R7eZDSTX7z54wGdD8KBKn9vuvI=; b=EgHj1lPuwxxF7nT8U4wKaQR+RaYO9IipnSX48Gc/qLTii8qz4a6RlGCPMChRxH6QdR MiGQ4u3fOj6GLOfPtYyUVGCIQWox9k2+UNT/zY2BzqTpiCsB8mIdQXe+Zo5ICbusEpna YzJnp/92tZ23nkB/aufnwSe1JUu9dkb9ClKI867FycqPuhmDpC+W7Wis3c5Jy8Q59V/W BCl7QPyx0YCdKs6jU9BT5ja1Icf7uA11O1lMBc4leN+MsVZ5XLDH8OVLrGFHmYerMfRX 84hbGQYB4qBseyAn/01vvvxpz2OOSANZJJhoLx5HsyjHYt7Sl3a/5NaThrjHlSnauAnx PYmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=x9wMKym9S9fXqEpB7R7eZDSTX7z54wGdD8KBKn9vuvI=; b=rtDF7dCuWldSDTqmODvywtGxo0SiwMzTUWRun/7ghdHgTXcZm4xH+nVoR0aXYFyms4 GUPHLMjsWKUq5yy/7lEiG7rgKOF+LL3J56kjLD8Z6gDmwZHvZ+2gZADx/D/MPVjRaS4e mDC7s3TZbKisgSyz5BOkd1dJ2aWY3LHGcwkMIN+mD4mqEvQtdfLzj7VKdajZEmuZkFiN ziNMHNN3kN+4JU9gzPAvsnyyY/Q1UASSmBrHJlr8m5GmPTQi1eDbsFxI8+GVheF59rxn Ce2ltJFrCQy4+OK44yiFYFDQv58//agL6asMIM5ZVDrhs67eo7Hfqir/BoKe+TLDBd5i SW+Q== X-Gm-Message-State: AOAM533cY/6WPb9Ear+ZszF9mbcfOsRkBJdUTbrJb4NyqqDxirOSsylJ KrWGKoeKf5rf9Nzm+3O/L0e0vw== X-Received: by 2002:a05:6a00:d4c:b0:4e0:27dd:37c1 with SMTP id n12-20020a056a000d4c00b004e027dd37c1mr35550899pfv.86.1646261640293; Wed, 02 Mar 2022 14:54:00 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id s2-20020a056a001c4200b004f41e1196fasm221880pfw.17.2022.03.02.14.53.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 02 Mar 2022 14:53:59 -0800 (PST) Date: Wed, 2 Mar 2022 22:53:56 +0000 From: Sean Christopherson To: Paolo Bonzini Cc: Christian Borntraeger , Janosch Frank , David Hildenbrand , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Gardon , Lai Jiangshan Subject: Re: [PATCH v2 4/7] KVM: x86/mmu: Zap only obsolete roots if a root shadow page is zapped Message-ID: References: <20220225182248.3812651-1-seanjc@google.com> <20220225182248.3812651-5-seanjc@google.com> <40a22c39-9da4-6c37-8ad0-b33970e35a2b@redhat.com> <217cc048-8ca7-2b7b-141f-f44f0d95eec5@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <217cc048-8ca7-2b7b-141f-f44f0d95eec5@redhat.com> X-Spam-Status: No, score=-10.0 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE, USER_IN_DEF_DKIM_WL 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 Wed, Mar 02, 2022, Paolo Bonzini wrote: > On 3/2/22 20:45, Sean Christopherson wrote: > > AMD NPT is hosed because KVM's awful ASID scheme doesn't assign an ASID per root > > and doesn't force a new ASID. IMO, this is an SVM mess and not a TDP MMU bug. > > I agree. > > > In the short term, I think something like the following would suffice. Long term, > > we really need to redo SVM ASID management so that ASIDs are tied to a KVM root. > > > diff --git a/arch/x86/kvm/svm/svm.c b/arch/x86/kvm/svm/svm.c > index c5e3f219803e..7899ca4748c7 100644 > --- a/arch/x86/kvm/svm/svm.c > +++ b/arch/x86/kvm/svm/svm.c > @@ -3857,6 +3857,9 @@ static void svm_load_mmu_pgd(struct kvm_vcpu *vcpu, > hpa_t root_hpa, > unsigned long cr3; > > if (npt_enabled) { > + if (is_tdp_mmu_root(root_hpa)) > + svm->current_vmcb->asid_generation = 0; > + > svm->vmcb->control.nested_cr3 = __sme_set(root_hpa); > vmcb_mark_dirty(svm->vmcb, VMCB_NPT); > > Why not just new_asid My mental coin flip came up tails? new_asid() is definitely more intuitive. > (even unconditionally, who cares)? Heh, I was going to say we do care to some extent for nested transitions, then I remembered we flush on every nested transition anyways, in no small part because the ASID handling is a mess.