From nobody Sun May 5 07:34:07 2024 Delivered-To: importer@patchew.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=1564762658; cv=none; d=zoho.com; s=zohoarc; b=Es9O0JCz1ehlLeKfv6bt0dGCi5NkF918Mec8kFRjBPVapVPXizFpK9B1Oy5VCNwz3tdnItdJj/T6nraj7x3uJS66jsQuN0TQxQTovYrHrZi5OdDjwSoz+2SayYbch101PRDU0rNzphqPbH/5Dpj6aZN73O8wY+MWECVJmiwE6w4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zoho.com; s=zohoarc; t=1564762658; h=Content-Type:Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To:ARC-Authentication-Results; bh=JCf4e80vNJSIdLjzwUkjnhB+y4owLN85WLDUUC03Mtk=; b=RBvRKxPo5WHWs2UmbmuoVA4Me7bidA/iO0IX7jdpsw3P2gmOCBLgxumS23GV22f2JGfeXyom2jf9QhlcP0lglbVPqAZGPaS3l6lwAwPCKH6yObEaDXkSlBmsZhves9ehGcBLjN1G5Flwio0d6ob9F/D4LEGdAQXw6maIRYAaC5Y= 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 1564762658301850.8929867080319; Fri, 2 Aug 2019 09:17:38 -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 1htaEA-00022b-M8; Fri, 02 Aug 2019 16:16:22 +0000 Received: from us1-rack-dfw2.inumbo.com ([104.130.134.6]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1htaE9-00022S-6s for xen-devel@lists.xenproject.org; Fri, 02 Aug 2019 16:16:21 +0000 Received: from esa4.hc3370-68.iphmx.com (unknown [216.71.155.144]) by us1-rack-dfw2.inumbo.com (Halon) with ESMTPS id dcdcffd5-b540-11e9-8980-bc764e045a96; Fri, 02 Aug 2019 16:16:20 +0000 (UTC) X-Inumbo-ID: dcdcffd5-b540-11e9-8980-bc764e045a96 Authentication-Results: esa4.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 (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; Received-SPF: None (esa4.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=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="george.dunlap@citrix.com"; x-conformance=sidf_compatible Received-SPF: Pass (esa4.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=esa4.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 ~all" Received-SPF: None (esa4.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=esa4.hc3370-68.iphmx.com; envelope-from="George.Dunlap@citrix.com"; x-sender="postmaster@mail.citrix.com"; x-conformance=sidf_compatible IronPort-SDR: hAcvFRb5TIqJOsVdWHhDr7f7WeHBHABccqioPSVd6tDJPs2QfJ9G6v63iH1e1fDO9belvulNtP vissyUhsVxX/3aXOPSXW3XPXeyX2sZYYQWqJwaMl5TzRapMmT04OoGpm7RVkQZcV6Y5peYHv47 uQ/mB11x+goSlvVSmBKDFUPJ3s+hhft5cnVrMV6MFCykEj9x6YSo/++qsdaPy3Shiqwx3Llwn+ t4azuAoJUSlp8N12Fe0Wg1ipnclFVHvcc+05pCqXYJWSRPRxwLZTbrIvD8ZuE1lqdxgoXxEjcp Q+4= X-SBRS: 2.7 X-MesageID: 3952364 X-Ironport-Server: esa4.hc3370-68.iphmx.com X-Remote-IP: 162.221.158.21 X-Policy: $RELAYED X-IronPort-AV: E=Sophos;i="5.64,338,1559534400"; d="scan'208";a="3952364" From: George Dunlap To: Date: Fri, 2 Aug 2019 17:16:11 +0100 Message-ID: <20190802161611.4145-1-george.dunlap@citrix.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] mm: Safe to clear PGC_allocated on xenheap pages without an extra reference 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 , Paul Durrant , 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" Commits ec83f825627 "mm.h: add helper function to test-and-clear _PGC_allocated" (and subsequent fix-up 44a887d021d "mm.h: fix BUG_ON() condition in put_page_alloc_ref()") introduced a BUG_ON() to detect unsafe behavior of callers. Unfortunately this condition still turns out to be too strict. xenheap pages are somewhat "magic": calling free_domheap_pages() on them will not cause free_heap_pages() to be called: whichever part of Xen allocated them specially must call free_xenheap_pages() specifically. (They'll also be handled appropriately at domain destruction time.) Only crash Xen when put_page_alloc_ref() finds only a single refcount if the page is not a xenheap page. Signed-off-by: George Dunlap Reviewed-by: Jan Beulich --- NB this has been compile-tested only. CC: Andrew Cooper CC: Jan Beulich CC: Paul Durrant --- xen/include/xen/mm.h | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/xen/include/xen/mm.h b/xen/include/xen/mm.h index 977e45aae7..297fc6ad7b 100644 --- a/xen/include/xen/mm.h +++ b/xen/include/xen/mm.h @@ -666,15 +666,20 @@ static inline void share_xen_page_with_privileged_gue= sts( static inline void put_page_alloc_ref(struct page_info *page) { /* - * Whenever a page is assigned to a domain then the _PGC_allocated bit - * is set and the reference count is set to at least 1. This function - * clears that 'allocation reference' but it is unsafe to do so without - * the caller holding an additional reference. I.e. the allocation - * reference must never be the last reference held. + * Whenever a page is assigned to a domain then the _PGC_allocated + * bit is set and the reference count is set to at least 1. This + * function clears that 'allocation reference' but it is unsafe to + * do so to domheap pages without the caller holding an additional + * reference. I.e. the allocation reference must never be the last + * reference held. + *=20 + * (It's safe for xenheap pages, because put_page() will not cause + * them to be freed.) */ if ( test_and_clear_bit(_PGC_allocated, &page->count_info) ) { - BUG_ON((page->count_info & PGC_count_mask) <=3D 1); + BUG_ON((page->count_info & PGC_count_mask) <=3D 1 && + !(page->count_info & PGC_xen_heap)); put_page(page); } } --=20 2.20.1 _______________________________________________ Xen-devel mailing list Xen-devel@lists.xenproject.org https://lists.xenproject.org/mailman/listinfo/xen-devel