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 6F5F5C05027 for ; Mon, 6 Feb 2023 23:34:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229741AbjBFXet (ORCPT ); Mon, 6 Feb 2023 18:34:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32848 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229740AbjBFXe2 (ORCPT ); Mon, 6 Feb 2023 18:34:28 -0500 Received: from mail-vs1-xe2e.google.com (mail-vs1-xe2e.google.com [IPv6:2607:f8b0:4864:20::e2e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D66131042B for ; Mon, 6 Feb 2023 15:34:27 -0800 (PST) Received: by mail-vs1-xe2e.google.com with SMTP id z22so542483vsq.11 for ; Mon, 06 Feb 2023 15:34:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=FbhxqYSnM0QVkv6Sp3VM+vd772qQ+TcTU6CDsEGA4Og=; b=Cx79guYuAJpsYHml9Wx/12xWxQPyF8soU/xhIAgPEnvNvCUSxYU7iY51ACUPWGPdbb kUUXWUl6PRVxqL5+0yWtIk+UJjU6n4T8JrtX3KYBVQT2bSKs/rpe2oWBVmdtbKknMXXA umJXccBR70k9eQZGdx7v02ys14adp2l7UQHjvxKpd1Da75gJdFWVc0QfS/UNBPcE3xUy kLepkR4YZQFz9NwmDa788RmmwL7cJhHHAkmKv+DtTdc5qlQNpSFv2T2waf1x0SxE/24T l82PbUP2UNQ/mDXExubTPt4OlRlSsP3GYWAx+0TJGg7MR6n8FIrT6ncCs8CvQwhIbhnT cagg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=FbhxqYSnM0QVkv6Sp3VM+vd772qQ+TcTU6CDsEGA4Og=; b=kYvmIMPcvE1JTNKVSKoU3d65J7xvGyio8iwpSYm7ogdEMfluFAUZWTH5NTEvLI5xIT QHAhW1DKDDROramfuqMkbfbzHOJJ962Q0FD9ZLOoEvxn+vJ4Hb5iU1Mq09zFN9sZILKt ai4uG8Lw8trTHe1XjISULI7/bJUZzRAjjnLT3Cj6WVjN01P9MfJ6W56jsZpbY1H7Wpj2 CX/yBFJqka0cZLWZ5ueMn6UfaAhq8HYo06dgr6+ERVoK7bFAFsSvvDgnB0sfvBqyTg7q D75/ZkuZse1IjRt+gNaFZmub3/m5PLdLBX9mlSZRA2OuSbrvmq7mOYLKfPJ998DmBxjq 3m6w== X-Gm-Message-State: AO0yUKWGaztZQ2JQxcmPOpMT62HYyYwzM4C8/wwB8NLPlJyA2oHBQv3i Zy+ggYZ1jPGFkheSJJakmmGpuXt1wN6Y1x/+gJXSdQ== X-Google-Smtp-Source: AK7set+2l/p1gINBZT5HgFQ4KeQHjnsJsxO3Yvjfza4XfHZe7AyEdBtN8oKN4GJIoY06nGFM5pwLnK3I5aoaTauxv74= X-Received: by 2002:a05:6102:5c0a:b0:401:57f8:7c18 with SMTP id ds10-20020a0561025c0a00b0040157f87c18mr323247vsb.51.1675726466974; Mon, 06 Feb 2023 15:34:26 -0800 (PST) MIME-Version: 1.0 References: <20230203192822.106773-1-vipinsh@google.com> <20230203192822.106773-3-vipinsh@google.com> In-Reply-To: From: David Matlack Date: Mon, 6 Feb 2023 15:34:00 -0800 Message-ID: Subject: Re: [Patch v2 2/5] KVM: x86/mmu: Optimize SPTE change flow for clear-dirty-log To: Ben Gardon Cc: Vipin Sharma , seanjc@google.com, pbonzini@redhat.com, kvm@vger.kernel.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 6, 2023 at 2:06 PM Ben Gardon wrote: > > On Fri, Feb 3, 2023 at 11:28 AM Vipin Sharma wrote: > > > > +static inline u64 kvm_tdp_mmu_clear_spte_bit(struct tdp_iter *iter, u64 mask) > > +{ > > + atomic64_t *sptep; > > + > > + if (kvm_tdp_mmu_spte_has_volatile_bits(iter->old_spte, iter->level)) { > > + sptep = (atomic64_t *)rcu_dereference(iter->sptep); > > + return (u64)atomic64_fetch_and(~mask, sptep); > > + } > > + > > + __kvm_tdp_mmu_write_spte(iter->sptep, iter->old_spte & ~mask); > > + return iter->old_spte; > > +} > > + > > If you do end up sending another version of the series and feel like > breaking up this patch, you could probably split this part out since > the change to how we set the SPTE and how we handle that change are > somewhat independent. I like the switch to atomic64_fetch_and though. > No idea if it's faster, but I would believe it could be. The changes are actually dependent. Using the atomic-AND makes it impossible for KVM to clear a volatile bit that it wasn't intending to clear, and that is what enables simplifying the SPTE change propagation. Instead I would split out the opportunistic cleanup of @record_dirty_log to a separate patch, since that's dead-code cleanup and refactoring.