Message ID | 20221213033030.83345-2-seanjc@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2610371wrr; Mon, 12 Dec 2022 19:33:46 -0800 (PST) X-Google-Smtp-Source: AA0mqf7An6SYeVzc/InOMQOcRkFwL708wfkFAvUd7PWOLdIfVheUE1mN0VeTN7mc9oqZRcn63juU X-Received: by 2002:a17:906:26d6:b0:78d:f454:387a with SMTP id u22-20020a17090626d600b0078df454387amr15861289ejc.55.1670902426770; Mon, 12 Dec 2022 19:33:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670902426; cv=none; d=google.com; s=arc-20160816; b=nYcAAY+pbKnd89zT1silueohyjYkjR1VVp5s+jqSzKLXdXpZ0m6fH4YdibGbGVyrYm JV2n0GfW7m4dolE8K+aqyQXoT+RKJ2ZZpHNXc4HS5kEGJHS/zWkx52MtVMlL443wu/eE MJ07hiC1dPNC9E0z0MQRYCeu/0usYX+bmxdXC4GMzUnAEunqOUEUe8diA5UwnZWP5qPo MefZKoDVpqOfYJkBpVPmMOW1IBzQV/4p0iiHh/Q9lgCBPNvCFjblggu424bYv6oXlGUb DsNhVlVqMzCLzRYmjTnAIkeOZGOqy8fsxTwW7gnj8v7iyv2n5QodlmX4YJyIRMH2jjwj ZzVQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:reply-to:dkim-signature; bh=RxUces6vMG4+c5LveealZEzgVFW4k2gLn9w4VIDwQ6E=; b=NWWtL147U+OvIgKLxk483o/JqHk5i5C6UyULJJqOVZVZ2KHbHQO8MCx6kfHRipYdKs wJWYFeROdCSAjy+4mD7Vq5uUTl5ffwQBZebsOfwo62ceuDuzQj+yp8MpmKqYJd214Xh2 Xel+YJWGM+puUtq4h09Rwd1ldvgPIX6meaW+64laKaQRTZQte+fRv1cpySCJovZM4bmV wSoxFpgTLUw7qcfIT5gmZ10uu8LJ/U49eALC3heWc/+LsaDtrnc4/3Gr4+DIX07siM1m rEyQHSU7ltMEHrZzM6L3smoCWZ96RX6ku/3VLuo1kwHepmBIvUvj7pq6E54k4M/Ufb/A bIlQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b="lq/GEj1d"; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g22-20020a1709065d1600b0077e04f856a2si7964041ejt.541.2022.12.12.19.33.23; Mon, 12 Dec 2022 19:33:46 -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="lq/GEj1d"; 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 S229441AbiLMDal (ORCPT <rfc822;jeantsuru.cumc.mandola@gmail.com> + 99 others); Mon, 12 Dec 2022 22:30:41 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234128AbiLMDag (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Mon, 12 Dec 2022 22:30:36 -0500 Received: from mail-pf1-x449.google.com (mail-pf1-x449.google.com [IPv6:2607:f8b0:4864:20::449]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 037A11B9C0 for <linux-kernel@vger.kernel.org>; Mon, 12 Dec 2022 19:30:36 -0800 (PST) Received: by mail-pf1-x449.google.com with SMTP id f14-20020a056a0022ce00b005782e3b4704so1207983pfj.4 for <linux-kernel@vger.kernel.org>; Mon, 12 Dec 2022 19:30:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=RxUces6vMG4+c5LveealZEzgVFW4k2gLn9w4VIDwQ6E=; b=lq/GEj1d2zHrbru8iZ1qjB/Gm763m2IT0FGRntOmlZZGmAogcCDxjdxsgG8QUkA4gs 3HmAKxedcc0SmnlM8mMF3b1XEjAJJvxaOoMkV2Rf73uEsd7wrce4ToRMMVotLxikcdaR 8tz060UpDPZVxXEif4gg8Fr8oHHUzwhTIh9wNHGH3mv4KqwmTj6hVqMGxUosvHTwK5OQ p+Sy6U3lcLspFg0JRm7jXJbswBNorqyfcqMfRL/jBamIWn6JrUCyOw0houliRDImP+Cy foC16AHRKQ5j66k+3J656QAirqxqhzt1d+Gvjvuhg9DgO6b0TlhOiBsNE+MMy5oNTg7j LF9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RxUces6vMG4+c5LveealZEzgVFW4k2gLn9w4VIDwQ6E=; b=71e07Q0ctGtVtO79CXtuIsxXPR/3iOAo8qDFVR1WG0i9bjK9IpemalnCD4Z90Oouwn brH0KDVL4tmNUZ1wUADF8YIXfIlzRL2eXhJq1S5FyY7BJlh4o/GTIt1fOziQ9yDeTh4f w4d95hz1k1w/gNNsNmuzDSx4dp+YbCczzEMHMBNhn4SmPLcMJrSQN4egrkA1v/AvKSTC koLGoBSxVrcph4nUhhAfhSEW2TxZEGdtAay0WnBBEx4ddUTbgcIIAJivHzQrnrqjDd0v lC/IYROvkLDdNXkVKNXxB5RCyEz7/yZWmE4LvgJkSC8mxuTmDc+ta5NxdnVDQUm8nOPe 7lfw== X-Gm-Message-State: ANoB5pma5pOKY7p19DiEvep6XQu+8dnvuFPeO7t4z3q2gTMWEctWgp5h ecEqKXC3attOTGrlJhI/YUx+UEibymE= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a17:90a:2ecb:b0:219:5b3b:2b9f with SMTP id h11-20020a17090a2ecb00b002195b3b2b9fmr14549pjs.2.1670902235305; Mon, 12 Dec 2022 19:30:35 -0800 (PST) Reply-To: Sean Christopherson <seanjc@google.com> Date: Tue, 13 Dec 2022 03:30:26 +0000 In-Reply-To: <20221213033030.83345-1-seanjc@google.com> Mime-Version: 1.0 References: <20221213033030.83345-1-seanjc@google.com> X-Mailer: git-send-email 2.39.0.rc1.256.g54fd8350bd-goog Message-ID: <20221213033030.83345-2-seanjc@google.com> Subject: [PATCH 1/5] KVM: x86/mmu: Don't attempt to map leaf if target TDP MMU SPTE is frozen From: Sean Christopherson <seanjc@google.com> To: Sean Christopherson <seanjc@google.com>, Paolo Bonzini <pbonzini@redhat.com> Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Robert Hoo <robert.hu@linux.intel.com>, Greg Thelen <gthelen@google.com>, David Matlack <dmatlack@google.com>, Ben Gardon <bgardon@google.com>, Mingwei Zhang <mizhang@google.com> Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1752068183202583717?= X-GMAIL-MSGID: =?utf-8?q?1752068183202583717?= |
Series |
KVM: x86/mmu: TDP MMU fixes for 6.2
|
|
Commit Message
Sean Christopherson
Dec. 13, 2022, 3:30 a.m. UTC
Hoist the is_removed_spte() check above the "level == goal_level" check
when walking SPTEs during a TDP MMU page fault to avoid attempting to map
a leaf entry if said entry is frozen by a different task/vCPU.
------------[ cut here ]------------
WARNING: CPU: 3 PID: 939 at arch/x86/kvm/mmu/tdp_mmu.c:653 kvm_tdp_mmu_map+0x269/0x4b0
Modules linked in: kvm_intel
CPU: 3 PID: 939 Comm: nx_huge_pages_t Not tainted 6.1.0-rc4+ #67
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 02/06/2015
RIP: 0010:kvm_tdp_mmu_map+0x269/0x4b0
RSP: 0018:ffffc9000068fba8 EFLAGS: 00010246
RAX: 00000000000005a0 RBX: ffffc9000068fcc0 RCX: 0000000000000005
RDX: ffff88810741f000 RSI: ffff888107f04600 RDI: ffffc900006a3000
RBP: 060000010b000bf3 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 000ffffffffff000 R12: 0000000000000005
R13: ffff888113670000 R14: ffff888107464958 R15: 0000000000000000
FS: 00007f01c942c740(0000) GS:ffff888277cc0000(0000) knlGS:0000000000000000
CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033
CR2: 0000000000000000 CR3: 0000000117013006 CR4: 0000000000172ea0
Call Trace:
<TASK>
kvm_tdp_page_fault+0x10c/0x130
kvm_mmu_page_fault+0x103/0x680
vmx_handle_exit+0x132/0x5a0 [kvm_intel]
vcpu_enter_guest+0x60c/0x16f0
kvm_arch_vcpu_ioctl_run+0x1e2/0x9d0
kvm_vcpu_ioctl+0x271/0x660
__x64_sys_ioctl+0x80/0xb0
do_syscall_64+0x2b/0x50
entry_SYSCALL_64_after_hwframe+0x46/0xb0
</TASK>
---[ end trace 0000000000000000 ]---
Fixes: 63d28a25e04c ("KVM: x86/mmu: simplify kvm_tdp_mmu_map flow when guest has to retry")
Cc: Robert Hoo <robert.hu@linux.intel.com>
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/mmu/tdp_mmu.c | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
Comments
On Tue, 2022-12-13 at 03:30 +0000, Sean Christopherson wrote: > Hoist the is_removed_spte() check above the "level == goal_level" > check > when walking SPTEs during a TDP MMU page fault to avoid attempting to > map > a leaf entry if said entry is frozen by a different task/vCPU. > > ------------[ cut here ]------------ > WARNING: CPU: 3 PID: 939 at arch/x86/kvm/mmu/tdp_mmu.c:653 > kvm_tdp_mmu_map+0x269/0x4b0 > Modules linked in: kvm_intel > CPU: 3 PID: 939 Comm: nx_huge_pages_t Not tainted 6.1.0-rc4+ #67 > Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 0.0.0 > 02/06/2015 > RIP: 0010:kvm_tdp_mmu_map+0x269/0x4b0 > RSP: 0018:ffffc9000068fba8 EFLAGS: 00010246 > RAX: 00000000000005a0 RBX: ffffc9000068fcc0 RCX: 0000000000000005 > RDX: ffff88810741f000 RSI: ffff888107f04600 RDI: ffffc900006a3000 > RBP: 060000010b000bf3 R08: 0000000000000000 R09: 0000000000000000 > R10: 0000000000000000 R11: 000ffffffffff000 R12: 0000000000000005 > R13: ffff888113670000 R14: ffff888107464958 R15: 0000000000000000 > FS: 00007f01c942c740(0000) GS:ffff888277cc0000(0000) > knlGS:0000000000000000 > CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 > CR2: 0000000000000000 CR3: 0000000117013006 CR4: 0000000000172ea0 > Call Trace: > <TASK> > kvm_tdp_page_fault+0x10c/0x130 > kvm_mmu_page_fault+0x103/0x680 > vmx_handle_exit+0x132/0x5a0 [kvm_intel] > vcpu_enter_guest+0x60c/0x16f0 > kvm_arch_vcpu_ioctl_run+0x1e2/0x9d0 > kvm_vcpu_ioctl+0x271/0x660 > __x64_sys_ioctl+0x80/0xb0 > do_syscall_64+0x2b/0x50 > entry_SYSCALL_64_after_hwframe+0x46/0xb0 > </TASK> > ---[ end trace 0000000000000000 ]--- > > Fixes: 63d28a25e04c ("KVM: x86/mmu: simplify kvm_tdp_mmu_map flow > when guest has to retry") > Cc: Robert Hoo <robert.hu@linux.intel.com> > Signed-off-by: Sean Christopherson <seanjc@google.com> > --- > arch/x86/kvm/mmu/tdp_mmu.c | 6 +++--- > 1 file changed, 3 insertions(+), 3 deletions(-) > > diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c > index 764f7c87286f..b740f38fedcc 100644 > --- a/arch/x86/kvm/mmu/tdp_mmu.c > +++ b/arch/x86/kvm/mmu/tdp_mmu.c > @@ -1162,9 +1162,6 @@ int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, > struct kvm_page_fault *fault) > if (fault->nx_huge_page_workaround_enabled) > disallowed_hugepage_adjust(fault, > iter.old_spte, iter.level); > > - if (iter.level == fault->goal_level) > - break; > - > /* > * If SPTE has been frozen by another thread, just give > up and > * retry, avoiding unnecessary page table allocation > and free. > @@ -1172,6 +1169,9 @@ int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, > struct kvm_page_fault *fault) > if (is_removed_spte(iter.old_spte)) > goto retry; > > + if (iter.level == fault->goal_level) > + break; > + > /* Step down into the lower level page table if it > exists. */ > if (is_shadow_present_pte(iter.old_spte) && > !is_large_pte(iter.old_spte)) Reviewed-by: Robert Hoo <robert.hu@linux.intel.com>
diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 764f7c87286f..b740f38fedcc 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -1162,9 +1162,6 @@ int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) if (fault->nx_huge_page_workaround_enabled) disallowed_hugepage_adjust(fault, iter.old_spte, iter.level); - if (iter.level == fault->goal_level) - break; - /* * If SPTE has been frozen by another thread, just give up and * retry, avoiding unnecessary page table allocation and free. @@ -1172,6 +1169,9 @@ int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) if (is_removed_spte(iter.old_spte)) goto retry; + if (iter.level == fault->goal_level) + break; + /* Step down into the lower level page table if it exists. */ if (is_shadow_present_pte(iter.old_spte) && !is_large_pte(iter.old_spte))