From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 439DBC25B08 for ; Fri, 5 Aug 2022 23:05:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241549AbiHEXFc (ORCPT ); Fri, 5 Aug 2022 19:05:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59398 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237177AbiHEXFX (ORCPT ); Fri, 5 Aug 2022 19:05:23 -0400 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EEC21277D for ; Fri, 5 Aug 2022 16:05:22 -0700 (PDT) Received: by mail-pj1-x1049.google.com with SMTP id oo11-20020a17090b1c8b00b001f285a3bdf0so5043884pjb.5 for ; Fri, 05 Aug 2022 16:05:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:reply-to:from:to:cc; bh=cVyg5lVhUGta27OyTveQuZSdsBeAtej8VaD6SjStUhY=; b=OBrKgXyIpckqO9CrRKQ6JD4KRVGxW16h0LR+qvoW/sZRw5MpW/Z9S0i8q2GProLabD U11zjkDbuoq485Mk9Gd/+WBd0Y7EDcsnfKEGq88nBSWANQXbpWNkzagKz8yzPTvahbgr Tx+W5fNIO9/woKPBCVsAR1d+3ya8ZuMcfUgqPC5wcdVXVlcbDMH07bemHy8Uc3zWnN88 yep++LgjoXTqfsrDX/l1pXFO0TlR2UuqX1RCPnZCmLK6gik8SrDD6XuOceyCetZ/Ec+S jHqPwi4f3xEfzKsUsShxmzbZT0pkQ9aGQ3hAMH6YuWAVcs2kQoxnYtEDMGqPPww34yeU wQVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc; bh=cVyg5lVhUGta27OyTveQuZSdsBeAtej8VaD6SjStUhY=; b=iJO5FVrmcFQ5FPKt1qfqLkck6LVlnMTzU1hScO+tJcw6CREPouqBrimqhId8/52MNK tpK0zLfm5Son2yMjYC1m4JhvnHAh2OMHsb/hnYEHb/Ve1HCYHPSDgsINHDcfUbcY16Pm oxagUzSzp0QfJUiNN2B6SYGkO4iPsZh66c8mYSdr0RHd3BFCSRaNBNZ0CPZvD6GByDwt pa6O4eSFHfIixEVmEg9c13p86jg9DT7S2kRXkLc9EsUzrzwMYsQBjVwWPDg4KNcIHYhI I1N8FrVJMzK8KAtUW8VEDh+3ZtTFMSSTe9J7W7dKjlfsJq1r/Yvh0lmCUOT8v9Qk7K5b HqEA== X-Gm-Message-State: ACgBeo0cl8LSBXFnhp2ubLWYrP9kDzF5MpLEgj5SiQ0FEIZnnrbWCxpy b8vEAXNE4bLLsbGafnGaShLTadiAFn8= X-Google-Smtp-Source: AA6agR6n7rwy6mGJvNzb2TddHLX9FDpvrM4ae0/FLkoU/yQ2ZlFbW1POomBPv4xPpQsAGD08UagtVoVsl78= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a05:6a00:27a0:b0:52e:316c:851e with SMTP id bd32-20020a056a0027a000b0052e316c851emr9010748pfb.68.1659740722006; Fri, 05 Aug 2022 16:05:22 -0700 (PDT) Reply-To: Sean Christopherson Date: Fri, 5 Aug 2022 23:05:06 +0000 In-Reply-To: <20220805230513.148869-1-seanjc@google.com> Message-Id: <20220805230513.148869-2-seanjc@google.com> Mime-Version: 1.0 References: <20220805230513.148869-1-seanjc@google.com> X-Mailer: git-send-email 2.37.1.559.g78731f0fdb-goog Subject: [PATCH v3 1/8] 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 , Yan Zhao , Mingwei Zhang , Ben Gardon Content-Type: text/plain; charset="UTF-8" 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 --- 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 3e1317325e1f..36b898dbde91 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.1.559.g78731f0fdb-goog