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=-8.3 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 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 D762CC388F2 for ; Fri, 6 Nov 2020 09:35:10 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5E143208FE for ; Fri, 6 Nov 2020 09:35:10 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.b="LuMTOVeJ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5E143208FE Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=suse.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from list by lists.xenproject.org with outflank-mailman.20535.46487 (Exim 4.92) (envelope-from ) id 1kay90-0000oX-W6; Fri, 06 Nov 2020 09:34:54 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 20535.46487; Fri, 06 Nov 2020 09:34:54 +0000 X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kay90-0000oQ-T5; Fri, 06 Nov 2020 09:34:54 +0000 Received: by outflank-mailman (input) for mailman id 20535; Fri, 06 Nov 2020 09:34:53 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kay8z-0000oL-69 for xen-devel@lists.xenproject.org; Fri, 06 Nov 2020 09:34:53 +0000 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d43b57f9-cd03-4de3-ad00-975e46d5dc47; Fri, 06 Nov 2020 09:34:52 +0000 (UTC) Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 378BFACD5; Fri, 6 Nov 2020 09:34:51 +0000 (UTC) Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1kay8z-0000oL-69 for xen-devel@lists.xenproject.org; Fri, 06 Nov 2020 09:34:53 +0000 X-Inumbo-ID: d43b57f9-cd03-4de3-ad00-975e46d5dc47 Received: from mx2.suse.de (unknown [195.135.220.15]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id d43b57f9-cd03-4de3-ad00-975e46d5dc47; Fri, 06 Nov 2020 09:34:52 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1604655291; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1GwwWGinKRoKjPvFBHMATio3i/QUWXVKUREq8KUhXiA=; b=LuMTOVeJF0oNruLJnVnj4z8/cDi5pAxf01CqII3myeLP6M5nmrGK2qKKOipWr77hKiOWzz sm/+U+Pq5XC5w2J79I9o445llPQ9hoH1I+BjO4KkdfUaW6YzJLrVT56272x04mRPRUNnS8 LbZfpxaMdwvjAAgj80toYlVVjlfgvEM= Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id 378BFACD5; Fri, 6 Nov 2020 09:34:51 +0000 (UTC) Subject: [PATCH v2 1/9] x86/p2m: paging_write_p2m_entry() is a private function From: Jan Beulich To: "xen-devel@lists.xenproject.org" Cc: Andrew Cooper , Wei Liu , =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= , George Dunlap References: <4b63025f-164c-2e93-3d54-7a7f145ad046@suse.com> Message-ID: Date: Fri, 6 Nov 2020 10:34:50 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.4.0 MIME-Version: 1.0 In-Reply-To: <4b63025f-164c-2e93-3d54-7a7f145ad046@suse.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit As it gets installed by p2m_pt_init(), it doesn't need to live in paging.c. The function working in terms of l1_pgentry_t even further indicates its non-paging-generic nature. Move it and drop its paging_ prefix, not adding any new one now that it's static. This then also makes more obvious that in the EPT case we wouldn't risk mistakenly calling through the NULL hook pointer. Signed-off-by: Jan Beulich --- a/xen/arch/x86/mm/p2m-pt.c +++ b/xen/arch/x86/mm/p2m-pt.c @@ -108,6 +108,31 @@ static unsigned long p2m_type_to_flags(c } } +/* + * Atomically write a P2M entry and update the paging-assistance state + * appropriately. + * Arguments: the domain in question, the GFN whose mapping is being updated, + * a pointer to the entry to be written, the MFN in which the entry resides, + * the new contents of the entry, and the level in the p2m tree at which + * we are writing. + */ +static int write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn, + l1_pgentry_t *p, l1_pgentry_t new, + unsigned int level) +{ + struct domain *d = p2m->domain; + struct vcpu *v = current; + int rc = 0; + + if ( v->domain != d ) + v = d->vcpu ? d->vcpu[0] : NULL; + if ( likely(v && paging_mode_enabled(d) && paging_get_hostmode(v)) ) + rc = paging_get_hostmode(v)->write_p2m_entry(p2m, gfn, p, new, level); + else + safe_write_pte(p, new); + + return rc; +} // Find the next level's P2M entry, checking for out-of-range gfn's... // Returns NULL on error. @@ -594,7 +619,7 @@ p2m_pt_set_entry(struct p2m_domain *p2m, entry_content.l1 = l3e_content.l3; rc = p2m->write_p2m_entry(p2m, gfn, p2m_entry, entry_content, 3); - /* NB: paging_write_p2m_entry() handles tlb flushes properly */ + /* NB: write_p2m_entry() handles tlb flushes properly */ if ( rc ) goto out; } @@ -631,7 +656,7 @@ p2m_pt_set_entry(struct p2m_domain *p2m, /* level 1 entry */ rc = p2m->write_p2m_entry(p2m, gfn, p2m_entry, entry_content, 1); - /* NB: paging_write_p2m_entry() handles tlb flushes properly */ + /* NB: write_p2m_entry() handles tlb flushes properly */ if ( rc ) goto out; } @@ -666,7 +691,7 @@ p2m_pt_set_entry(struct p2m_domain *p2m, entry_content.l1 = l2e_content.l2; rc = p2m->write_p2m_entry(p2m, gfn, p2m_entry, entry_content, 2); - /* NB: paging_write_p2m_entry() handles tlb flushes properly */ + /* NB: write_p2m_entry() handles tlb flushes properly */ if ( rc ) goto out; } @@ -1107,7 +1132,7 @@ void p2m_pt_init(struct p2m_domain *p2m) p2m->recalc = do_recalc; p2m->change_entry_type_global = p2m_pt_change_entry_type_global; p2m->change_entry_type_range = p2m_pt_change_entry_type_range; - p2m->write_p2m_entry = paging_write_p2m_entry; + p2m->write_p2m_entry = write_p2m_entry; #if P2M_AUDIT p2m->audit_p2m = p2m_pt_audit_p2m; #else --- a/xen/arch/x86/mm/paging.c +++ b/xen/arch/x86/mm/paging.c @@ -941,27 +941,7 @@ void paging_update_nestedmode(struct vcp v->arch.paging.nestedmode = NULL; hvm_asid_flush_vcpu(v); } -#endif -int paging_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn, - l1_pgentry_t *p, l1_pgentry_t new, - unsigned int level) -{ - struct domain *d = p2m->domain; - struct vcpu *v = current; - int rc = 0; - - if ( v->domain != d ) - v = d->vcpu ? d->vcpu[0] : NULL; - if ( likely(v && paging_mode_enabled(d) && paging_get_hostmode(v) != NULL) ) - rc = paging_get_hostmode(v)->write_p2m_entry(p2m, gfn, p, new, level); - else - safe_write_pte(p, new); - - return rc; -} - -#ifdef CONFIG_HVM int __init paging_set_allocation(struct domain *d, unsigned int pages, bool *preempted) { --- a/xen/include/asm-x86/paging.h +++ b/xen/include/asm-x86/paging.h @@ -369,18 +369,6 @@ static inline void safe_write_pte(l1_pge *p = new; } -/* Atomically write a P2M entry and update the paging-assistance state - * appropriately. - * Arguments: the domain in question, the GFN whose mapping is being updated, - * a pointer to the entry to be written, the MFN in which the entry resides, - * the new contents of the entry, and the level in the p2m tree at which - * we are writing. */ -struct p2m_domain; - -int paging_write_p2m_entry(struct p2m_domain *p2m, unsigned long gfn, - l1_pgentry_t *p, l1_pgentry_t new, - unsigned int level); - /* * Called from the guest to indicate that the a process is being * torn down and its pagetables will soon be discarded.