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 BDDB2C433EF for ; Tue, 14 Dec 2021 03:12:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235407AbhLNDMj (ORCPT ); Mon, 13 Dec 2021 22:12:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48254 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232655AbhLNDMi (ORCPT ); Mon, 13 Dec 2021 22:12:38 -0500 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 31711C06173F for ; Mon, 13 Dec 2021 19:12:38 -0800 (PST) Received: by mail-pg1-x52d.google.com with SMTP id m15so16199948pgu.11 for ; Mon, 13 Dec 2021 19:12:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=DaUpjQsRXzDlNok3onB0tnTkJffX5UHYJGcB3WC+79I=; b=n/GrE6WqmC75O6tMABEgMi0icLtjq1J/sVwOqg0xtjO22NaCgBcN5l4O1X30LDcOWL tgRIRyjgwcjGqMWJ4+fhXiupYbO79FF6zhbtlLLEalFGUFe1SXdKengeNBji3XDUJD+q 3K465B4EC5w7R2ro5iynpzXLn6VdQHus524cczmRzZm5UW67WsVQ+HOMLcntdn9f90P7 gAJoy+vA2Vp3bZFfPmBO5TOWgYuCU1Fh6fmqSH81uPBw9fLeveOG14khDDCRIHZcRZ+R 9Y2DnSnd/PkioGxmHLt/8RJuRZg/tomtoZP0YaW277jW7ZK5DbEKbO+672gEP61Mmd91 1xoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=DaUpjQsRXzDlNok3onB0tnTkJffX5UHYJGcB3WC+79I=; b=RqGzXK7SY+lW0Aar2tWKI730/TdBBgkIsWuFfRp4/YCBVrzaISXJCNN6iNOaAiWQd7 ZyeiD6DiyLIf53DfPG4aQw8vZWtxdgxo9WPZV9DGuSw4k8Br3jDvcK8dK0QqWFZ0Rgvs AHSxoM0W9jAGLWQ2uSHeTdLKA7FLnWQHhEPShzgFouXyoRnJdKsR8VPtbWQCLAbbNMbR YWKj/e2wx/DnDyLiTH6uAa1suyMxZqbfqsXzRwzPAcq5PoScan9mQ3gdPn8WN47+/CHl vQtdAYy7jzvDj3UoOm6IT0XF2zMeqJRwalgI8DNGvPR6HYAZ+g8sJcoKXsyMbiysMhfP q6BQ== X-Gm-Message-State: AOAM532xM/U5DAGV1MzJCKC6VMLojPCc7ChwLM5OZLKF9wTCPmTfLQk3 GFvx5Rou/sfDQyy8v6PEazCa9w== X-Google-Smtp-Source: ABdhPJxHgZ7+unda1WxLgv6UMe8FB2suboBfBniZ7oOLB/b+GY1BhQC1gNcfoKtYxYoLRDxeG1OxkQ== X-Received: by 2002:a05:6a00:1c56:b0:4a4:f8cb:2604 with SMTP id s22-20020a056a001c5600b004a4f8cb2604mr1910174pfw.34.1639451557474; Mon, 13 Dec 2021 19:12:37 -0800 (PST) Received: from google.com (157.214.185.35.bc.googleusercontent.com. [35.185.214.157]) by smtp.gmail.com with ESMTPSA id u22sm14990479pfk.148.2021.12.13.19.12.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Dec 2021 19:12:36 -0800 (PST) Date: Tue, 14 Dec 2021 03:12:33 +0000 From: Sean Christopherson To: Ignat Korchagin Cc: Paolo Bonzini , linux-kernel , kvm@vger.kernel.org, bgardon@google.com, dmatlack@google.com, stevensd@chromium.org, kernel-team Subject: Re: [PATCH 0/2] KVM: x86: Fix dangling page reference in TDP MMU Message-ID: References: <20211213112514.78552-1-pbonzini@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Dec 13, 2021, Sean Christopherson wrote: > On Mon, Dec 13, 2021, Sean Christopherson wrote: > > On Mon, Dec 13, 2021, Ignat Korchagin wrote: > > > Unfortunately, this patchset does not fix the original issue reported in [1]. > > > > Can you provide your kernel config? And any other version/config info that might > > be relevant, e.g. anything in gvisor or runsc? > > Scratch that, I've reproduced this, with luck I'll have a root cause by end of day. Ok, the root cause is comically simple compared to all the theories we came up with. If tdp_mmu_iter_cond_resched() drops mmu_lock and restarts the iterator, the "continue" in the caller triggers tdp_iter_next(). tdp_iter_next() does what it's told and advances the iterator. Because all users call tdp_mmu_iter_cond_resched() at the very beginning of the loop, this has the effect of skipping the current SPTE. E.g. in the "zap all" case, where iter->level == iter->min_level == iter->root_level, we effectively end up with code like this, which is obviously wrong once the complexity of traversing a tree is simplified down to walking an array of SPTEs. gfn_t end = tdp_mmu_max_gfn_host(); gfn_t start = 0; gfn_t last; for (i = last = start; i < end; i += 8, last = i) { if (cond_resched()) { i = last; continue; } sp = &root->spt[i]; zap(sp); } Patch incoming...