From nobody Sat Apr 27 00:23:02 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org ARC-Seal: i=1; a=rsa-sha256; t=1589384673; cv=none; d=zohomail.com; s=zohoarc; b=fHSVHQm7vxdGM1OKWovb7gS2YMD05YLB5vLASJB9eHAvrcE9EsH40Y0sXd2BhQ7v7+u8CHFtnLinCj/P6nIo2cmggURqRIkxUFIK/ThwNX9Z1BKaGIq5hNScHMqwtojx2x6dqaC8Hk25Tg6OXXf270S8hi4B5z3X6HuxMFJJ650= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1589384673; h=Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:Message-ID:Sender:Subject:To; bh=/7oErC2oD1FcQ4fz06/kz/o4eYcq6WUr8ULBeUXJrcs=; b=PBSf++wSFDPZEeNBcoUlLnF/ZLDLDnxS/poWu/j4jJIwTHhL+jZtaT6fxjdetPar0BVXlh+u+Uzt/Y27zp4uwnPapcdb2500qrkT5GqZhycR4E+pRhHNlKoOYT+mXhcp6iVTDaPAuhY7/PBCJBpYWC+Zaau8F+2umwuHfqb1wYU= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) 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 1589384673897847.8117392109148; Wed, 13 May 2020 08:44:33 -0700 (PDT) Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jYtYE-00015c-0C; Wed, 13 May 2020 15:44:06 +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.92) (envelope-from ) id 1jYtYC-00015T-7A for xen-devel@lists.xenproject.org; Wed, 13 May 2020 15:44:04 +0000 Received: from mail.xenproject.org (unknown [104.130.215.37]) by us1-amaz-eas2.inumbo.com (Halon) with ESMTPS id 9211a456-9530-11ea-a3ac-12813bfff9fa; Wed, 13 May 2020 15:44:03 +0000 (UTC) Received: from xenbits.xenproject.org ([104.239.192.120]) by mail.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1jYtYA-0001ra-Kp; Wed, 13 May 2020 15:44:02 +0000 Received: from 54-240-197-236.amazon.com ([54.240.197.236] helo=u1bbd043a57dd5a.ant.amazon.com) by xenbits.xenproject.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.89) (envelope-from ) id 1jYtYA-000716-8Y; Wed, 13 May 2020 15:44:02 +0000 X-Inumbo-ID: 9211a456-9530-11ea-a3ac-12813bfff9fa DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=xen.org; s=20200302mail; h=Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: MIME-Version:Content-Type:Content-Transfer-Encoding:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=/7oErC2oD1FcQ4fz06/kz/o4eYcq6WUr8ULBeUXJrcs=; b=Mq0bonYakbRr3UnPTZ9WkzH/8R G2Kf6Bpl0KPZK8TutwBptlA3bz5URgiBzHc7xn1BKoKmgEjwqtjGfahzxnU/AAKDJKOAqCTazFBRk AOZDHlk+S0EaSFyvlYTzUvMmYBASA/J37D+Y30EdN5Mcu7XJ1CZCtcpxmQBuSvjh5xns=; From: Hongyan Xia To: xen-devel@lists.xenproject.org Subject: [PATCH] domain_page: handle NULL within unmap_domain_page() itself Date: Wed, 13 May 2020 16:43:33 +0100 Message-Id: X-Mailer: git-send-email 2.17.1 X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: Stefano Stabellini , Julien Grall , Wei Liu , Andrew Cooper , Ian Jackson , George Dunlap , Jan Beulich , Volodymyr Babchuk , =?UTF-8?q?Roger=20Pau=20Monn=C3=A9?= Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" From: Hongyan Xia The macro version UNMAP_DOMAIN_PAGE() does both NULL checking and variable clearing. Move NULL checking into the function itself so that the semantics is consistent with other similar constructs like XFREE(). This also eases the use unmap_domain_page() in error handling paths, where we only care about NULL checking but not about variable clearing. Signed-off-by: Hongyan Xia Acked-by: Jan Beulich Acked-by: Julien Grall Reviewed-by: Wei Liu --- xen/arch/arm/mm.c | 3 +++ xen/arch/x86/domain_page.c | 2 +- xen/include/xen/domain_page.h | 7 ++----- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/xen/arch/arm/mm.c b/xen/arch/arm/mm.c index 727107eefa..1b14f49345 100644 --- a/xen/arch/arm/mm.c +++ b/xen/arch/arm/mm.c @@ -498,6 +498,9 @@ void unmap_domain_page(const void *va) lpae_t *map =3D this_cpu(xen_dommap); int slot =3D ((unsigned long) va - DOMHEAP_VIRT_START) >> SECOND_SHIFT; =20 + if ( !va ) + return; + local_irq_save(flags); =20 ASSERT(slot >=3D 0 && slot < DOMHEAP_ENTRIES); diff --git a/xen/arch/x86/domain_page.c b/xen/arch/x86/domain_page.c index dd32712d2f..b03728e18e 100644 --- a/xen/arch/x86/domain_page.c +++ b/xen/arch/x86/domain_page.c @@ -181,7 +181,7 @@ void unmap_domain_page(const void *ptr) unsigned long va =3D (unsigned long)ptr, mfn, flags; struct vcpu_maphash_entry *hashent; =20 - if ( va >=3D DIRECTMAP_VIRT_START ) + if ( !va || va >=3D DIRECTMAP_VIRT_START ) return; =20 ASSERT(va >=3D MAPCACHE_VIRT_START && va < MAPCACHE_VIRT_END); diff --git a/xen/include/xen/domain_page.h b/xen/include/xen/domain_page.h index ab2be7b719..a182d33b67 100644 --- a/xen/include/xen/domain_page.h +++ b/xen/include/xen/domain_page.h @@ -73,11 +73,8 @@ static inline void unmap_domain_page_global(const void *= va) {}; #endif /* !CONFIG_DOMAIN_PAGE */ =20 #define UNMAP_DOMAIN_PAGE(p) do { \ - if ( p ) \ - { \ - unmap_domain_page(p); \ - (p) =3D NULL; \ - } \ + unmap_domain_page(p); \ + (p) =3D NULL; \ } while ( false ) =20 #endif /* __XEN_DOMAIN_PAGE_H__ */ --=20 2.17.1