From patchwork Mon Dec 12 09:01:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lai Jiangshan X-Patchwork-Id: 32273 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp2128893wrr; Mon, 12 Dec 2022 01:05:31 -0800 (PST) X-Google-Smtp-Source: AA0mqf7AxjaYiTr6XGMQvrSmTi+bkET9AB9OCtkXJfSpo8tztflK9v793c4rK2dVqUjy8zFj3+zX X-Received: by 2002:a17:906:4a56:b0:7c1:4a3:10b6 with SMTP id a22-20020a1709064a5600b007c104a310b6mr12737759ejv.53.1670835931135; Mon, 12 Dec 2022 01:05:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670835931; cv=none; d=google.com; s=arc-20160816; b=RWpHM1cU6QTNpy1LAZ298d2eQvkV8J8zKa9kn9qUybRlbAc8Mje39gv3kosaw32R05 cc7MdcHyEpcBIHmRG7elpLP3E4b32dmUQ7EFP4bD6+SHsZN7VpP9xrZS1Dk2sm3utH5d 6Ur14MneKC0xQjD1kPKjcb74uhZftvfcfnkqHYyz3cDMNgwDwQD5yODMCTdPpEC6D3Tk PFQPAiy0tu2fLvCPSS38H1xmm8WmE/dxwI1HmF/dJxgpyxezwYxtAs05sza5HRIHQ9rt MnHeRxGc6hT3U+MdwdSAjV96T/fkDpFqHvrkpOfOKXC1tN4H0+Hrx8jH17ysPZQuWOnp n6aA== 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 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.05.07; Mon, 12 Dec 2022 01:05:31 -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 + 99 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1751998457069538346?= X-GMAIL-MSGID: =?utf-8?q?1751998457069538346?= 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); }