From nobody Mon Feb 9 18:43:59 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail(p=none dis=none) header.from=citrix.com ARC-Seal: i=1; a=rsa-sha256; t=1576172005; cv=none; d=zohomail.com; s=zohoarc; b=OZMHj+rSJ90QoeqX1sSYyY30VCNjo0aQiI/k5/Nj0syVRhPwRaa4oJmBCjEAt2sIU6boXTEQKQDbnfV1To4Hms61MA9daJiwJEcWvUk3efkPMd2uzekkE9TsdedgC1OIjmsuRekKC8bl5Un8IxB1B/6Hgu8jWsFgkqGfcBcTQO4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1576172005; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Vfp3TQFwT3xsXSZck8DLzhnxRCt+zSJ6NNXv24VulfQ=; b=WltaWXWQw8wJypS2ZNcV0jyb+TpDvUHb7M7aiaehZe+5QLR5SYCMUq9Fz6V3sIXzBkm6pc77JGVAdCqMzYt++SWR3JDUUcfMXIp++zN+IGsC3mvesERTT2s4fKZ6CKeVHh6mHQ1lvzWYqfjavrAaiozlWcSeJXoncoWQXqdsCU4= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1576172005111705.2163842493866; Thu, 12 Dec 2019 09:33:25 -0800 (PST) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ifSKA-0002SP-8p; Thu, 12 Dec 2019 17:32:26 +0000 Received: from all-amaz-eas1.inumbo.com ([34.197.232.57] helo=us1-amaz-eas2.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1ifSK8-0002SK-S1 for xen-devel@lists.xenproject.org; Thu, 12 Dec 2019 17:32:24 +0000 Received: from esa5.hc3370-68.iphmx.com (unknown [216.71.155.168]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 5b563bf0-1d05-11ea-8dd6-12813bfff9fa; Thu, 12 Dec 2019 17:32:23 +0000 (UTC) X-Inumbo-ID: 5b563bf0-1d05-11ea-8dd6-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=citrix.com; s=securemail; t=1576171943; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=BONvafvW7Xehu3KlD6QfL+lTUEkUwUanZ7dAlhNMZG4=; b=e/j2Y4qCBEzSMlpja0h6fi0gKdKZjDPaZ5EjClO+l3mDsHYxgdPq12ZO 18UAtTx9QVrhq7XrTAM+wYpDdGxgJz8cev6KSTPvNl6YTNRG9HG22uTxI 3Y8uUAi3UHbvdWRYuo0TPRQgnkdNHR6C9cNNjTmVfoV3GBhgz0z3do6l2 c=; Authentication-Results: esa5.hc3370-68.iphmx.com; dkim=none (message not signed) header.i=none; spf=None smtp.pra=george.dunlap@citrix.com; spf=Pass smtp.mailfrom=George.Dunlap@citrix.com; spf=None smtp.helo=postmaster@mail.citrix.com Received-SPF: none (zohomail.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of george.dunlap@citrix.com) identity=pra; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="george.dunlap@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa5.hc3370-68.iphmx.com: domain of George.Dunlap@citrix.com designates 162.221.158.21 as permitted sender) identity=mailfrom; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="George.Dunlap@citrix.com"; x-conformance=sidf_compatible; x-record-type="v=spf1"; x-record-text="v=spf1 ip4:209.167.231.154 ip4:178.63.86.133 ip4:195.66.111.40/30 ip4:85.115.9.32/28 ip4:199.102.83.4 ip4:192.28.146.160 ip4:192.28.146.107 ip4:216.52.6.88 ip4:216.52.6.188 ip4:162.221.158.21 ip4:162.221.156.83 ip4:168.245.78.127 ~all" Received-SPF: None (esa5.hc3370-68.iphmx.com: no sender authenticity information available from domain of postmaster@mail.citrix.com) identity=helo; client-ip=162.221.158.21; receiver=esa5.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: XFd0hG5L7Ta2/CtgTkT82O25vEaz0c45jBuJz0anPaDKnR/cBGhVnwUTs19KosdsnKoCcSGlmk LZTtxSiGZ3UgijgSwwM1EFOg5dzue7yca73JUlFJBrjme5hR5QRpQAAYUjsWzVTft/E1UTz/Dm 5Sw1vD9T2jfj0SS+OibAgKb9adLxWcGqGTVpRzoOMMVpX0ugd6bwm96B9GBEOuYRb4fR22ez6X bO6awkJOr3q7NUgU7V3sGH0G+SdGVIiUTc3kXEdnw5YbYDPJY+apmOVlMIqgP1BEIwnHRElSPY TeU= X-SBRS: 2.7 X-MesageID: 9961409 X-Ironport-Server: esa5.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.69,306,1571716800"; d="scan'208";a="9961409" From: George Dunlap To: Date: Thu, 12 Dec 2019 17:32:00 +0000 Message-ID: <20191212173203.1692762-2-george.dunlap@citrix.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: <20191212173203.1692762-1-george.dunlap@citrix.com> References: <20191212173203.1692762-1-george.dunlap@citrix.com> MIME-Version: 1.0 Subject: [Xen-devel] [PATCH 1/4] x86/mm: Refactor put_page_from_l*e to reduce code duplication X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Andrew Cooper , George Dunlap , Jan Beulich Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) put_page_from_l[234]e have identical functionality for devalidating an N-1 entry which is a pagetable. But mystifyingly, they duplicate the code in slightly different arrangements that make it hard to tell that it's the same. Create a new function, put_pt_page(), which handles the common functionality; and refactor all the functions to be symmetric, differing only in the level of pagetable expected (and in whether they handle superpages). No functional change intended. Signed-off-by: George Dunlap Reviewed-by: Andrew Cooper --- CC: Andrew Cooper CC: Jan Beulich --- xen/arch/x86/mm.c | 89 +++++++++++++++-------------------------------- 1 file changed, 28 insertions(+), 61 deletions(-) diff --git a/xen/arch/x86/mm.c b/xen/arch/x86/mm.c index 7d4dd80a85..d8a0eb2aa5 100644 --- a/xen/arch/x86/mm.c +++ b/xen/arch/x86/mm.c @@ -1297,6 +1297,28 @@ static void put_data_page(struct page_info *page, bo= ol writeable) put_page(page); } =20 +static int put_pt_page(struct page_info *pg, struct page_info *ptpg, + unsigned int flags) +{ + int rc =3D 0; + + if ( flags & PTF_defer ) + { + ASSERT(!(flags & PTF_partial_set)); + current->arch.old_guest_ptpg =3D ptpg; + current->arch.old_guest_table =3D pg; + current->arch.old_guest_table_partial =3D false; + } + else + { + rc =3D _put_page_type(pg, flags | PTF_preemptible, ptpg); + if ( likely(!rc) ) + put_page(pg); + } + + return rc; +} + /* * NB. Virtual address 'l2e' maps to a machine address within frame 'pfn'. * Note also that this automatically deals correctly with linear p.t.'s. @@ -1304,8 +1326,6 @@ static void put_data_page(struct page_info *page, boo= l writeable) static int put_page_from_l2e(l2_pgentry_t l2e, unsigned long pfn, unsigned int flags) { - int rc =3D 0; - if ( !(l2e_get_flags(l2e) & _PAGE_PRESENT) || (l2e_get_pfn(l2e) =3D=3D= pfn) ) return 1; =20 @@ -1319,35 +1339,16 @@ static int put_page_from_l2e(l2_pgentry_t l2e, unsi= gned long pfn, ((1UL << (L2_PAGETABLE_SHIFT - PAGE_SHIFT)) - 1))); for ( i =3D 0; i < (1u << PAGETABLE_ORDER); i++, page++ ) put_data_page(page, writeable); - } - else - { - struct page_info *pg =3D l2e_get_page(l2e); - struct page_info *ptpg =3D mfn_to_page(_mfn(pfn)); =20 - if ( flags & PTF_defer ) - { - current->arch.old_guest_ptpg =3D ptpg; - current->arch.old_guest_table =3D pg; - current->arch.old_guest_table_partial =3D false; - } - else - { - rc =3D _put_page_type(pg, flags | PTF_preemptible, ptpg); - if ( likely(!rc) ) - put_page(pg); - } + return 0; } =20 - return rc; + return put_pt_page(l2e_get_page(l2e), mfn_to_page(_mfn(pfn)), flags); } =20 static int put_page_from_l3e(l3_pgentry_t l3e, unsigned long pfn, unsigned int flags) { - struct page_info *pg; - int rc; - if ( !(l3e_get_flags(l3e) & _PAGE_PRESENT) || (l3e_get_pfn(l3e) =3D=3D= pfn) ) return 1; =20 @@ -1365,50 +1366,16 @@ static int put_page_from_l3e(l3_pgentry_t l3e, unsi= gned long pfn, return 0; } =20 - pg =3D l3e_get_page(l3e); - - if ( flags & PTF_defer ) - { - ASSERT(!(flags & PTF_partial_set)); - current->arch.old_guest_ptpg =3D mfn_to_page(_mfn(pfn)); - current->arch.old_guest_table =3D pg; - current->arch.old_guest_table_partial =3D false; - return 0; - } - - rc =3D _put_page_type(pg, flags | PTF_preemptible, mfn_to_page(_mfn(pf= n))); - if ( likely(!rc) ) - put_page(pg); - - return rc; + return put_pt_page(l3e_get_page(l3e), mfn_to_page(_mfn(pfn)), flags); } =20 static int put_page_from_l4e(l4_pgentry_t l4e, unsigned long pfn, unsigned int flags) { - int rc =3D 1; - - if ( (l4e_get_flags(l4e) & _PAGE_PRESENT) && - (l4e_get_pfn(l4e) !=3D pfn) ) - { - struct page_info *pg =3D l4e_get_page(l4e); - - if ( flags & PTF_defer ) - { - ASSERT(!(flags & PTF_partial_set)); - current->arch.old_guest_ptpg =3D mfn_to_page(_mfn(pfn)); - current->arch.old_guest_table =3D pg; - current->arch.old_guest_table_partial =3D false; - return 0; - } - - rc =3D _put_page_type(pg, flags | PTF_preemptible, - mfn_to_page(_mfn(pfn))); - if ( likely(!rc) ) - put_page(pg); - } + if ( !(l4e_get_flags(l4e) & _PAGE_PRESENT) || (l4e_get_pfn(l4e) =3D=3D= pfn) ) + return 1; =20 - return rc; + return put_pt_page(l4e_get_page(l4e), mfn_to_page(_mfn(pfn)), flags); } =20 static int alloc_l1_table(struct page_info *page) --=20 2.24.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel