Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp6402987rwb; Mon, 12 Dec 2022 01:06:38 -0800 (PST) X-Google-Smtp-Source: AA0mqf7Iw7i5MtVv1Kl56iT9hInlsfTd3V/8JytcVGhCT7wSldmt/uGG3lqTJfk2sERZos9w47F8 X-Received: by 2002:a17:906:b114:b0:78d:f455:b4b6 with SMTP id u20-20020a170906b11400b0078df455b4b6mr14041975ejy.29.1670835998519; Mon, 12 Dec 2022 01:06:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670835998; cv=none; d=google.com; s=arc-20160816; b=Bg7AutasawhfthjGDm6PheDwJFvBAQSfR+2R6D5I1xZxK1p4B10F0hwNjXJCs0WXdj nXx+SAiiw7QbCxufWMx5jwYZzbY0JOHFPMksN6FWh8S2xLyJGPwB/7Tgpwdkcv4bqMnJ uBT47h7kqgG1iVkvB4qvBGDYHj+rXm5Z29RU+oaQOUlFhvA/2v87WZaQBDjLdb3H4Lvm u8x0cdwWFDf/7FfWrwAq42x0JNegjJke5lfHe3Vad9s+t/35uH937Jhp6xexTiuhETM0 gr7CvU83yUpe65cGapnQL8D2wzH+vBPnj6hi02KsuulYDYX9tnqQyOlNBuig3MGf/QZC WpKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=NsqQBlG7OALHs9p2W6AkND+AQ3ZkN//jvoUDNbWIbKQ=; b=U4UzxKyCSjC/k+zHIc3s33MHxD8wRWnb9CuLwqUV41agx5Xj1aozZlFpQTMWV5pPDB xzyKM/GyInE3fSiHzF9tSgQieR63eO3p8hbZTP2BsEkOZxKDCdsHUCAJKYilRYCa8MCN O0b7aC7izypTgmmc4sNhaQnRTA8pslX1CLwnV1h1nGzNpxC3Xg23t6ZdtwaSkgG9CfPL 9beeGtvcxBZ/Hi1ieuY4VDV9ComV6kW21DKYFjEAcgeJUdyyll/3O5half3qh15YpZpq 68SEzDvt+wum73Rgkau3SQSiFXUjIg1GEz8KTiG6YLG4gs3oj8d6OEg2+MA6rWBaz4+z Lrig== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=HufF+lFF; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ko22-20020a170907987600b007839bfdaa33si4465481ejc.358.2022.12.12.01.06.19; Mon, 12 Dec 2022 01:06:38 -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=@gmail.com header.s=20210112 header.b=HufF+lFF; 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=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231710AbiLLJAO (ORCPT + 76 others); Mon, 12 Dec 2022 04:00:14 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36392 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231690AbiLLJAL (ORCPT ); Mon, 12 Dec 2022 04:00:11 -0500 Received: from mail-pj1-x102b.google.com (mail-pj1-x102b.google.com [IPv6:2607:f8b0:4864:20::102b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 007FA6317; Mon, 12 Dec 2022 01:00:10 -0800 (PST) Received: by mail-pj1-x102b.google.com with SMTP id z8-20020a17090abd8800b00219ed30ce47so14974126pjr.3; Mon, 12 Dec 2022 01:00:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=NsqQBlG7OALHs9p2W6AkND+AQ3ZkN//jvoUDNbWIbKQ=; b=HufF+lFF8AUfjv0wnsSPAksVvIPcOML/MwkmnCkf8sbfeMw1cDXYkx+HSUcP50C2Qj OUa4ud1lBI7y7tS9+99H0dV5NFXUTs5maiwW8JtVBlAlv7F/k53HIC/cwirz8jBR0Gl3 HWnFcPaNfgkHqlooSq/HS6gipH1YnRrx0uYlhEsj5puSiEHbwZ1HJo+IaGHUmiXvprl/ WlMt+0l+bCZVpTXQ0mTavNI1Gt4ZdTOj+WHBY+u7XoLXmZaBIu6hfbnczzeOv9Ngl9R6 DxFjYGzjB1DDpHnWmGWPMOMWX6iia5BK7XdRmRmmK4Qu3meSiNgyyUfW4IjQsp/H5XGv bQKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=NsqQBlG7OALHs9p2W6AkND+AQ3ZkN//jvoUDNbWIbKQ=; b=z5YFsryKKnULLm60gZZ8cYCLd8/xUFLLzige6vV2TprXB49BhgI6r2Px13cgpidUil hzd3YMhmCM64lcibS5dsJ5Hyo60DCJsScPyT9ICnt2JXYn5DTeVND/1qS0Owj0MGBh9m GceAySEtWghBaQeuCCuNkah1T2dNlmM+SzdMG+d3cKFkOpudqB6IUgyikRAS0FbF6RFH pzjXCu5e9tFekY5jk3/no7+MXlvXOMdlsXyDTi7V9Fp/qvuTm60N+UlleDZ7YZuaavb/ EG2fGzbG16n0QKO9QlHMXJAvskHd2aqZUmY4S6A0yNH9fgqOeecrLA+etu1AubfFZ5+v lnrg== X-Gm-Message-State: ANoB5pl+JRpujkbZEp+sXzxxr/Gh2NaDoRSzFwQRRwZ73yfBzoEfXc+W B1HlLaW5lv/SI4jhI+8iDf3GeMbp9Rw= X-Received: by 2002:a17:902:7c8a:b0:189:ed86:178b with SMTP id y10-20020a1709027c8a00b00189ed86178bmr18625085pll.64.1670835610242; Mon, 12 Dec 2022 01:00:10 -0800 (PST) Received: from localhost ([47.89.225.180]) by smtp.gmail.com with ESMTPSA id e7-20020a17090301c700b00189bf5dc96dsm5771488plh.230.2022.12.12.01.00.09 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 12 Dec 2022 01:00:09 -0800 (PST) From: Lai Jiangshan To: linux-kernel@vger.kernel.org Cc: Sean Christopherson , Lai Jiangshan , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , kvm@vger.kernel.org Subject: [PATCH] kvm: x86/mmu: Warn on linking when sp->unsync_children Date: Mon, 12 Dec 2022 17:01:06 +0800 Message-Id: <20221212090106.378206-1-jiangshanlai@gmail.com> X-Mailer: git-send-email 2.19.1.6.gb485710b MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 From: Lai Jiangshan Since the commit 65855ed8b034 ("KVM: X86: Synchronize the shadow pagetable before link it"), no sp would be linked with sp->unsync_children = 1. So make it WARN if it is the case. Signed-off-by: Lai Jiangshan --- arch/x86/kvm/mmu/mmu.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index 4d188f056933..15d389370f88 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -2367,7 +2367,16 @@ static void __link_shadow_page(struct kvm *kvm, mmu_page_add_parent_pte(cache, sp, sptep); - if (sp->unsync_children || sp->unsync) + /* + * The non-direct sub-pagetable must be updated before linking. For + * L1 sp, the pagetable is updated via kvm_sync_page() in + * kvm_mmu_find_shadow_page() without write-protecting the gfn, + * so sp->unsync can be true or false. For higher level non-direct + * sp, the pagetable is updated/synced via mmu_sync_children() in + * FNAME(fetch)(), so sp->unsync_children can only be false. + * WARN_ON_ONCE() if anything happens unexpectedly. + */ + if (WARN_ON_ONCE(sp->unsync_children) || sp->unsync) mark_unsync(sptep); } -- 2.19.1.6.gb485710b