From patchwork Wed Jan 25 21:38:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vipin Sharma X-Patchwork-Id: 48382 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp500573wrn; Wed, 25 Jan 2023 13:48:57 -0800 (PST) X-Google-Smtp-Source: AMrXdXuiVjVMPdCsUOopPyFw4E2dMFZfPUoXc5PWBJB0TYoF7gEb/1H3jCf22PfH/HP7pWqE/DcM X-Received: by 2002:a05:6a20:7f8f:b0:b9:5fc6:9e4b with SMTP id d15-20020a056a207f8f00b000b95fc69e4bmr32201958pzj.62.1674683337309; Wed, 25 Jan 2023 13:48:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674683337; cv=none; d=google.com; s=arc-20160816; b=tQlIy7JConNM0Glcwe/iQSWzzH25RMZ2cE7yQev2kivLHPtMa00UBmkzniy3Fxkv7J X+qVwe7tjwZzI2rVnLTkux8RPtAiG7zjiMcmoAHlQzazM53KzDppfacNPG7MPijaAYzb fVYGkTl0x1yDtv/7Q+0dg6VvbkbBN67VMj0c93sX68yqRHExrk+LIh4GMElo5VNzStjf TpvuoFUIKx3hz+J3PxIyxjF1YnjJEybbgNoQtsWCGtTSDU4OHAhE5KqpHSpHabfZRTb1 P71CoO/hhVm8TfWtb6WDOWcFG3UHkRC8JHKE37Ah4X65Sv/UkbZrCuYY2TWFYcyprH7A NZ3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:message-id:mime-version:date :dkim-signature; bh=z+H+UxvTCHRq2s16xJmpZ8uSEEOupkr1b5CjiCnOkq0=; b=EaITAcMzgRZdJ8Fw2zR+h9suTeWXlqbw0JlX4aRzJt01KBAag432GagqOvg7MMMUCb oevBkzV8ExRlMtQv/4kqRo+YuYSohY3oFGvjMmlb2OEgPtca+Ffjf4mxoos+HmkmGcGP yotqSQHpMlsFNqG4i2pqfm8j+92W40RuveSQ8kcN47OPiZf/uzmhiv+hIsMDqf69oXNm SFCGvbsXA0rRZR1oA4DjdBRNGU6sozbGqClElLt1MiFt0fWwnUYjpgAKLLzSwH/i3vmo NvcmALjBUsGx7a7j9PW5uXCmsTFqzHH95vz4HFtJfrrrQb+WQ1qoYzWz7s7EL46PVzQL /7Zw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ThnR8aaR; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r12-20020a17090a560c00b00219f068d241si3267747pjf.130.2023.01.25.13.48.45; Wed, 25 Jan 2023 13:48:57 -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=@google.com header.s=20210112 header.b=ThnR8aaR; 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 S236713AbjAYVjJ (ORCPT + 99 others); Wed, 25 Jan 2023 16:39:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36364 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236681AbjAYVjH (ORCPT ); Wed, 25 Jan 2023 16:39:07 -0500 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 66A541F932 for ; Wed, 25 Jan 2023 13:39:05 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-506368dc06dso80286877b3.9 for ; Wed, 25 Jan 2023 13:39:05 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=z+H+UxvTCHRq2s16xJmpZ8uSEEOupkr1b5CjiCnOkq0=; b=ThnR8aaRFSVJ6f1dSLQmti6T/10Si88QgufO2iD1z2YErNe8jTdRZDq6tWbXGO+1aY 6JR7ubUZJ1ktrc4CwqGf40eFzOcSSHFCSz7OTItOt0PZq0bxEMe5Bx8eFDqyyWLQTnkk sBzg7v+EPWRVXqGC747qF4kjUuz531+g0SzfXiSaJ4WynBW7ktKI2gBYTohy1VN1KURX jS/JKpZWaNxkKZgQhhcsgb9py1ZFcc9c+nSjrCSfWyzFiII6YCUFMwycxbV/dh1/VjbQ 4wAnqmcLadNOXItFDGiLgpmToLQQAPdldYLQflRwBmoTgylFVtOm9ymkxBkFQwV01BUl TSWA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=z+H+UxvTCHRq2s16xJmpZ8uSEEOupkr1b5CjiCnOkq0=; b=KLDkncnR1nbRNRtAwaUBSCuo6+9CMd7SzvJMOTUY6Ih9XqE9Wzh/sIAf/Fl4CBVyfv krdsjBjZE7NQPF8iVdYC1YHpvoGUZfkT1KDtnzioWI2W/nv8oWGIWJtqJAetvN64mu+X SSlTn8Yp4Q+nvN40KlhO+U+WU4fAdfA1d6xNo0GXB6z5dLi+RqbJ3H2k+sV9sDq7EVX4 SvfqpDcPuqubxS6iWfHvx46dvRW3hTcbE/Om+CihkaurdMGRP8dcf274fYAX8KBedNj/ IEuOR3fRWYepgwSAKkdGhSpJQjn6CcdV7AMfYGCgEY1d4VoB51/3aREqb8juVk580fyz lTuQ== X-Gm-Message-State: AO0yUKWM7IFTv4n9WNk88Ent931gatR1NmajOmTt6xUxJX1qilizgWVD dLkW+bIouex1KTvU9u+vZJDbmKJQlkdv X-Received: from vipin.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:479f]) (user=vipinsh job=sendgmr) by 2002:a81:7e4b:0:b0:506:4f19:740c with SMTP id p11-20020a817e4b000000b005064f19740cmr722466ywn.383.1674682744614; Wed, 25 Jan 2023 13:39:04 -0800 (PST) Date: Wed, 25 Jan 2023 13:38:57 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Message-ID: <20230125213857.824959-1-vipinsh@google.com> Subject: [Patch] KVM: x86/mmu: Make optimized __handle_changed_spte() for clear dirty log From: Vipin Sharma To: seanjc@google.com, pbonzini@redhat.com, bgardon@google.com, dmatlack@google.com Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Vipin Sharma X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1756032755470016053?= X-GMAIL-MSGID: =?utf-8?q?1756032755470016053?= Use a tone down version of __handle_changed_spte() when clearing dirty log. Remove checks which will not be needed when dirty logs are cleared. This change shows ~13% improvement in clear dirty log calls in dirty_log_perf_test Before tone down version: Clear dirty log over 3 iterations took 10.006764203s. (Avg 3.335588067s/iteration) After tone down version: Clear dirty log over 3 iterations took 8.686433554s. (Avg 2.895477851s/iteration) Signed-off-by: Vipin Sharma --- arch/x86/kvm/mmu/tdp_mmu.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index bba33aea0fb0..ca21b33c4386 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -504,6 +504,19 @@ static void handle_removed_pt(struct kvm *kvm, tdp_ptep_t pt, bool shared) call_rcu(&sp->rcu_head, tdp_mmu_free_sp_rcu_callback); } +static void handle_changed_spte_clear_dirty_log(int as_id, gfn_t gfn, + u64 old_spte, u64 new_spte, + int level) +{ + if (old_spte == new_spte) + return; + + trace_kvm_tdp_mmu_spte_changed(as_id, gfn, level, old_spte, new_spte); + + if (is_dirty_spte(old_spte) && !is_dirty_spte(new_spte)) + kvm_set_pfn_dirty(spte_to_pfn(old_spte)); +} + /** * __handle_changed_spte - handle bookkeeping associated with an SPTE change * @kvm: kvm instance @@ -736,7 +749,12 @@ static u64 __tdp_mmu_set_spte(struct kvm *kvm, int as_id, tdp_ptep_t sptep, old_spte = kvm_tdp_mmu_write_spte(sptep, old_spte, new_spte, level); - __handle_changed_spte(kvm, as_id, gfn, old_spte, new_spte, level, false); + if (record_dirty_log) + __handle_changed_spte(kvm, as_id, gfn, old_spte, new_spte, + level, false); + else + handle_changed_spte_clear_dirty_log(as_id, gfn, old_spte, + new_spte, level); if (record_acc_track) handle_changed_spte_acc_track(old_spte, new_spte, level);