From patchwork Wed Oct 19 16:56:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 5762 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4ac7:0:0:0:0:0 with SMTP id y7csp433012wrs; Wed, 19 Oct 2022 10:00:42 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5AiDgb6WdzAebi1C1plA05E0VJQpXkcuVhVoBlbIBAHzz2vXAlka+v84MLsVl2BtKk1yz8 X-Received: by 2002:a17:907:6e11:b0:78e:3057:f631 with SMTP id sd17-20020a1709076e1100b0078e3057f631mr7450854ejc.333.1666198842272; Wed, 19 Oct 2022 10:00:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666198842; cv=none; d=google.com; s=arc-20160816; b=nXWPz/WvaVDZK4EbqaJfz8vq7Ug2uBR9Ksboc4eciVc8EBfMWu+29TlQfojU9zvF+x zjUqll+ZAUGy0NijOs7Yzy2tEzwTqPEtwQVDtuxatk5fnr8nFmueEG7J6u3sOjB81QQc CdZatFcb0vJezeEjROBIJy37ZsOr89YVWdWFTs9N00TBBd2wa2BsUrkXfaqZYi4YSKpq jSLjR6zCEoLFwvbct7Oej4sRqwfBVQZJoqO00ORk0UHcOK2LZkmdsil9l0LocauG5fuh WFDeRW+iHl20d6YZtoNQ73cQrOPPog4XAQLlcu3p48w5E9dh3AlfPnIbX8g8xTD8umDw DYGg== 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=zolBZdZc8YdUGOdwe6gjYM21Hp1u8s0GmGxgf32zoYY=; b=MzEaYA2pHBhsLqSRe+w89eR6QEofFP8CTceLzT81sWT/SDJlDZ1Sb9wtaLzf0L8EH3 t8xRFfLXztpd0SKeuFc5A/s2os7pjWaM7FqkG+35y3AnXNZvTQ7SAmslwp0rPDlWDfPs tXpZuTawNdk2/GxlI2zOKzFa15j9mqQMhR4YJzwA5ZjX01cX9isKYTw1+gBn+lNJbmd9 dLB31v4ZQ5zxhAjl1eysN6l4Rny3ORbCt04u1i3nlHbPxQHd/im5GBBdyiVij64zXlJQ aslCiJU+FchpZSge0gvCH5Olhg8OlD5Qi4JExx0rDkatYMYa33KUTaCbvffAjPwNaUN/ 8IOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=aLnzkHpD; 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 js7-20020a17090797c700b00790058488d3si11910915ejc.89.2022.10.19.10.00.11; Wed, 19 Oct 2022 10:00:42 -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=aLnzkHpD; 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 S231591AbiJSQ5M (ORCPT + 99 others); Wed, 19 Oct 2022 12:57:12 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37878 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230517AbiJSQ46 (ORCPT ); Wed, 19 Oct 2022 12:56:58 -0400 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C97FA1D0D4F for ; Wed, 19 Oct 2022 09:56:37 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id y65-20020a25c844000000b006bb773548d5so16649901ybf.5 for ; Wed, 19 Oct 2022 09:56:37 -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:subject:date:message-id:reply-to; bh=zolBZdZc8YdUGOdwe6gjYM21Hp1u8s0GmGxgf32zoYY=; b=aLnzkHpDpkeBNhxgUkhiqgxKHHtY4ZbhvNY3bJhR0ovSRwtOSLtNKKCjvs1PDtXMUm eajcWDo93u7FNylqbddyXHZXnxbWOSBdTj4/5V9+IDyPKawo2MPzEFH/OpvcILanRjiD gbDCKj3AHS+JtcoCV39QmB0z7cGG7NkGppT/yxeMaseTYyjdsgZAA2RQq/tVesYvGjpA 5FtfPIyuDpTIF9SAvKoNjSXl7TLkVUpl9hHutCkSkuAGWnBF+aJDh3/BM01cJb17gk4y 3mBir7X7QBpyDRK+6zPStUPgfESc3jrBc+sa9GIY7ZNLR548FGyXpHKCSd0M3D4cXO4l 8A9w== 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=zolBZdZc8YdUGOdwe6gjYM21Hp1u8s0GmGxgf32zoYY=; b=TLQMzEfk+NBpjsiQcVoGe79LyIDM32PdTaKFfSno6qy3uSmVHEiPmZFn8MC/dVklH+ o5JzRHrVMeJkLj7Zw8c8TaPvRXAwO71VK3j8oMY9S83ZpDUG2tWaBXF9X2FAllFCOJ9q NJSVd+JTuskI86+Xm6k36RKxjX4E20bSH4vv6IoGDBrDHLiHK9H6EV1Imjn+rPTqS1ez h9WKKvcv02vbtDXsHiIQcIyRlenLZU1wXTDbhDTJTh1+SfAbiGW8fCvfmP1MLjniFyiL l0tFpCB6w6QDaCsl/+hVkIwlCR0j7Ub1DGrpFf0iVeJjX3tlLBYhWbMcmWjp1JzCS+kb BYXg== X-Gm-Message-State: ACrzQf0Z0E1hTGrN9gLLK4BgaPPKRMqoBthiJ2BCrlEr19O4njNBYIAV kwkN0jrUBs0DoQ5iyls9amRI1A69jQI= X-Received: from zagreus.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:5c37]) (user=seanjc job=sendgmr) by 2002:a25:bfc2:0:b0:6c0:fec7:ae64 with SMTP id q2-20020a25bfc2000000b006c0fec7ae64mr6946686ybm.366.1666198596284; Wed, 19 Oct 2022 09:56:36 -0700 (PDT) Reply-To: Sean Christopherson Date: Wed, 19 Oct 2022 16:56:18 +0000 In-Reply-To: <20221019165618.927057-1-seanjc@google.com> Mime-Version: 1.0 References: <20221019165618.927057-1-seanjc@google.com> X-Mailer: git-send-email 2.38.0.413.g74048e4d9e-goog Message-ID: <20221019165618.927057-9-seanjc@google.com> Subject: [PATCH v6 8/8] KVM: x86/mmu: WARN if TDP MMU SP disallows hugepage after being zapped From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Mingwei Zhang , David Matlack , Yan Zhao , Ben Gardon 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=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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747136117044317905?= X-GMAIL-MSGID: =?utf-8?q?1747136117044317905?= Extend the accounting sanity check in kvm_recover_nx_huge_pages() to the TDP MMU, i.e. verify that zapping a shadow page unaccounts the disallowed NX huge page regardless of the MMU type. Recovery runs while holding mmu_lock for write and so it should be impossible to get false positives on the WARN. Suggested-by: Yan Zhao Signed-off-by: Sean Christopherson Reviewed-by: Yan Zhao --- arch/x86/kvm/mmu/mmu.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 14674c9e10f7..dfd1656232ad 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -6864,12 +6864,11 @@ static void kvm_recover_nx_huge_pages(struct kvm *kvm) struct kvm_mmu_page, possible_nx_huge_page_link); WARN_ON_ONCE(!sp->nx_huge_page_disallowed); - if (is_tdp_mmu_page(sp)) { + if (is_tdp_mmu_page(sp)) flush |= kvm_tdp_mmu_zap_sp(kvm, sp); - } else { + else kvm_mmu_prepare_zap_page(kvm, sp, &invalid_list); - WARN_ON_ONCE(sp->nx_huge_page_disallowed); - } + WARN_ON_ONCE(sp->nx_huge_page_disallowed); if (need_resched() || rwlock_needbreak(&kvm->mmu_lock)) { kvm_mmu_remote_flush_or_zap(kvm, &invalid_list, flush);