From patchwork Fri Feb 26 01:03:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12105335 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0CCEBC433DB for ; Fri, 26 Feb 2021 01:04:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C807464F21 for ; Fri, 26 Feb 2021 01:04:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229769AbhBZBEb (ORCPT ); Thu, 25 Feb 2021 20:04:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231335AbhBZBEQ (ORCPT ); Thu, 25 Feb 2021 20:04:16 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 67ED2C061786 for ; Thu, 25 Feb 2021 17:03:36 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id a63so8411999yba.2 for ; Thu, 25 Feb 2021 17:03:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=BZaWszN/LLBzcU94c/xowczYk0Zi91gjd6GZk09bLp8=; b=Tqbg9PdKVSAx0v9v1M+vUle/2MQJ9wjgId2EgtMTB3GOHfGzXZbdf4Ua4weJGSWKcU tcZXuhEBfMr9X7+A+v0/93pFy0mx+Ta5ntmHwHIn8e9k6a0s9V/nYJQ6I3QTMZS9Hdp7 VQpgETaIivseKcse3lEd2M4Rhg3nMs9FGnzqlHw3wZtkFWQRam41xDYf3XTQJ63bdmkO uyWXD8yL3cEWfIOy/hD7gW9HCXw9xZjSd7P526xFqENKjPP0JLFOXsgrDNeV1lJokQrI 0wIVcXzKHdx3cW/hvn4e83cCKQVAzdtPu0Q0eiUBWLRc0xWMfO3jP9aUonNOUqW0bpqF cOKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=BZaWszN/LLBzcU94c/xowczYk0Zi91gjd6GZk09bLp8=; b=gE9qL4elOcsgHkqJoQkkGdOWltzT6Bde5Pqk+JTKtpLENv5D1T1ktn2uCq3xjfNGe0 Okbl3QwG4B15HpVJmLYau9i9cBT02WUbqhBf1b/xEOolE8SL7bWeT/Bv4EoA1ijeMicl TQBeptOGHZMCwUX7TVj741uPKpHXuFU3yDESzw/WHzdDpY/sNAO7S68PSVgH4cfdKUeF lDBAaGZLnxlKqmhSSsj/p7VskHl/igKHxQjTQbUdm8G+q+9vCUe+nPDaU3bSQn4WThoZ v9kIG0f1PzR4GidW/GWqsGoxlP44u7pE3AOgXDAfBwOA22yg6re8uuo1d/QrWU114N7K kqLw== X-Gm-Message-State: AOAM5311VS802ibS32rfVxS2OsTlTkiJ1sxqamnuobrK3KzLoh/ApFHe f8Ao/zxA14eazV0+ayFixZVsa2vyafA= X-Google-Smtp-Source: ABdhPJzLd/OexlxhpNoqN6h4X4CVKwl6YHyGAR57H9qGFlrTHD2sD39ekg0Z+DEZAKW+a9hlzCBbwk2piJM= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:34c4:7c1d:f9ba:4576]) (user=seanjc job=sendgmr) by 2002:a25:d314:: with SMTP id e20mr814723ybf.155.1614301415676; Thu, 25 Feb 2021 17:03:35 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 25 Feb 2021 17:03:25 -0800 In-Reply-To: <20210226010329.1766033-1-seanjc@google.com> Message-Id: <20210226010329.1766033-2-seanjc@google.com> Mime-Version: 1.0 References: <20210226010329.1766033-1-seanjc@google.com> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH 1/5] KVM: x86/mmu: Remove spurious TLB flush from TDP MMU's change_pte() hook From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Gardon Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Remove an unnecessary remote TLB flush from set_tdp_spte(), the TDP MMu's hook for handling change_pte() invocations from the MMU notifier. If the new host PTE is writable, the flush is completely redundant as there are no futher changes to the SPTE before the post-loop flush. If the host PTE is read-only, then the primary MMU is responsible for ensuring that the contents of the old and new pages are identical, thus it's safe to let the guest continue reading both the old and new pages. KVM must only ensure the old page cannot be referenced after returning from its callback; this is handled by the post-loop flush. Fixes: 1d8dd6b3f12b ("kvm: x86/mmu: Support changed pte notifier in tdp MMU") Cc: Ben Gardon Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/tdp_mmu.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index c926c6b899a1..3290e53fb850 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -1044,10 +1044,14 @@ static int set_tdp_spte(struct kvm *kvm, struct kvm_memory_slot *slot, if (!is_shadow_present_pte(iter.old_spte)) break; + /* + * Note, when changing a read-only SPTE, it's not strictly + * necessary to zero the SPTE before setting the new PFN, but + * doing so preserves the invariant that the PFN of a present + * leaf SPTE can never change. See __handle_changed_spte(). + */ tdp_mmu_set_spte(kvm, &iter, 0); - kvm_flush_remote_tlbs_with_address(kvm, iter.gfn, 1); - if (!pte_write(*ptep)) { new_spte = kvm_mmu_changed_pte_notifier_make_spte( iter.old_spte, new_pfn); From patchwork Fri Feb 26 01:03:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12105337 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2573CC433E0 for ; Fri, 26 Feb 2021 01:05:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D812464F29 for ; Fri, 26 Feb 2021 01:05:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232008AbhBZBFI (ORCPT ); Thu, 25 Feb 2021 20:05:08 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48886 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230010AbhBZBFC (ORCPT ); Thu, 25 Feb 2021 20:05:02 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19178C06178A for ; Thu, 25 Feb 2021 17:03:39 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id g17so8409833ybh.4 for ; Thu, 25 Feb 2021 17:03:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=jjFmqKl5TUSlu20yk/qEiThTFlDZmJ7vLsHCxIjCxWQ=; b=thzagAC2ArbMJiyjkGonrAiEV5IKDadQD3GoC8IqgDet51VKEpm93EWDj/6VzmpRuj a/VY0bkTye3mYeoBN4b4QNxaAR9EuZbJjUULUXiARyXHcq750mYq5777gtWqvfp2AGGA k/sNnEhMFooq/WTLdg12HYSxlO06Wvq5pPpfCcQxVWNJAQZXziKuk3Kgv5HFXK8R/pxp Hm3Htl7yVjjQUhqALGZ27qBZpp7ck0SOzJ5ndxse6+LASF4xvLQLItlyj2/cSgPdCNyS cVEErZByxYfDcTl9bgYYVUeEZlB8VbbfMuVdiW8Ae2vE+z0Rpr6UU+wI2chH80TVAmAF 0P1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=jjFmqKl5TUSlu20yk/qEiThTFlDZmJ7vLsHCxIjCxWQ=; b=N7XQ4IztjPFfcjyh+ElCH3llYK373enjaGp4YeuLyN4hxMrW/g26kHjhq4jpHKKBXR gag+b0sLwvzoatQ7S4w8WBZXWkBr9BG4SgdGUGJnuGC07rY9lgEFQDia1mp+s/hGuaIn TfE6pDXooHJaECRW0gK/mP13qU5tiRxBUpobIz1L+ysn4WoeMggktNaB57shLb6evp0h HlhDomb/IFPRSCPV/a3kQ6cVGQ0KRY5mbA0+lombG52L94mRRfu1y1p+NIjstXUhzce3 oFCztlpQuRrm8EWc6uSsTgMVl8TFMoHKJo5BUq2TyR/oEMZN8to7iY10mEvXCfM+bkLf tN7A== X-Gm-Message-State: AOAM531/596ymdXgsTWuVYP1B7t+Jj4Zi2zTDXaJYpk+IEdfkUr7FYBt LfZIA3HOlX3hL7pyVNg72T/hbPoKB6k= X-Google-Smtp-Source: ABdhPJxS7wqy9jeWhEDjop15HOx+Q9pR1KowWkU+O8C8ijl/iTyZmsIqLlwpkLz1+C2/XCwoINxwcOewFn4= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:34c4:7c1d:f9ba:4576]) (user=seanjc job=sendgmr) by 2002:a25:7312:: with SMTP id o18mr895039ybc.352.1614301418368; Thu, 25 Feb 2021 17:03:38 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 25 Feb 2021 17:03:26 -0800 In-Reply-To: <20210226010329.1766033-1-seanjc@google.com> Message-Id: <20210226010329.1766033-3-seanjc@google.com> Mime-Version: 1.0 References: <20210226010329.1766033-1-seanjc@google.com> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH 2/5] KVM: x86/mmu: WARN if TDP MMU's set_tdp_spte() sees multiple GFNs From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Gardon Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org WARN if set_tdp_spte() is invoked with multipel GFNs. It is specifically a callback to handle a single host PTE being changed. Consuming the @end parameter also eliminates the confusing 'unused' parameter. Cc: Ben Gardon Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/tdp_mmu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 3290e53fb850..020f2e573f44 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -1022,7 +1022,7 @@ int kvm_tdp_mmu_test_age_hva(struct kvm *kvm, unsigned long hva) * Returns non-zero if a flush is needed before releasing the MMU lock. */ static int set_tdp_spte(struct kvm *kvm, struct kvm_memory_slot *slot, - struct kvm_mmu_page *root, gfn_t gfn, gfn_t unused, + struct kvm_mmu_page *root, gfn_t gfn, gfn_t end, unsigned long data) { struct tdp_iter iter; @@ -1033,7 +1033,7 @@ static int set_tdp_spte(struct kvm *kvm, struct kvm_memory_slot *slot, rcu_read_lock(); - WARN_ON(pte_huge(*ptep)); + WARN_ON(pte_huge(*ptep) || (gfn + 1) != end); new_pfn = pte_pfn(*ptep); From patchwork Fri Feb 26 01:03:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12105343 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id BF6EBC433E0 for ; Fri, 26 Feb 2021 01:05:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 942E064F22 for ; Fri, 26 Feb 2021 01:05:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232144AbhBZBFP (ORCPT ); Thu, 25 Feb 2021 20:05:15 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48902 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231787AbhBZBFG (ORCPT ); Thu, 25 Feb 2021 20:05:06 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C20F6C06178C for ; Thu, 25 Feb 2021 17:03:41 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id 194so8358770ybl.5 for ; Thu, 25 Feb 2021 17:03:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=qpS7GnYM+VvVuInH7Q+CEmlH+I0WNjfKsvpZu1wz92s=; b=Wben5QyU96ys7KjMGaMwlDENkCrkljjCcTiQK7iqau4peOpcza4F9Nu5kai1mo7aHB wowSzju/bwAwXxMLBGdCBG3Vo3x9rviVRz5Bk2xXxl9lZFfBrZy5gPg76k2B1MiGnBZy BcTRRAQTdJGX5yu2za10oYQgWodsHWF7se0NAl4wk46k+/GYHyff5aK0LaPO/32P/h5h ysdX8JS1qvkkbBMKYR58Otttd3LX2dAeIRbplsgtg76qqHHjwyXvqaHd2ZnwC86bE+6b 1OvbirwMVSUNB8bsMJ8pgQs4PBIzbhuhTg3iR7hvgH2lzMLXU6ypMAU9kWXpApmGDcTx e5xQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=qpS7GnYM+VvVuInH7Q+CEmlH+I0WNjfKsvpZu1wz92s=; b=cA9GXwfiUH+seP8dsKp76DGVErZtW2ipdVMNTd2oOornWMtTk9w9qYWLGHm+EcnFSm RL3jW9W8bvAxY14yCULe5dK231BTysTxIg5K6CEK9g6UYiDSN9EdJZiSHiiqm9preecD TPlhSRyyFX2pIeSRzkp0zKS4JGpCQcd3iSmTx6g8DrtPKF63R7/lcARLg2bVJfORa1aR JveDDuDcx9iQZIUOT/7uCA8hFmiEa1CblIvmFWgMADRsZ7XsAMgo7F95vltTJt3MF+h0 n53mvzHiwk+e6f9L5VjJPDdtrxgdglmUr8ZuJNRlEZgWkESPm5rEZsea3Vl4JfrClLEd nAjA== X-Gm-Message-State: AOAM5313k6dSqFjUMSaDSJaj9Jwb+sqvGYg+B7ETzlrryxXHAWQaoUGo oR0lySn1Rof6Of8TRqA+PSC/VEyEgjI= X-Google-Smtp-Source: ABdhPJxAv8NLAGkTg59FY3aLxcVqNtcoJWj9Dd9vAhOtBjufQnxrIDaMn2J+HNxN+TdwAN5N5mOfq/PEVIY= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:34c4:7c1d:f9ba:4576]) (user=seanjc job=sendgmr) by 2002:a05:6902:6ac:: with SMTP id j12mr867837ybt.440.1614301421040; Thu, 25 Feb 2021 17:03:41 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 25 Feb 2021 17:03:27 -0800 In-Reply-To: <20210226010329.1766033-1-seanjc@google.com> Message-Id: <20210226010329.1766033-4-seanjc@google.com> Mime-Version: 1.0 References: <20210226010329.1766033-1-seanjc@google.com> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH 3/5] KVM: x86/mmu: Use 'end' param in TDP MMU's test_age_gfn() From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Gardon Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Use the @end param when aging a GFN instead of hardcoding the walk to a single GFN. Unlike tdp_set_spte(), which simply cannot work with more than one GFN, aging multiple GFNs would not break, though admittedly it would be weird. Be nice to the casual reader and don't make them puzzle out why the end GFN is unused. No functional change intended. Cc: Ben Gardon Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/tdp_mmu.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 020f2e573f44..9ce8d226b621 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -997,12 +997,12 @@ int kvm_tdp_mmu_age_hva_range(struct kvm *kvm, unsigned long start, } static int test_age_gfn(struct kvm *kvm, struct kvm_memory_slot *slot, - struct kvm_mmu_page *root, gfn_t gfn, gfn_t unused, - unsigned long unused2) + struct kvm_mmu_page *root, gfn_t gfn, gfn_t end, + unsigned long unused) { struct tdp_iter iter; - tdp_root_for_each_leaf_pte(iter, root, gfn, gfn + 1) + tdp_root_for_each_leaf_pte(iter, root, gfn, end) if (is_accessed_spte(iter.old_spte)) return 1; From patchwork Fri Feb 26 01:03:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12105341 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5ED86C43381 for ; Fri, 26 Feb 2021 01:05:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2315464F2F for ; Fri, 26 Feb 2021 01:05:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232103AbhBZBFN (ORCPT ); Thu, 25 Feb 2021 20:05:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231701AbhBZBFG (ORCPT ); Thu, 25 Feb 2021 20:05:06 -0500 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A0A6C061793 for ; Thu, 25 Feb 2021 17:03:44 -0800 (PST) Received: by mail-qt1-x849.google.com with SMTP id b7so5432355qtj.16 for ; Thu, 25 Feb 2021 17:03:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=VwL4OKVPwLd2Pg+VBJhmXhH54fx49qLMEAmb7K/yfzE=; b=asBlIwqlyL3G7lCGd6ftlZ1p4O/OaNv+4nvJBXTpJ1jQp9zF54AfPzE2oHarE2oPsQ zqzpcbUazeizOI4ugER4Iq0P3Uxm6BML7s8w8CYGRsylnB4OdekwN05mrsLfCCGGyI8m B0O6TRQ/8Jl67lg5q9sr/kzygY3f7g/0+WxJNgfPg1Z4Fze39MwwRD2qPh6KcjhWkDhK MAFCL3PZO/mZUOph13ndkkV8vxBu6lT30P0mcAV31ueREbJFCBskk4seupk5D4/ai+/m T/ePm4CejvmH0ND4V/1pMjINhZyxXmFdeWWGV/ApdZWpSv6xRwnvfNR1v0Go5Z7TtUGT BMLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=VwL4OKVPwLd2Pg+VBJhmXhH54fx49qLMEAmb7K/yfzE=; b=XBgiA1BgV91rcrU8ZVHJw1WeAiNE9OKzx77AjNmVCTc8LAJbwxQ5/sf+wpW/GWlDET L51cmkiSg2UwgEARBrz+PWEnQoltz+aOqu0SEqyabnUOXN9PQqENCpoXLppCMC/WGvNU ycqk9mfuDBgjlkoA/mDgsjV7zD98RnWy48zu/qwzjLodL1XI/5Bq7xLfKi3ZK/rVciGm 4X3h7MhoNbafKgvu4D/ba4lIwuWAkmeqUAwTsS38953fF2jCwnSLC/notd49wSRrjnmw ZcBuBNtINkpD/vUgnHY2b6B07VuOYOSSFMuOsncMzyxAVaTK8+0WHr78+ZDGH98DP6PF Nw3Q== X-Gm-Message-State: AOAM530KFWUpnGhUAM5J0Ler3PZ0CUyMe3UpE0Xqc3V0W7ey5MBkV0NH jceh/UZnV8Ao8E8ftOUgGlNBUylSzyI= X-Google-Smtp-Source: ABdhPJzH0AkeJmFJPvLyy38HssKzf5B73Itkikl9QMv9yK+MbjaJztQXtpP6dNt9q7l96dZUTk/jbOfcwWY= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:34c4:7c1d:f9ba:4576]) (user=seanjc job=sendgmr) by 2002:a0c:d78e:: with SMTP id z14mr477802qvi.8.1614301423475; Thu, 25 Feb 2021 17:03:43 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 25 Feb 2021 17:03:28 -0800 In-Reply-To: <20210226010329.1766033-1-seanjc@google.com> Message-Id: <20210226010329.1766033-5-seanjc@google.com> Mime-Version: 1.0 References: <20210226010329.1766033-1-seanjc@google.com> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH 4/5] KVM: x86/mmu: Add typedefs for rmap/iter handlers From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Gardon Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add typedefs for the MMU handlers that are invoked when walking the MMU SPTEs (rmaps in legacy MMU) to act on a host virtual address range. No functional change intended. Cc: Ben Gardon Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/mmu.c | 27 ++++++++++----------------- arch/x86/kvm/mmu/tdp_mmu.c | 20 +++++++++----------- 2 files changed, 19 insertions(+), 28 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index d75524bc8423..1ee01ca196bd 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -1424,17 +1424,15 @@ static void slot_rmap_walk_next(struct slot_rmap_walk_iterator *iterator) slot_rmap_walk_okay(_iter_); \ slot_rmap_walk_next(_iter_)) -static __always_inline int -kvm_handle_hva_range(struct kvm *kvm, - unsigned long start, - unsigned long end, - unsigned long data, - int (*handler)(struct kvm *kvm, - struct kvm_rmap_head *rmap_head, - struct kvm_memory_slot *slot, - gfn_t gfn, - int level, - unsigned long data)) +typedef int (*rmap_handler_t)(struct kvm *kvm, struct kvm_rmap_head *rmap_head, + struct kvm_memory_slot *slot, gfn_t gfn, + int level, unsigned long data); + +static __always_inline int kvm_handle_hva_range(struct kvm *kvm, + unsigned long start, + unsigned long end, + unsigned long data, + rmap_handler_t handler) { struct kvm_memslots *slots; struct kvm_memory_slot *memslot; @@ -1473,12 +1471,7 @@ kvm_handle_hva_range(struct kvm *kvm, } static int kvm_handle_hva(struct kvm *kvm, unsigned long hva, - unsigned long data, - int (*handler)(struct kvm *kvm, - struct kvm_rmap_head *rmap_head, - struct kvm_memory_slot *slot, - gfn_t gfn, int level, - unsigned long data)) + unsigned long data, rmap_handler_t handler) { return kvm_handle_hva_range(kvm, hva, hva + 1, data, handler); } diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index 9ce8d226b621..b6f829b58e67 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -879,17 +879,15 @@ int kvm_tdp_mmu_map(struct kvm_vcpu *vcpu, gpa_t gpa, u32 error_code, return ret; } -static __always_inline int -kvm_tdp_mmu_handle_hva_range(struct kvm *kvm, - unsigned long start, - unsigned long end, - unsigned long data, - int (*handler)(struct kvm *kvm, - struct kvm_memory_slot *slot, - struct kvm_mmu_page *root, - gfn_t start, - gfn_t end, - unsigned long data)) +typedef int (*tdp_handler_t)(struct kvm *kvm, struct kvm_memory_slot *slot, + struct kvm_mmu_page *root, gfn_t start, gfn_t end, + unsigned long data); + +static __always_inline int kvm_tdp_mmu_handle_hva_range(struct kvm *kvm, + unsigned long start, + unsigned long end, + unsigned long data, + tdp_handler_t handler) { struct kvm_memslots *slots; struct kvm_memory_slot *memslot; From patchwork Fri Feb 26 01:03:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 12105339 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 45398C433E6 for ; Fri, 26 Feb 2021 01:05:18 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0028B64F22 for ; Fri, 26 Feb 2021 01:05:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232060AbhBZBFL (ORCPT ); Thu, 25 Feb 2021 20:05:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48906 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231375AbhBZBFG (ORCPT ); Thu, 25 Feb 2021 20:05:06 -0500 Received: from mail-qt1-x849.google.com (mail-qt1-x849.google.com [IPv6:2607:f8b0:4864:20::849]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 170ADC061797 for ; Thu, 25 Feb 2021 17:03:47 -0800 (PST) Received: by mail-qt1-x849.google.com with SMTP id r1so5453262qtu.9 for ; Thu, 25 Feb 2021 17:03:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:reply-to:date:in-reply-to:message-id:mime-version:references :subject:from:to:cc; bh=e6eBX5arsmuvKaEXCcMohgv1CZ2IbMRSR/jmdxJbsBs=; b=Y/DgjEw5meqAmc3rYmAoRFfyLa9ujttNoYX0gjpaDAOvdALuUc3aWqHBmi7WMr57Ka KSGo3dC2CNtKbk2fNeH6tdeVKf7ZT+tI9Fr6r+0kn6EG+H/BGiHXgOgBh4OsaDt2zNzn Y6IwwKEVksZET6NDCsWSKe84B9xWOI0Xm0zICDOE5U/eiH09luAf+xPlj4UAHP2WW5DZ yZ2ysR8BZj2EgY/1nhU8akd6gSYn+/jF3VXwmg1GeVOGgrg5L4cEPQ+OnOmtytFU759Z e7af6XNiMkYjuqqlzrwrgaLOG8WCKQHG6hZ+lSWO0md/Y30u/OTQaASPZjgoFhT5wCFN SSEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:reply-to:date:in-reply-to:message-id :mime-version:references:subject:from:to:cc; bh=e6eBX5arsmuvKaEXCcMohgv1CZ2IbMRSR/jmdxJbsBs=; b=QoVnl418L6/8CclzpCTvPuUW5IpV3/jt83GipnjfFEbQPoGNHliefcL7bgC7Qljd99 PL8tHqi7K60i9BnObqUSO446u/416h8JwTnyBVAlM/0QxOVxyQ8TX9zxVUhMQGU2XmY6 xpVHCtHHTPb96zm2bIYnXR4fxsF2bkxwpsp9f302ncV/4HRfJm1LYdUMarlcb3fyMYdH bC2ikySKopNqFO96ZpOyLIGsHyYKiHe0dFMzp8tUtipOlZHwkpa1HOiO+LrcAH+bTSsr 2r5TOaYNt6HNIdWUdqkgxA8cvAt1urAkypsPFcGdUKGN2fvSEfgnunvVwDCBgfwONeEO CXEw== X-Gm-Message-State: AOAM530Zn5zG/Kn4NUzEHSBsxKm0Tw6BdaKFiLrYulHsB4om6nACq9hf bmvX56ppfFrbAWrw1oNx93CmvoW7Pw4= X-Google-Smtp-Source: ABdhPJwP4vEFvry4fCj958VczSglgLQSQer805zjAzOvhXuyKzXxpumXWcVQucW1d65igOwn1MFganW1ets= Sender: "seanjc via sendgmr" X-Received: from seanjc798194.pdx.corp.google.com ([2620:15c:f:10:34c4:7c1d:f9ba:4576]) (user=seanjc job=sendgmr) by 2002:a05:6214:2402:: with SMTP id fv2mr417147qvb.49.1614301426291; Thu, 25 Feb 2021 17:03:46 -0800 (PST) Reply-To: Sean Christopherson Date: Thu, 25 Feb 2021 17:03:29 -0800 In-Reply-To: <20210226010329.1766033-1-seanjc@google.com> Message-Id: <20210226010329.1766033-6-seanjc@google.com> Mime-Version: 1.0 References: <20210226010329.1766033-1-seanjc@google.com> X-Mailer: git-send-email 2.30.1.766.gb4fecdf3b7-goog Subject: [PATCH 5/5] KVM: x86/mmu: Add convenience wrapper for acting on single hva in TDP MMU From: Sean Christopherson To: Paolo Bonzini Cc: Sean Christopherson , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, Ben Gardon Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add a TDP MMU helper to handle a single HVA hook, the name is a nice reminder that the flow in question is operating on a single HVA. No functional change intended. Cc: Ben Gardon Signed-off-by: Sean Christopherson --- arch/x86/kvm/mmu/tdp_mmu.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/arch/x86/kvm/mmu/tdp_mmu.c b/arch/x86/kvm/mmu/tdp_mmu.c index b6f829b58e67..c0c09ec07c53 100644 --- a/arch/x86/kvm/mmu/tdp_mmu.c +++ b/arch/x86/kvm/mmu/tdp_mmu.c @@ -922,6 +922,14 @@ static __always_inline int kvm_tdp_mmu_handle_hva_range(struct kvm *kvm, return ret; } +static __always_inline int kvm_tdp_mmu_handle_hva(struct kvm *kvm, + unsigned long addr, + unsigned long data, + tdp_handler_t handler) +{ + return kvm_tdp_mmu_handle_hva_range(kvm, addr, addr + 1, data, handler); +} + static int zap_gfn_range_hva_wrapper(struct kvm *kvm, struct kvm_memory_slot *slot, struct kvm_mmu_page *root, gfn_t start, @@ -1009,8 +1017,7 @@ static int test_age_gfn(struct kvm *kvm, struct kvm_memory_slot *slot, int kvm_tdp_mmu_test_age_hva(struct kvm *kvm, unsigned long hva) { - return kvm_tdp_mmu_handle_hva_range(kvm, hva, hva + 1, 0, - test_age_gfn); + return kvm_tdp_mmu_handle_hva(kvm, hva, 0, test_age_gfn); } /* @@ -1071,9 +1078,8 @@ static int set_tdp_spte(struct kvm *kvm, struct kvm_memory_slot *slot, int kvm_tdp_mmu_set_spte_hva(struct kvm *kvm, unsigned long address, pte_t *host_ptep) { - return kvm_tdp_mmu_handle_hva_range(kvm, address, address + 1, - (unsigned long)host_ptep, - set_tdp_spte); + return kvm_tdp_mmu_handle_hva(kvm, address, (unsigned long)host_ptep, + set_tdp_spte); } /*