[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Xen-devel] [PATCH] mm: Safe to clear PGC_allocated on xenheap pages without an extra reference


  • To: George Dunlap <george.dunlap@xxxxxxxxxx>
  • From: Jan Beulich <JBeulich@xxxxxxxx>
  • Date: Mon, 5 Aug 2019 09:42:06 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1;spf=pass smtp.mailfrom=suse.com;dmarc=pass action=none header.from=suse.com;dkim=pass header.d=suse.com;arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=/7Lfm5av1aaWb61l1BsJssc8z72U/JxkV3plF7E/0aw=; b=UIQ36/rYEPx1vyfGd2o5rtMwXnQK5TUfe8wjJC20+CEzAESIuRv50zA/Ul5/utoHzH7bZ++ZaQCpoXH8UpCArlyc6KRcR664mLfHT+XKT+9f5miGlxyZVjCkWM1YZDbL14QhyC9JvDIlPKtkDq9ngJY5GcH9jWc+7aGmN8hC2uACySr+4Wjd8ZsE+Tx/A7EYIviGSzXJ2QmZSn31N7J+EKbuo7LX+kYgKQ+wSoOxEsr3x191dT2Cj7wYc+H7lAyAGvBkQfHtKuYAstwnwil1UXF/4b0RI4smd48TmaiqnzDbxkX2B6c+KQA1b92yMBcpCKOETSE2lmsB6PGnCcDR/w==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L1jNfzExitrLi6OKMjlNi+ubeMJ8K4WxCLQx6CAsjYWm/2KXh1RMbw5BHh23kDRxOj/ld4uu8so5bbcdUAAUlh1+2Fv64SZwCdOroGKH8C/TqcvjCxLpUrDExQFH0zL33FsR0RUiC5paLMrRUa3vVN4vI/9gswU8tJW6bBJ3eaWZOHJFeegmygAqQYvGnWvSPpXk8rT+oL7me1n00TqFR61ZmKMCSZtqdVUX6Rxc4soNbvVU+qg+6XhEC9Jr3m+YxtpiBLCfDaIaw32/2lhCFFZY0zFpadWJbxh6pcZAoOd/xMUzHnQFars+AvD3rM4lQhkENULYd26DcTfeomXPZw==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=JBeulich@xxxxxxxx;
  • Cc: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>, Paul Durrant <paul.durrant@xxxxxxxxxx>, Andrew Cooper <andrew.cooper3@xxxxxxxxxx>
  • Delivery-date: Mon, 05 Aug 2019 09:43:45 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHVSU2kZMdYId1RWUmjRXli///P+6bsUXoA
  • Thread-topic: [PATCH] mm: Safe to clear PGC_allocated on xenheap pages without an extra reference

On 02.08.2019 18:16, George Dunlap wrote:
> 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 <george.dunlap@xxxxxxxxxx>

Reviewed-by: Jan Beulich <jbeulich@xxxxxxxx>
albeit with a suggestion:

> --- a/xen/include/xen/mm.h
> +++ b/xen/include/xen/mm.h
> @@ -666,15 +666,20 @@ static inline void 
> share_xen_page_with_privileged_guests(
>   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.
> +     *
> +     * (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) <= 1);
> +        BUG_ON((page->count_info & PGC_count_mask) <= 1 &&
> +               !(page->count_info & PGC_xen_heap));

This can be had with a single conditional:

         BUG_ON((page->count_info & (PGC_xen_heap | PGC_count_mask)) <= 1);

Jan

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.