From nobody Fri Apr 19 12:59:52 2024 Delivered-To: importer@patchew.org Received-SPF: none (zoho.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; Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1557837147; cv=none; d=zoho.com; s=zohoarc; b=JObkOJWKrb1G6Eyzl1LlJV4FvDWTAKoVa8u8v6krBuKR+zySnAuJU75l3er1ArdxDguyEJbIv5Ra6o/RkMA250hFAysbj9dt2+AoIlvy6aFMZEpdxr1KtpWEsfYZ6jHxtI314QTr0rXv16V5oy2lX3IIjYXkKbJOjGmeLsIAP9w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1557837147; 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:ARC-Authentication-Results; bh=Sd5LlFTLrSwuH9XsPqTgL8PejG5Vyahgchhl9qG0fuk=; b=PzKicfsbmc1KP1TQchi8Y0eij4+4MxFotSfZ0/m4lKUCtYT46XEY59V8yGROe50mtHtIM5kX9xQ4vkkqbd3Q9vvSEDEQtfgG/9cEBiQZkaXaSQlMH+kNNP774icTKoUuKBEhFx4sOHbS8v3ajYjx+2nj8koX5yy5JPxP5xb+N88= ARC-Authentication-Results: i=1; mx.zoho.com; spf=none (zoho.com: 192.237.175.120 is neither permitted nor denied by domain of lists.xenproject.org) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1557837147114967.7517917855666; Tue, 14 May 2019 05:32:27 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1hQWan-0005Lb-Q8; Tue, 14 May 2019 12:31:37 +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 1hQWan-0005LK-1a for xen-devel@lists.xenproject.org; Tue, 14 May 2019 12:31:37 +0000 Received: from foss.arm.com (unknown [217.140.101.70]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTP id 36ade63a-7644-11e9-a640-97876d6490b5; Tue, 14 May 2019 12:31:36 +0000 (UTC) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id A2CC4341; Tue, 14 May 2019 05:31:35 -0700 (PDT) Received: from e108454-lin.cambridge.arm.com (e108454-lin.cambridge.arm.com [10.1.196.50]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 6FB0F3F71E; Tue, 14 May 2019 05:31:34 -0700 (PDT) X-Inumbo-ID: 36ade63a-7644-11e9-a640-97876d6490b5 From: Julien Grall To: xen-devel@lists.xenproject.org Date: Tue, 14 May 2019 13:31:16 +0100 Message-Id: <20190514123125.29086-4-julien.grall@arm.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20190514123125.29086-1-julien.grall@arm.com> References: <20190514123125.29086-1-julien.grall@arm.com> Subject: [Xen-devel] [PATCH MM-PART3 v2 03/12] xen/arm: mm: Move out of xen_pt_update() the logic to update an entry 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: Oleksandr_Tyshchenko@epam.com, Julien Grall , Stefano Stabellini , Andrii Anisov MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" In preparation of rework of the Xen PT, the logic to update an entry in moved out in a separate function. Signed-off-by: Julien Grall Reviewed-by: Andrii Anisov Reviewed-by: Stefano Stabellini --- Changes in v2: - Add Andrii's reviewed-by --- xen/arch/arm/mm.c | 140 +++++++++++++++++++++++++++++---------------------= ---- 1 file changed, 74 insertions(+), 66 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 36e22fc9ad..f956aa6399 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -968,6 +968,76 @@ enum xenmap_operation { RESERVE }; =20 +static int xen_pt_update_entry(enum xenmap_operation op, unsigned long add= r, + mfn_t mfn, unsigned int flags) +{ + lpae_t pte, *entry; + lpae_t *third =3D NULL; + + entry =3D &xen_second[second_linear_offset(addr)]; + if ( !lpae_is_valid(*entry) || !lpae_is_table(*entry, 2) ) + { + int rc =3D create_xen_table(entry); + if ( rc < 0 ) { + printk("%s: L2 failed\n", __func__); + return rc; + } + } + + BUG_ON(!lpae_is_valid(*entry)); + + third =3D mfn_to_virt(lpae_get_mfn(*entry)); + entry =3D &third[third_table_offset(addr)]; + + switch ( op ) { + case INSERT: + case RESERVE: + if ( lpae_is_valid(*entry) ) + { + printk("%s: trying to replace an existing mapping addr=3D%= lx mfn=3D%"PRI_mfn"\n", + __func__, addr, mfn_x(mfn)); + return -EINVAL; + } + if ( op =3D=3D RESERVE ) + break; + pte =3D mfn_to_xen_entry(mfn, PAGE_AI_MASK(flags)); + pte.pt.ro =3D PAGE_RO_MASK(flags); + pte.pt.xn =3D PAGE_XN_MASK(flags); + BUG_ON(!pte.pt.ro && !pte.pt.xn); + pte.pt.table =3D 1; + write_pte(entry, pte); + break; + case MODIFY: + case REMOVE: + if ( !lpae_is_valid(*entry) ) + { + printk("%s: trying to %s a non-existing mapping addr=3D%lx= \n", + __func__, op =3D=3D REMOVE ? "remove" : "modify", a= ddr); + return -EINVAL; + } + if ( op =3D=3D REMOVE ) + pte.bits =3D 0; + else + { + pte =3D *entry; + pte.pt.ro =3D PAGE_RO_MASK(flags); + pte.pt.xn =3D PAGE_XN_MASK(flags); + if ( !pte.pt.ro && !pte.pt.xn ) + { + printk("%s: Incorrect combination for addr=3D%lx\n", + __func__, addr); + return -EINVAL; + } + } + write_pte(entry, pte); + break; + default: + BUG(); + } + + return 0; +} + static DEFINE_SPINLOCK(xen_pt_lock); =20 static int xen_pt_update(enum xenmap_operation op, @@ -978,78 +1048,16 @@ static int xen_pt_update(enum xenmap_operation op, { int rc =3D 0; unsigned long addr =3D virt, addr_end =3D addr + nr_mfns * PAGE_SIZE; - lpae_t pte, *entry; - lpae_t *third =3D NULL; =20 spin_lock(&xen_pt_lock); =20 for(; addr < addr_end; addr +=3D PAGE_SIZE, mfn =3D mfn_add(mfn, 1)) { - entry =3D &xen_second[second_linear_offset(addr)]; - if ( !lpae_is_valid(*entry) || !lpae_is_table(*entry, 2) ) - { - rc =3D create_xen_table(entry); - if ( rc < 0 ) { - printk("%s: L2 failed\n", __func__); - goto out; - } - } - - BUG_ON(!lpae_is_valid(*entry)); - - third =3D mfn_to_virt(lpae_get_mfn(*entry)); - entry =3D &third[third_table_offset(addr)]; - - switch ( op ) { - case INSERT: - case RESERVE: - if ( lpae_is_valid(*entry) ) - { - printk("%s: trying to replace an existing mapping addr= =3D%lx mfn=3D%"PRI_mfn"\n", - __func__, addr, mfn_x(mfn)); - rc =3D -EINVAL; - goto out; - } - if ( op =3D=3D RESERVE ) - break; - pte =3D mfn_to_xen_entry(mfn, PAGE_AI_MASK(flags)); - pte.pt.ro =3D PAGE_RO_MASK(flags); - pte.pt.xn =3D PAGE_XN_MASK(flags); - BUG_ON(!pte.pt.ro && !pte.pt.xn); - pte.pt.table =3D 1; - write_pte(entry, pte); - break; - case MODIFY: - case REMOVE: - if ( !lpae_is_valid(*entry) ) - { - printk("%s: trying to %s a non-existing mapping addr= =3D%lx\n", - __func__, op =3D=3D REMOVE ? "remove" : "modify= ", addr); - rc =3D -EINVAL; - goto out; - } - if ( op =3D=3D REMOVE ) - pte.bits =3D 0; - else - { - pte =3D *entry; - pte.pt.ro =3D PAGE_RO_MASK(flags); - pte.pt.xn =3D PAGE_XN_MASK(flags); - if ( !pte.pt.ro && !pte.pt.xn ) - { - printk("%s: Incorrect combination for addr=3D%lx\n= ", - __func__, addr); - rc =3D -EINVAL; - goto out; - } - } - write_pte(entry, pte); - break; - default: - BUG(); - } + rc =3D xen_pt_update_entry(op, addr, mfn, flags); + if ( rc ) + break; } -out: + /* * Flush the TLBs even in case of failure because we may have * partially modified the PT. This will prevent any unexpected --=20 2.11.0 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel