Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp37449imm; Fri, 25 May 2018 13:45:28 -0700 (PDT) X-Google-Smtp-Source: AB8JxZo1InENFShu7cNqNQfjGEX89Qvk3bh+NmtHvEqCsmfbPqUJ2zIZdIjsDn4aD1c3sClBo5d3 X-Received: by 2002:a17:902:8d8c:: with SMTP id v12-v6mr4062012plo.366.1527281128090; Fri, 25 May 2018 13:45:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527281128; cv=none; d=google.com; s=arc-20160816; b=ITRkd1ZrTqIRHhHzaXaoUdIB+o1+yWRyA1y2XhBQhBFWVotnODsU67PuxtZZOREZ0w Kv3ZOALZxzV/+u6tyf6udewzpqMg51Wqa1nGU0Ay/VNmcY5A8wnWqinx0GC2uufgF8vn 4syfjM//WXyVT+Xg98RPAfRnBkk9MqOnzqmynp+9B/y9Bj2ZpQsAZA/iRfDmYTUD5S+J todTa7IdEcMqsg/DhyR0HKQ27lWVvjGGVkb7dMzjfMaUNclPm1dqWE+hUDP/m7tktM5d ioZNcNL9VIzUh+D+d44o1SIIErorv2+ZoPKNW1vxtHrkOBuwxYBRC8iSdRaYtzTvwERz bm+g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :arc-authentication-results; bh=2Kmi1ER6cTd7+UYuHf/j8D/M7N6OxvkV30xvgdlnMK8=; b=LhEmWZz/gbnkNVhtUH0k+Sa+pJL8rZFYh2VtzElNW1rJpAnxcqC8NuRx8gkxqUb5NG /a6ecQTXFfIH74SSUvL9lHDRuKJ+u0ojgCC9bSmyi9lc7XGgtYkIGmUS167br02M0ITW gCtH6zI60HH8VyFdfm97XYLsObwFxV1g22fVNwKXZJ5R0cCPXACP7b0D2RKJsWrFEhAW uhqPDbg05ydloAmF6SUAEK4ZvbNA9QpItrmMbYxdDNo/3fPLOI9RZcmoX/MI8KK5xXa8 c3lc30G7tsDO0lZYGDxnGEkbzq5m+99Nrd7iQOFwkp50CjunaH0U/wYqcFsBuCwQfGcy j6FQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c6-v6si24125563pfi.102.2018.05.25.13.45.13; Fri, 25 May 2018 13:45:28 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S968429AbeEYUpC (ORCPT + 99 others); Fri, 25 May 2018 16:45:02 -0400 Received: from mail.linuxfoundation.org ([140.211.169.12]:60384 "EHLO mail.linuxfoundation.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S968275AbeEYUpB (ORCPT ); Fri, 25 May 2018 16:45:01 -0400 Received: from akpm3.svl.corp.google.com (unknown [104.133.9.71]) by mail.linuxfoundation.org (Postfix) with ESMTPSA id D70B0C21; Fri, 25 May 2018 20:45:00 +0000 (UTC) Date: Fri, 25 May 2018 13:44:59 -0700 From: Andrew Morton To: David Rientjes Cc: Mike Kravetz , "Aneesh Kumar K.V" , Naoya Horiguchi , Vlastimil Babka , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [patch] mm, hugetlb_cgroup: suppress SIGBUS when hugetlb_cgroup charge fails Message-Id: <20180525134459.5c6f8e06f55307f72b95a901@linux-foundation.org> In-Reply-To: References: X-Mailer: Sylpheed 3.6.0 (GTK+ 2.24.31; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 25 May 2018 13:16:45 -0700 (PDT) David Rientjes wrote: > When charging to a hugetlb_cgroup fails, alloc_huge_page() returns > ERR_PTR(-ENOSPC) which will cause VM_FAULT_SIGBUS to be returned to the > page fault handler. > > Instead, return the proper error code, ERR_PTR(-ENOMEM), so VM_FAULT_OOM > is handled correctly. This is consistent with failing mem cgroup charges > in the non-hugetlb fault path. > > At the same time, restructure the return paths of alloc_huge_page() so it > is consistent. Patch doesn't appear to match the changelog? > --- a/mm/hugetlb.c > +++ b/mm/hugetlb.c > @@ -2006,8 +2006,10 @@ struct page *alloc_huge_page(struct vm_area_struct *vma, > * code of zero indicates a reservation exists (no change). > */ > map_chg = gbl_chg = vma_needs_reservation(h, vma, addr); > - if (map_chg < 0) > - return ERR_PTR(-ENOMEM); > + if (map_chg < 0) { > + ret = -ENOMEM; > + goto out; > + } This doesn't change the return value. > /* > * Processes that did not create the mapping will have no > @@ -2019,8 +2021,8 @@ struct page *alloc_huge_page(struct vm_area_struct *vma, > if (map_chg || avoid_reserve) { > gbl_chg = hugepage_subpool_get_pages(spool, 1); > if (gbl_chg < 0) { > - vma_end_reservation(h, vma, addr); > - return ERR_PTR(-ENOSPC); > + ret = -ENOSPC; > + goto out_reservation; > } Nor does this. > /* > @@ -2049,8 +2051,10 @@ struct page *alloc_huge_page(struct vm_area_struct *vma, > if (!page) { > spin_unlock(&hugetlb_lock); > page = alloc_buddy_huge_page_with_mpol(h, vma, addr); > - if (!page) > + if (!page) { > + ret = -ENOSPC; > goto out_uncharge_cgroup; > + } Nor does this. > if (!avoid_reserve && vma_has_reserves(vma, gbl_chg)) { > SetPagePrivate(page); > h->resv_huge_pages--; > @@ -2087,8 +2091,10 @@ struct page *alloc_huge_page(struct vm_area_struct *vma, > out_subpool_put: > if (map_chg || avoid_reserve) > hugepage_subpool_put_pages(spool, 1); > +out_reservation: > vma_end_reservation(h, vma, addr); > - return ERR_PTR(-ENOSPC); > +out: > + return ERR_PTR(ret); > } > It would be nice if you could add a comment over alloc_huge_page() explaining the return values (at least). Why sometimes ENOMEM, other times ENOSPC?