Received: by 2002:a05:6602:18e:0:0:0:0 with SMTP id m14csp790564ioo; Thu, 26 May 2022 15:09:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzF6GsH9EmRBk454TbYBXdUMTYYNJ2AhaKpdwUu9WBWTqNqDLYKoreDNpDUE0I1GZ570jSK X-Received: by 2002:a17:902:f647:b0:161:67af:6bf0 with SMTP id m7-20020a170902f64700b0016167af6bf0mr38290124plg.100.1653602993663; Thu, 26 May 2022 15:09:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653602993; cv=none; d=google.com; s=arc-20160816; b=gX1Xd7EYrxjtHTqoN9bJWe8Ex2q3ZRgMHKrvBi35mJS5cgExZZeJZwuh+1jdiIQx2j sgqah6zNnxWy24Ul2D6lU42EX1SLyBtZJPE6TjeXEMRZfjXHW7dNGIReOfxPVZWTE0g6 zjJ5GLhlUl6Oe1vNoh/QzFYQTUUB/E3eQHjAqG26aoRYSXMJLakJjeii64m1eVCrEqdh 70oT6Vy1uaCYKyIVo4rE7fNT1Fg8xOhnfD1wxKX8mxBvEccwYN6qJb37Lovf2mn/zMbE gm+1FzQnNum2+VhwUGdi2+w1SsIazIsYDsLSw1DLXUy8hqaUV1DT0Iu1Hjw6PZ+bn+W+ egRQ== 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=j9xQMdzHNoTHZ+UFq3AI9FpCr84h47csBpAVGEWrE6E=; b=HxQHje3qNdqSZnM97E2ZNWd9W3wvx0bMuwqQTqbOFStLi2aHn7tfmCRqjFtLZ8hOt1 uzI+8cajoSF0bJlIIaPvBk1/uS5WOd10dTIli/2JxgMAc5ZOJkf+dBSPw69svACTuZ2k RSh6OVKDme6l304fPsHZ9lAlYmRVlXKncfLhAJ7bwCn+EfudKhOT1U2n+qLONV0Z6GDf hNvuzCAntIt7MW0HsSh6qY30x5N0fZbw/MefuwXdvNgQUOUKnfFt2U8PduS8H6P9aGe7 NmAB+b9USOsFisSSZfCw2n3RJEycGd8Z3vet9qkprhO3laVS8x3XO28ejrqvg7/u/hjo Cx0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=gKUCA8XR; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a11-20020a17090abe0b00b001dfef58d071si457115pjs.124.2022.05.26.15.09.41; Thu, 26 May 2022 15:09:53 -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=gKUCA8XR; 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 S1348060AbiEZQAp (ORCPT + 99 others); Thu, 26 May 2022 12:00:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58318 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1348049AbiEZQAo (ORCPT ); Thu, 26 May 2022 12:00:44 -0400 Received: from mail-yw1-x112b.google.com (mail-yw1-x112b.google.com [IPv6:2607:f8b0:4864:20::112b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3FAE69346B for ; Thu, 26 May 2022 09:00:42 -0700 (PDT) Received: by mail-yw1-x112b.google.com with SMTP id 00721157ae682-300beab2b76so19872887b3.13 for ; Thu, 26 May 2022 09:00:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=j9xQMdzHNoTHZ+UFq3AI9FpCr84h47csBpAVGEWrE6E=; b=gKUCA8XRy/7JOvVldrZ98O5RkwoNOFqFfVJCWQmSpHW+tyi++EKfJ8iAHZiR6KWIB/ eXPp+A43o7gNeTUt2iC4vaJCbp0efqZjXXQLa7Tg62DEzFcMgqR6cljQP7gFMTtrDidc BNsQwJ8T+Jc8UoPqH4rvET9kMgjUG6HS58z9KlosNdNDsRoFLLizwJfFW8is630RPsli vXd+xbKl+O+glH18i+BmZles82K3xg7eviCZDURpyevjzFXUnoffDQ4aAO+z/XSWGWBe /ZeB5HMPgOpniKQud0ZvZJSChAmbL/Ey7iUHW3OaKL2ygAWzbPhE2+8PAVdS+xCdJSmW kwkg== 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=j9xQMdzHNoTHZ+UFq3AI9FpCr84h47csBpAVGEWrE6E=; b=YC/+9Cxy0CtuCWRrJ4pKfLNxmma717O4zHV8FS2MIv1MgCntOTtDGDDP6f0Yv+6BlR xvIcIVoesABu+fiUR3ij6i0a+yqk0dRqtJn03cYzC3Sk3EzzGBMhleyJgCk579c5q007 fl5by7gZsYnt0b6LEAtmLHSGrq5RZZoIeHgdiO8JrGXk7XWbW5Ac8E13JxHy1wB2/fMD YpgdS85xC8Yp/ZAGqP9jFkoYzqx0ci5RHiqJfVXSq8suHLIrETScxJZTvsKirp988xRF 06wJXqDPcPlm5LVCIpH8h6nAJud5U6yolgv+6N1HTjL5O+7CNQU68H+MTNLn/0HzJ5RG yYcg== X-Gm-Message-State: AOAM531Ou2B+C+rTsNDADQ9FQHPn4equEJBMxnB5uOCfip3ZHSZrGy4V MOuDoCG9CdQN0IXldQLp5fLgb840KSoSDthDcEc/2w== X-Received: by 2002:a81:3696:0:b0:2ff:2dc1:3a05 with SMTP id d144-20020a813696000000b002ff2dc13a05mr40469644ywa.478.1653580840998; Thu, 26 May 2022 09:00:40 -0700 (PDT) MIME-Version: 1.0 References: <20220525230904.1584480-1-bgardon@google.com> In-Reply-To: From: Ben Gardon Date: Thu, 26 May 2022 09:00:29 -0700 Message-ID: Subject: Re: [PATCH] KVM: x86/MMU: Zap non-leaf SPTEs when disabling dirty logging To: Paolo Bonzini Cc: Peter Xu , kvm , LKML , Sean Christopherson , David Matlack , Jim Mattson , David Dunn , Jing Zhang , Junaid Shahid Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_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 On Thu, May 26, 2022 at 8:52 AM Paolo Bonzini wrote: > > On 5/26/22 16:30, Peter Xu wrote: > > On Thu, May 26, 2022 at 02:01:43PM +0200, Paolo Bonzini wrote: > >> On 5/26/22 01:09, Ben Gardon wrote: > >>> + WARN_ON(max_mapping_level < iter.level); > >>> + > >>> + /* > >>> + * If this page is already mapped at the highest > >>> + * viable level, there's nothing more to do. > >>> + */ > >>> + if (max_mapping_level == iter.level) > >>> + continue; > >>> + > >>> + /* > >>> + * The page can be remapped at a higher level, so step > >>> + * up to zap the parent SPTE. > >>> + */ > >>> + while (max_mapping_level > iter.level) > >>> + tdp_iter_step_up(&iter); > >>> + > >>> /* Note, a successful atomic zap also does a remote TLB flush. */ > >>> - if (tdp_mmu_zap_spte_atomic(kvm, &iter)) > >>> - goto retry; > >>> + tdp_mmu_zap_spte_atomic(kvm, &iter); > >>> + > >> > >> Can you make this a sparate function (for example > >> tdp_mmu_zap_collapsible_spte_atomic)? Otherwise looks great! > > > > There could be a tiny downside of using a helper in that it'll hide the > > step-up of the iterator, which might not be as obvious as keeping it in the > > loop? > > That's true, my reasoning is that zapping at a higher level can only be > done by first moving the iterator up. Maybe > tdp_mmu_zap_at_level_atomic() is a better Though, I can very well apply > this patch as is. I'd be inclined to apply the patch as-is for a couple reasons: 1. As Peter said, hiding the step up could be confusing. 2. If we want to try the in-place promotion, we'll have to dismantle that helper again anyway or else have a bunch of duplicate code. > > Paolo >