From patchwork Sat Jul 1 00:26:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Feiner X-Patchwork-Id: 9820645 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id BE7EE603F2 for ; Sat, 1 Jul 2017 00:26:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B172326E1A for ; Sat, 1 Jul 2017 00:26:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A5540274D2; Sat, 1 Jul 2017 00:26:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 46C8D274D2 for ; Sat, 1 Jul 2017 00:26:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752017AbdGAA0i (ORCPT ); Fri, 30 Jun 2017 20:26:38 -0400 Received: from mail-pf0-f181.google.com ([209.85.192.181]:33257 "EHLO mail-pf0-f181.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751974AbdGAA0g (ORCPT ); Fri, 30 Jun 2017 20:26:36 -0400 Received: by mail-pf0-f181.google.com with SMTP id e7so74248534pfk.0 for ; Fri, 30 Jun 2017 17:26:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=Prt1bqIUuHTCow1eEqCyO78grMDgmFUhcU7gwdbLWYM=; b=mK+ZHdRqNEjDrbDKQaxJRqgCe9Bs5LZNIP+APZCzYZ8KVgqiHMiXeqPY1c2lIzK1zU N2Q0xKWLf4fcWQKFaljVThJP/hRUc1d+bP2CcYf7XVVpZyyT6sfYNdUYoLrjNT+7ufjL rlOVYIDpSOfBUzMAqaxUUoXNepR/3SJq0AzCv7G1XMESDNWMEsPGlpOilerDNw8Q8U8x uAHJqVTv4Ut+ZWTilpls/1xuYXTdNdLNACoYvXWwAKGvxxKFMyD2/sM8UuOAAn+3FwpL W42/KuTUxmZp0xQolnDAKQYX+b68grcfRvrtJVHjo06eMzBmlHzOmVNNUeywtyzYueZ2 G3Kw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=Prt1bqIUuHTCow1eEqCyO78grMDgmFUhcU7gwdbLWYM=; b=qQF/2Ls5cnhBzyKuj7NoEG6d12w1KRzy4E5VNnEc/8uHcCh1fuVZpNUDnBJDv+KWRT nUbg2dV2IHW8xMayEu0IWg9idD6Q9vbVW8F+ugqCNo4W4ijqSe2iCTCtSw8bLnG6eNyf g+pI7Me2jg1yd4dsYx9kEEYKYTBDed1vFrLtub1TTw9VU3jnl55A00Tm2K7Mnh1KELS4 kb0zCkncE3xvJQ3eDo+OBId38yPFqCMWgI5HPLVNoiyPpcnxc98uYOfblWYA6sAdCZBq PnbjAun/9bb0Sfh2lfcmbBQ6nU6z8mftlLL4grBIc0GuMqtZqUI9XIk7rNbFKCdkh2/z 6qnA== X-Gm-Message-State: AKS2vOwToXOQ42W4iqJsZhfchGtIOWlFvN3jorTzWa2MGKptqSAof2iQ 9hbA416Y5QJOhacNN9aCNA== X-Received: by 10.98.224.11 with SMTP id f11mr25438572pfh.118.1498868795733; Fri, 30 Jun 2017 17:26:35 -0700 (PDT) Received: from localhost ([2620:0:1009:3:4123:6f60:64cb:d807]) by smtp.gmail.com with ESMTPSA id u9sm21452888pfd.56.2017.06.30.17.26.34 (version=TLS1_2 cipher=AES128-SHA bits=128/128); Fri, 30 Jun 2017 17:26:35 -0700 (PDT) From: Peter Feiner To: kvm@vger.kernel.org Cc: Paolo Bonzini , David Matlack , Peter Feiner Subject: [PATCH 1/4] x86: kvm: mmu: dead code thanks to access tracking Date: Fri, 30 Jun 2017 17:26:29 -0700 Message-Id: <94ab515da0d8b702aebf0acd30b8daacea1b8839.1498868316.git.pfeiner@google.com> X-Mailer: git-send-email 2.13.2.725.g09c95d1e9-goog In-Reply-To: References: In-Reply-To: References: Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The MMU always has hardware A bits or access tracking support, thus it's unnecessary to handle the scenario where we have neither. Signed-off-by: Peter Feiner --- arch/x86/kvm/mmu.c | 30 +++++++++--------------------- 1 file changed, 9 insertions(+), 21 deletions(-) diff --git a/arch/x86/kvm/mmu.c b/arch/x86/kvm/mmu.c index 5d3376f67794..dfd4cd67e5a6 100644 --- a/arch/x86/kvm/mmu.c +++ b/arch/x86/kvm/mmu.c @@ -315,12 +315,21 @@ static bool check_mmio_spte(struct kvm_vcpu *vcpu, u64 spte) return likely(kvm_gen == spte_gen); } +/* + * Sets the shadow PTE masks used by the MMU. + * + * Assumptions: + * - Setting either @accessed_mask or @dirty_mask requires setting both + * - At least one of @accessed_mask or @acc_track_mask must be set + */ void kvm_mmu_set_mask_ptes(u64 user_mask, u64 accessed_mask, u64 dirty_mask, u64 nx_mask, u64 x_mask, u64 p_mask, u64 acc_track_mask) { if (acc_track_mask != 0) acc_track_mask |= SPTE_SPECIAL_MASK; + BUG_ON(!dirty_mask != !accessed_mask); + BUG_ON(!accessed_mask && !acc_track_mask); shadow_user_mask = user_mask; shadow_accessed_mask = accessed_mask; @@ -1766,18 +1775,9 @@ static int kvm_test_age_rmapp(struct kvm *kvm, struct kvm_rmap_head *rmap_head, u64 *sptep; struct rmap_iterator iter; - /* - * If there's no access bit in the secondary pte set by the hardware and - * fast access tracking is also not enabled, it's up to gup-fast/gup to - * set the access bit in the primary pte or in the page structure. - */ - if (!shadow_accessed_mask && !shadow_acc_track_mask) - goto out; - for_each_rmap_spte(rmap_head, &iter, sptep) if (is_accessed_spte(*sptep)) return 1; -out: return 0; } @@ -1798,18 +1798,6 @@ static void rmap_recycle(struct kvm_vcpu *vcpu, u64 *spte, gfn_t gfn) int kvm_age_hva(struct kvm *kvm, unsigned long start, unsigned long end) { - /* - * In case of absence of EPT Access and Dirty Bits supports, - * emulate the accessed bit for EPT, by checking if this page has - * an EPT mapping, and clearing it if it does. On the next access, - * a new EPT mapping will be established. - * This has some overhead, but not as much as the cost of swapping - * out actively used pages or breaking up actively used hugepages. - */ - if (!shadow_accessed_mask && !shadow_acc_track_mask) - return kvm_handle_hva_range(kvm, start, end, 0, - kvm_unmap_rmapp); - return kvm_handle_hva_range(kvm, start, end, 0, kvm_age_rmapp); }