From patchwork Wed Dec 21 22:24:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ben Gardon X-Patchwork-Id: 35534 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:8188:b0:89:790f:f786 with SMTP id m8csp4945077dye; Wed, 21 Dec 2022 14:25:46 -0800 (PST) X-Google-Smtp-Source: AMrXdXtUs3qrko5d+0tA8+Zvk8YZwypDZJZ6+/syBHZPNtgB3fe18OVc48OfZKgLjd4JGn8bQhkg X-Received: by 2002:a17:906:555:b0:7c1:47bd:1814 with SMTP id k21-20020a170906055500b007c147bd1814mr2882247eja.63.1671661545968; Wed, 21 Dec 2022 14:25:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671661545; cv=none; d=google.com; s=arc-20160816; b=n/iSHyl/bFWRCnCZHH+ShNv1EpngUjXqzJjVO+1onInQrw8tfzf2u1V2R1OcvH9JcY LYjZY+BGH+j56x6jPnm0EVNIKu2iex6YT9iHEPI3rU1p0JlE2VUESowhPuebuUxCOYfV pWBCJ/cKY8OAoIk+G/WIfPNc8Qt1yf/nW/ngGJlUVcSe7iS/Hld5KnkcADlCOjfrItna nefLNQv/MnM0gpAIuHxmkyWq8eBIXPWvy2Iqlv9qrKTg89D9eSgU+YmAengK8B+o6K7v 5quYkvH33dO/ON/8u5Sq+XNf/6wnpANKDUCncRzlLI3th5wajf0BtpxdEnlzMmMDJWRv ZC2g== 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:references :mime-version:in-reply-to:date:dkim-signature; bh=yXovaXGmQ2hj+xhfXzlYPf6jy3g3M6Z97i9sJYKtL7o=; b=trzKxWGTN903wVYP9nExslTVC5cKI1FLxoOKdCZ9Fn4sK0dHoyzCgensr/N1n6PiNP TpVdLYwGA+pKdBYUjMUe567bpKqeAy54Xxc7Ruicvpk7WWR3Fj5jk9rRWN41zYjSzSgQ zc1IuLMYiLqAjBXc0g7JOSwsXVdGmbAnN4i7MABuDdinp6cJRIHnrddRZFNSuviPCRQU WOf+HPa1Q5U+CUSM/gccH2OEaU/AQjTV1Vo9TBq3Wg2fRzgSleYs0E8CdtFcY8vGWsIl AhTgZ1FAGykjjE1lcxqww1VQcYCiwSYRny4WvZZyOAAO6mAZZmrhRcpuKSxq2TZeCRe5 2Xjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=XUqeRrYp; 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 s26-20020aa7cb1a000000b0046cc0300c0fsi11123748edt.581.2022.12.21.14.25.21; Wed, 21 Dec 2022 14:25:45 -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=XUqeRrYp; 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 S234986AbiLUWYo (ORCPT + 99 others); Wed, 21 Dec 2022 17:24:44 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36276 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234953AbiLUWYc (ORCPT ); Wed, 21 Dec 2022 17:24:32 -0500 Received: from mail-pl1-x649.google.com (mail-pl1-x649.google.com [IPv6:2607:f8b0:4864:20::649]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7FC8027170 for ; Wed, 21 Dec 2022 14:24:29 -0800 (PST) Received: by mail-pl1-x649.google.com with SMTP id c12-20020a170902d48c00b00189e5443387so126066plg.15 for ; Wed, 21 Dec 2022 14:24:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=yXovaXGmQ2hj+xhfXzlYPf6jy3g3M6Z97i9sJYKtL7o=; b=XUqeRrYpmjbz24aOUCRdZhU/hasfAHWkBLZ4lTvglulOiCrqV4g30TxCuKN75BwGCU 4LXBLsZDthjsLf+2AAZudjXxcPvh/idm+4kfCCahPLRDtw4awMTHPJRM+3GLuCE2z2xW UXWY9noDLDSwD7MOFEHp549vimmJUdsZlZLlkat6N1yZkyca8ji4la9bIC+7aRA7MNjJ YtbFM6nqgK4y9kxkqqzX2AYDFPzZeTYjsNQEJ2emwoQuCWJEmRyoXNEcGGrMTsjlBGmI JZjMUvnzAPwUHXLd7BkZn8APBej2IkOxylMhK0+Z0QbMqCvFV2hi5iU8e6JCqA3ryxd/ vIwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=yXovaXGmQ2hj+xhfXzlYPf6jy3g3M6Z97i9sJYKtL7o=; b=0TuAqbB2rmzGeIoqEtRGCLJTNwjCCqIuY4Lu4U5VCC10Z38f9pvtSl8cb9oo3TYnRn 2CGLtAYUViLC2jMKGAeL3aOPEJBbxG59nQt7ve8apuHWvcQpL4wiXXCqtaQ9VUqQEri2 oN3dST/0B5gYZlUyGELemAm9St4G9OQQ77YY1ln59+M9EB6M9fZzftNX9hNjTDNcdCdP njB8X41QrXrCd8S4EET3NBUB0kLN7/OgbKtCMXf5K3JWCoy2xcfcHjzdEo/8I4jix16e U+9E0gm7GbsWydf+EiMC/H88cYzauLapxL3PQWDeH257NgAhETxJmv85P/WmF1Kqfpww H37A== X-Gm-Message-State: AFqh2kpBZpoWykiSmuD8dvv65obE2uJu+PHJVdLELw3UxRKQrt2JPlhO Olusev+qNXu0fnlNUqEiAoW1bxLozpN/gSB1Wz29CDnAluYrEyS9gmI22dJqrn42u/aiismLsR6 u4s95AfrwHRgGxr89FE2KFKQi/IWbyx+Zajd1KNV7mkDE6DOFln//bVohIArHItQ92Wd0FCg0 X-Received: from sweer.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:e45]) (user=bgardon job=sendgmr) by 2002:a17:90a:9913:b0:225:aa06:8fcb with SMTP id b19-20020a17090a991300b00225aa068fcbmr167806pjp.78.1671661468931; Wed, 21 Dec 2022 14:24:28 -0800 (PST) Date: Wed, 21 Dec 2022 22:24:08 +0000 In-Reply-To: <20221221222418.3307832-1-bgardon@google.com> Mime-Version: 1.0 References: <20221221222418.3307832-1-bgardon@google.com> X-Mailer: git-send-email 2.39.0.314.g84b9a713c41-goog Message-ID: <20221221222418.3307832-5-bgardon@google.com> Subject: [RFC 04/14] KVM: x86/MMU: Expose functions for paging_tmpl.h From: Ben Gardon To: linux-kernel@vger.kernel.org, kvm@vger.kernel.org Cc: Paolo Bonzini , Peter Xu , Sean Christopherson , David Matlack , Vipin Sharma , Nagareddy Reddy , Ben Gardon 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?1752864176882421661?= X-GMAIL-MSGID: =?utf-8?q?1752864176882421661?= In preparation for moving paging_tmpl.h to shadow_mmu.c, expose various functions it needs through mmu_internal.h. This includes modifying the BUILD_MMU_ROLE_ACCESSOR macro so that it does not automatically include the static label, since some but not all of the accessors are needed by paging_tmpl.h. No functional change intended. Signed-off-by: Ben Gardon --- arch/x86/kvm/mmu/mmu.c | 32 ++++++++++++++++---------------- arch/x86/kvm/mmu/mmu_internal.h | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 16 deletions(-) diff --git a/arch/x86/kvm/mmu/mmu.c b/arch/x86/kvm/mmu/mmu.c index bf14e181eb12..a17e8a79e4df 100644 --- a/arch/x86/kvm/mmu/mmu.c +++ b/arch/x86/kvm/mmu/mmu.c @@ -153,18 +153,18 @@ BUILD_MMU_ROLE_REGS_ACCESSOR(efer, lma, EFER_LMA); * and the vCPU may be incorrect/irrelevant. */ #define BUILD_MMU_ROLE_ACCESSOR(base_or_ext, reg, name) \ -static inline bool __maybe_unused is_##reg##_##name(struct kvm_mmu *mmu) \ +inline bool __maybe_unused is_##reg##_##name(struct kvm_mmu *mmu) \ { \ return !!(mmu->cpu_role. base_or_ext . reg##_##name); \ } BUILD_MMU_ROLE_ACCESSOR(base, cr0, wp); -BUILD_MMU_ROLE_ACCESSOR(ext, cr4, pse); +static BUILD_MMU_ROLE_ACCESSOR(ext, cr4, pse); BUILD_MMU_ROLE_ACCESSOR(ext, cr4, smep); -BUILD_MMU_ROLE_ACCESSOR(ext, cr4, smap); -BUILD_MMU_ROLE_ACCESSOR(ext, cr4, pke); -BUILD_MMU_ROLE_ACCESSOR(ext, cr4, la57); +static BUILD_MMU_ROLE_ACCESSOR(ext, cr4, smap); +static BUILD_MMU_ROLE_ACCESSOR(ext, cr4, pke); +static BUILD_MMU_ROLE_ACCESSOR(ext, cr4, la57); BUILD_MMU_ROLE_ACCESSOR(base, efer, nx); -BUILD_MMU_ROLE_ACCESSOR(ext, efer, lma); +static BUILD_MMU_ROLE_ACCESSOR(ext, efer, lma); static inline bool is_cr0_pg(struct kvm_mmu *mmu) { @@ -210,7 +210,7 @@ void kvm_flush_remote_tlbs_with_address(struct kvm *kvm, kvm_flush_remote_tlbs_with_range(kvm, &range); } -static gfn_t get_mmio_spte_gfn(u64 spte) +gfn_t get_mmio_spte_gfn(u64 spte) { u64 gpa = spte & shadow_nonpresent_or_rsvd_lower_gfn_mask; @@ -240,7 +240,7 @@ static bool check_mmio_spte(struct kvm_vcpu *vcpu, u64 spte) return likely(kvm_gen == spte_gen); } -static int is_cpuid_PSE36(void) +int is_cpuid_PSE36(void) { return 1; } @@ -279,7 +279,7 @@ void walk_shadow_page_lockless_end(struct kvm_vcpu *vcpu) } } -static int mmu_topup_memory_caches(struct kvm_vcpu *vcpu, bool maybe_indirect) +int mmu_topup_memory_caches(struct kvm_vcpu *vcpu, bool maybe_indirect) { int r; @@ -818,8 +818,8 @@ static int kvm_handle_error_pfn(struct kvm_vcpu *vcpu, gfn_t gfn, kvm_pfn_t pfn) return -EFAULT; } -static int handle_abnormal_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault, - unsigned int access) +int handle_abnormal_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault, + unsigned int access) { /* The pfn is invalid, report the error! */ if (unlikely(is_error_pfn(fault->pfn))) @@ -1275,8 +1275,8 @@ static int handle_mmio_page_fault(struct kvm_vcpu *vcpu, u64 addr, bool direct) return RET_PF_RETRY; } -static bool page_fault_handle_page_track(struct kvm_vcpu *vcpu, - struct kvm_page_fault *fault) +bool page_fault_handle_page_track(struct kvm_vcpu *vcpu, + struct kvm_page_fault *fault) { if (unlikely(fault->rsvd)) return false; @@ -1338,7 +1338,7 @@ void kvm_arch_async_page_ready(struct kvm_vcpu *vcpu, struct kvm_async_pf *work) kvm_mmu_do_page_fault(vcpu, work->cr2_or_gpa, 0, true); } -static int kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) +int kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) { struct kvm_memory_slot *slot = fault->slot; bool async; @@ -1403,8 +1403,8 @@ static int kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault) * Returns true if the page fault is stale and needs to be retried, i.e. if the * root was invalidated by a memslot update or a relevant mmu_notifier fired. */ -static bool is_page_fault_stale(struct kvm_vcpu *vcpu, - struct kvm_page_fault *fault, int mmu_seq) +bool is_page_fault_stale(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault, + int mmu_seq) { struct kvm_mmu_page *sp = to_shadow_page(vcpu->arch.mmu->root.hpa); diff --git a/arch/x86/kvm/mmu/mmu_internal.h b/arch/x86/kvm/mmu/mmu_internal.h index 74a99b67f09e..957376fcb333 100644 --- a/arch/x86/kvm/mmu/mmu_internal.h +++ b/arch/x86/kvm/mmu/mmu_internal.h @@ -341,6 +341,22 @@ bool is_obsolete_sp(struct kvm *kvm, struct kvm_mmu_page *sp); void walk_shadow_page_lockless_begin(struct kvm_vcpu *vcpu); void walk_shadow_page_lockless_end(struct kvm_vcpu *vcpu); +int mmu_topup_memory_caches(struct kvm_vcpu *vcpu, bool maybe_indirect); bool need_topup_split_caches_or_resched(struct kvm *kvm); int topup_split_caches(struct kvm *kvm); + +bool is_page_fault_stale(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault, + int mmu_seq); +bool page_fault_handle_page_track(struct kvm_vcpu *vcpu, + struct kvm_page_fault *fault); +int kvm_faultin_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault); +int handle_abnormal_pfn(struct kvm_vcpu *vcpu, struct kvm_page_fault *fault, + unsigned int access); + +gfn_t get_mmio_spte_gfn(u64 spte); + +bool is_efer_nx(struct kvm_mmu *mmu); +bool is_cr4_smep(struct kvm_mmu *mmu); +bool is_cr0_wp(struct kvm_mmu *mmu); +int is_cpuid_PSE36(void); #endif /* __KVM_X86_MMU_INTERNAL_H */