Received: by 2002:a05:6358:45e:b0:b5:b6eb:e1f9 with SMTP id 30csp4790428rwe; Tue, 30 Aug 2022 17:35:56 -0700 (PDT) X-Google-Smtp-Source: AA6agR5iGza3j/BVZnvhv1q6XaHAUOcXPzqahVRvMgBE3sVuZcb1acX3Fq8vKR4vAfvvOljES7+k X-Received: by 2002:a05:6402:348f:b0:448:6005:68af with SMTP id v15-20020a056402348f00b00448600568afmr11223783edc.184.1661906156377; Tue, 30 Aug 2022 17:35:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661906156; cv=none; d=google.com; s=arc-20160816; b=MtpE36BKTcuW4abKBLN9CZcpr8ZxNLIqHrZ4ZzeuVIAn5W7S1sXEwXI6E0cPHWtFxO x3gPRweBSg/tk/yIfmq8Sen8CwJShaIieG7XE0hfmqHzWFLtoc+K8K+3jSKhinGSiMe+ 9nkc2wsR092EQY3T0sICNEEw+ZS0G11fzuEdehk1xcD6xxs2RN+lgPoHkX+4SoY0AH/7 +RSd3s0aVeG9F0by0SIQx24zujGQQl/8KfKhw0XJT4yE6g83HyorEvXyqhpd5yRdvwSa yS6cOZCfZcHO0Y6HlpyTq30ybj/cVkiW+ude/amlqwqVttlVS0tpM1Yn3yuRfOtKClUo yX8g== 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=KwSYCZerlx8jq2QaoSW9rJT1jqCtPnDeeiOJE8jfST4=; b=qA/Rw1YNJwQf3TEG1E3TVybqH7iV/sKSRu3ktVbQMcsNI94MnvBTAEHK/mK3t/drTp b7qGXmJyRoHMwxTYeJfWqUrDbJHQ2ol8nEcff2FiwcipJxNbe4u3c3zYuWlfZd3iyp1H c/Ponf2HFUxQTlX7zXoKPahOnOOE2tJGN9BmuOGU00lVkVOGKIz4tBnfzY9ZGxk2jCSM sK6mUGFk516u1A6bfHBujWBh0iVGhgd8xA894F4o/HXxy9RRegHxDooBoximcowiOtfz XJb/HiyNo0yed3GeFKwRgfdrNgs/McB+K56bFVtnKdr48U6osd4jvRCEF64f0GflLJ1A 70kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=BPH+iO6g; 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 dy16-20020a05640231f000b0044756d7defdsi8366428edb.613.2022.08.30.17.35.04; Tue, 30 Aug 2022 17:35: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=20210112 header.b=BPH+iO6g; 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 S230292AbiH3Xzp (ORCPT + 99 others); Tue, 30 Aug 2022 19:55:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51778 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230093AbiH3Xzm (ORCPT ); Tue, 30 Aug 2022 19:55:42 -0400 Received: from mail-pl1-x64a.google.com (mail-pl1-x64a.google.com [IPv6:2607:f8b0:4864:20::64a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9984D2ED5A for ; Tue, 30 Aug 2022 16:55:41 -0700 (PDT) Received: by mail-pl1-x64a.google.com with SMTP id s8-20020a170902ea0800b00172e456031eso8776762plg.3 for ; Tue, 30 Aug 2022 16:55:41 -0700 (PDT) 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; bh=KwSYCZerlx8jq2QaoSW9rJT1jqCtPnDeeiOJE8jfST4=; b=BPH+iO6gDGCsp2Wcx1LYWuE/INfoeSg5h3VFyT2+38gryYDiRQNbYYVwlMT78ungxP uhH+zRrer8VCaDfUCOCZIBNmaRpGl8JFqhjto1VWg3595CY+538Oa5oLaTTGSZUOcTrx QmvyynMrgDUdcIUJAcBzCpeO9UY3gTlHOAfaFOQD9qfZr2BxPj/X7k0u36MGUUwFLb/D 3WJmTeRSqrkAK7oOeT0dGuQWP8LbfSWn8mXsflZgNJzq3/hGQ3Bx7/Qh90pQ0vUwCZt7 pl0QmujrSQkoPGrx/eThrTz9cTK3ObEIsit1R1QXl2WXj2YSj+wze22tC2CAXttiyjYT XjoA== 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; bh=KwSYCZerlx8jq2QaoSW9rJT1jqCtPnDeeiOJE8jfST4=; b=4sms1aO8Vbv/KiH/fH8mXkWnKzHR//stWTZxlb/UMwvDUPODKB0tfP8R93sovt0qII 9y2J1Z1oIe/kSe3rs8GbmQ5GN2XCKrK1b+U01bukBm3ybgjvIBO41lmeOeOsXMynevSj WM1oWgIyd3GOFYcQ3CYM5zk/nyne1FdtVSkDAnHY4FH7WiOpbKDhpUmNDJScK6Tf8ium 6gnzb50OX1xxcPcUAiPKQMagfxkNIniyKuCMhyStE7SnL4+TuZc4OkxuvXEneyxJkDAX /LHEG/BiRE8QB8sMsUkK0ocVPYeHpOMTY/Wo+qxDlO5PtSo73EB0EFzesyeFm2Uw0VKO 5QGA== X-Gm-Message-State: ACgBeo2vv6TjIBaHjZ7Q0U0xXZ09CRtX+lLXcq1TKmU/OR3Zls1JFZ3J on8Xq1VDxMwtzUIAqoEukuwevf2NHhg= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a62:5ec6:0:b0:538:3aa:7fe5 with SMTP id s189-20020a625ec6000000b0053803aa7fe5mr16255558pfb.73.1661903741190; Tue, 30 Aug 2022 16:55:41 -0700 (PDT) Reply-To: Sean Christopherson Date: Tue, 30 Aug 2022 23:55:29 +0000 In-Reply-To: <20220830235537.4004585-1-seanjc@google.com> Mime-Version: 1.0 References: <20220830235537.4004585-1-seanjc@google.com> X-Mailer: git-send-email 2.37.2.672.g94769d06f0-goog Message-ID: <20220830235537.4004585-2-seanjc@google.com> Subject: [PATCH v4 1/9] KVM: x86/mmu: Bug the VM if KVM attempts to double count an NX huge page From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, David Matlack , Mingwei Zhang , Yan Zhao , Ben Gardon 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,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_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 WARN and kill the VM if KVM attempts to double count an NX huge page, i.e. attempts to re-tag a shadow page with "NX huge page disallowed". KVM does NX huge page accounting only when linking a new shadow page, and it should be impossible for a new shadow page to be already accounted. E.g. even in the TDP MMU case, where vCPUs can race to install a new shadow page, only the "winner" will account the installed page. Kill the VM instead of continuing on as either KVM has an egregious bug, e.g. didn't zero-initialize the data, or there's host data corruption, in which carrying on is dangerous, e.g. could cause silent data corruption in the guest. Reported-by: David Matlack Signed-off-by: Sean Christopherson Reviewed-by: Mingwei Zhang --- arch/x86/kvm/mmu/mmu.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 32b60a6b83bd..74afee3f2476 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -804,7 +804,7 @@ static void account_shadowed(struct kvm *kvm, struct kvm_mmu_page *sp) void account_huge_nx_page(struct kvm *kvm, struct kvm_mmu_page *sp) { - if (sp->lpage_disallowed) + if (KVM_BUG_ON(sp->lpage_disallowed, kvm)) return; ++kvm->stat.nx_lpage_splits; -- 2.37.2.672.g94769d06f0-goog