Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp349174iob; Fri, 13 May 2022 03:08:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7cOXy7ZXr84Q/65WsZgV2A28/hbrjW4AUFfW8z3ZNi5NyeaxQP39quHRTWELwjNrGksTQ X-Received: by 2002:a17:907:62a1:b0:6da:7952:d4d2 with SMTP id nd33-20020a17090762a100b006da7952d4d2mr3533701ejc.260.1652436487589; Fri, 13 May 2022 03:08:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652436487; cv=none; d=google.com; s=arc-20160816; b=hpxgFRrNWaZ77SItLp7vlQNtge4jymmrX92gAHCtHa4vNLpehWJLuHpWKn9A0/pSeF PjX898EfbMepSRedPdS9MSKXj50JyLz8h76FKYNixMnpMoW3YBCsdqQgcl4r/8zsGofo BET/5M9htUSh2hQz+0Qatj3ehQXrhQGyTCJPQMw1SxSjCKFCuBY7UVq5Cdm0BYUyh3z5 mLeHbVhr+xVvp0iyhcq+kidot3dQ9OmSrlP3yXSFDRwaErmn08w4gGiO0HhphYDZ3DEG NjiMI/D9dc+OGCeTBvbmvIyekQfVqtb7sxSwGH08qugs3gCbP3y7I572ELlYH83xcZAP 3lmA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=nOLcuBx81l3T4akJ0OxMVdpq9MkOLHyLkjcSUt3VELs=; b=veSy4C1LQmJRdicvClN27ojP0ntNhwtmuYPksdw1HsHMA388L5XbGv1EbYiTh95K3V 1GtyHxiuj2KriZrSBqIoqE8MB8PSJPtd7DAoGHpNTkZzv8YChGN7cmmJCLpwshbtPsrb NxSEm9uIjfinQO11t7fsschOKZ5c5DF2d9O2miyT/lHdr9BhsR9VJ6dvumU02Ta4QkIL 9P0eUkDiG/t0C5mbwQ5ICbAtTyyG7Tq8nGJqxzDaGps44brLqS0EAg62+5gV0GpMmsNA J9oB3un8wXMpqHDCu/zJvCrtg9KF9Upy3Tdz5xKwiFkGrLt/BUBA3vzV92K3on+UlPz2 Tdjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=D6xPM6wQ; 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 qw33-20020a1709066a2100b006fdefd986ecsi1754233ejc.242.2022.05.13.03.07.40; Fri, 13 May 2022 03:08:07 -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=@gmail.com header.s=20210112 header.b=D6xPM6wQ; 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 S1378637AbiEMIyi (ORCPT + 99 others); Fri, 13 May 2022 04:54:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37948 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344569AbiEMIyg (ORCPT ); Fri, 13 May 2022 04:54:36 -0400 Received: from mail-yb1-xb36.google.com (mail-yb1-xb36.google.com [IPv6:2607:f8b0:4864:20::b36]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 183882B09D4; Fri, 13 May 2022 01:54:34 -0700 (PDT) Received: by mail-yb1-xb36.google.com with SMTP id i38so14123025ybj.13; Fri, 13 May 2022 01:54:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=nOLcuBx81l3T4akJ0OxMVdpq9MkOLHyLkjcSUt3VELs=; b=D6xPM6wQ7LbuBMKZwulpmITdzxO1wq9SYBVgycLpxFBm9iCGPStRJ2Mesmnb0HgOYz re/WmnImOZFr2VPThcsAWFxr+2VdMbRe/8C6yjnMxya+olpVal+bE11Vkar3WBWGy0LE WNcXJeSxDuG7TRxar6Stg8+6JIYwSVBjuW8coCqn3Ym+xBj5DvKmmgYPyqT/JnEw48yj BOba6JKhxaHRhRH393iYsmVCYQ85nTrIi7ieZhXB9ByRLjRAQF1MKJv76yTmjNswNd2g TPLyGmkTDEdS0EwReMPNS1/0xBkCDOszsbGg+W69oyT1eAFdBoxzMKf9VNPHZiTCTH+S G0tw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=nOLcuBx81l3T4akJ0OxMVdpq9MkOLHyLkjcSUt3VELs=; b=V+b8qB1BvsUjzhxdCzmCkYL+T+HOqEzcDgBPvhZlSDU6hn6SqWEC5dfyOIobLTgFU6 mlp3/lNHvosZ/J4CPDKDPUlisF38jyXWGs9b6H7Ku3QABs6/WCHr9dJnuV2Vlmr9PDsp gH2KkwStpxXK+qyK2i5EWtkI0pXzo8PAD/J0M9X6TEaz6aOg3Ab/Wq834PoOEwZoG40m gATvP6C64fbOW/kGtftAY55OHWksedbfUn90lV2VpG/r0RTWN2B/c++n/J80b4ubvp7f fh5uoqFsgPTn7gt9IIbGS7c/uMyQF2Q5Rd/PzqWsTbtSBOhsWhaRrOCY3x6LrAfL73Ph YxTQ== X-Gm-Message-State: AOAM5338T0tKbUVZxQxCr8GypehpH4+AV3jNUxdIIvk3n97ko1dswCYM pgmZ9dF3Fg1TYkXAPxl6UzjHjPoGmcwbNXTzdfEGS4RU X-Received: by 2002:a5b:81:0:b0:64a:f6d1:dc7f with SMTP id b1-20020a5b0081000000b0064af6d1dc7fmr3791799ybp.352.1652432073258; Fri, 13 May 2022 01:54:33 -0700 (PDT) MIME-Version: 1.0 References: <20220415103414.86555-1-jiangshanlai@gmail.com> In-Reply-To: <20220415103414.86555-1-jiangshanlai@gmail.com> From: Lai Jiangshan Date: Fri, 13 May 2022 16:54:21 +0800 Message-ID: Subject: Re: [PATCH] kvm: x86/svm/nested: Cache PDPTEs for nested NPT in PAE paging mode To: LKML Cc: Lai Jiangshan , Paolo Bonzini , Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , X86 ML , "H. Peter Anvin" , Marcelo Tosatti , Avi Kivity , "open list:KERNEL VIRTUAL MACHINE FOR MIPS (KVM/mips)" Content-Type: text/plain; charset="UTF-8" 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,T_SCC_BODY_TEXT_LINE 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 On Fri, Apr 15, 2022 at 6:33 PM Lai Jiangshan wrote: > > From: Lai Jiangshan > > When NPT enabled L1 is PAE paging, vcpu->arch.mmu->get_pdptrs() which > is nested_svm_get_tdp_pdptr() reads the guest NPT's PDPTE from memroy > unconditionally for each call. > > The guest PAE root page is not write-protected. > > The mmu->get_pdptrs() in FNAME(walk_addr_generic) might get different > values every time or it is different from the return value of > mmu->get_pdptrs() in mmu_alloc_shadow_roots(). > > And it will cause FNAME(fetch) installs the spte in a wrong sp > or links a sp to a wrong parent since FNAME(gpte_changed) can't > check these kind of changes. > > Cache the PDPTEs and the problem is resolved. The guest is responsible > to info the host if its PAE root page is updated which will cause > nested vmexit and the host updates the cache when next nested run. > > The commit e4e517b4be01 ("KVM: MMU: Do not unconditionally read PDPTE > from guest memory") fixs the same problem for non-nested case. > > Fixes: e4e517b4be01 ("KVM: MMU: Do not unconditionally read PDPTE from guest memory") > Signed-off-by: Lai Jiangshan Ping