Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp17237imm; Fri, 25 May 2018 13:19:47 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrbVhjrOs0pPqsXU7AVWbo4753dgxCuNn6sim0Q5s5hZHG3ZM3f7RexwERrsA/NyyWGVlVz X-Received: by 2002:a63:78c3:: with SMTP id t186-v6mr3045909pgc.93.1527279587224; Fri, 25 May 2018 13:19:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527279587; cv=none; d=google.com; s=arc-20160816; b=THYSFYdYLBXQMF5ZRmKbz08i4ci9/l2peUHwE5H5u8Q3aSt/g7SFB55Gs9hwiFCF0P lPFNmuSKmld7eSnZjoYYcnnCZEgZoXaYqWgVBK+9K3S8v9lXQLlvFeJhxg5Sj/wpcskk qLfFbOWeViAWm8gEVwfOeP8E9LC2UH+0RgDnmD2U8tWHhs9XXdSqxqoLSIunSbAhFfkd Jo1djHhz69fSiogJgprj3eLZIXc6wchR7V4yrqepv8lyVxbekAqaa6sy2NQaSSgVy05+ RwhdzvzRIXHSw6w/g3gSvQL6xppoj6g9qdsCbM2OtHR6IitZLPiU3Q2SYjXCdvNVCDDY tyAA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:message-id :subject:cc:to:from:date:dkim-signature:arc-authentication-results; bh=5JB8LLvqSezirheBin7AHndg6MrbuBlnTtV/kRZPAO0=; b=kOBxLsf+58qIB/TOI1P5UG3PCBNem53tBREzEadXIh5EdQZ9Q4qTEQnel8R6LleeOq KHi8QxEDX1pEluvjoJAztLtf982IU3EfwV7GfJqpXYwvke8AVczb6eQgVv+XZVsb8FxP CbseXRn/6ZpbNSZU25pMmEFNvicc8qrzhun2QHa890MMp1X2cRZAHUzvPTXETGaDubg1 YZBhTuQOR63kvdexU2L5zoSawiZcaEviOijriwAqUK8ev8qSOYGw2jTW61p0fhR1fZgv dOwIBAjhGhgKHFq3c9zlLkRILQuEFrKkybsbxJpdbgYttMQHTUR4vNntI3fl11ALAk6R AvJw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=AZB7dPxx; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s9-v6si25042237pfk.46.2018.05.25.13.19.32; Fri, 25 May 2018 13:19:47 -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; dkim=pass header.i=@google.com header.s=20161025 header.b=AZB7dPxx; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S968300AbeEYUQt (ORCPT + 99 others); Fri, 25 May 2018 16:16:49 -0400 Received: from mail-pf0-f174.google.com ([209.85.192.174]:35437 "EHLO mail-pf0-f174.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S967879AbeEYUQr (ORCPT ); Fri, 25 May 2018 16:16:47 -0400 Received: by mail-pf0-f174.google.com with SMTP id x9-v6so3076334pfm.2 for ; Fri, 25 May 2018 13:16:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:user-agent:mime-version; bh=5JB8LLvqSezirheBin7AHndg6MrbuBlnTtV/kRZPAO0=; b=AZB7dPxxO1nUYowCvEmr4e47DSAlPI1HjOJhKjLcdOTcA91SKWxTGBYR/helvbCvWv LMyIXncDIOacIljuwdU2XJkasoisGMT9oJcbIvpfo2Kb3x6dwfpZKMsCuTISWmCv0JoZ DQrK2JJuhMq6Kd8x1xNEeHo1SfTjYBsBCjjhSl267SNnCWd6OjreJZutFDq9CKwK6oa0 /+v/5f3BMN7C+lAi9BvBQZ8SY025VNV+T4l4dBb49SMwH5QD/8C3wNWEj9Vq+vZqKTJK 3Dwudu23VkmWr0L0oWlGE51TcUauHns4LLZ21QbztCbJ/IyV9YlGDbhBSbJk7R2PkbX0 cGhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:user-agent :mime-version; bh=5JB8LLvqSezirheBin7AHndg6MrbuBlnTtV/kRZPAO0=; b=BuvFe2ohlU732ZOvtHrqbycf04ORUAhssvtSqI9fdWl5FaEGxotI+vqn+6uAqCgK2R YXL9htDXRYyb6fcbnzNQSMEXHrucwDVqrLCFqIkrl2wqY8xIfXEe6NUbaGjuQErGyC2R lPMUIQ5KXaJICtXeNMItZhKqmUxewT74gMbf+XqQWuPiBHoUea0OuMsh1ziZ00a8bnS6 TznMK1gcyw35uEbxWs9eU+PpBxg63rO6POHANNx/ky++r1C2xaAagrnynGhBZIpSD52e 1cqfXaukZSCk9HiTyFKDrZEvSm/rM00ZCCk53kxOZ1H1xLw/3+JylchT1jHSrnhLTB4b MtgQ== X-Gm-Message-State: ALKqPweBr9GRuFNcT7tYfG4m11ZblmjOm5vg5b4EWGOSbPyE4Qgk9mrN qWz9EqcEWPJwdskOYKbXmn09sw== X-Received: by 2002:a63:69c3:: with SMTP id e186-v6mr3087448pgc.353.1527279407082; Fri, 25 May 2018 13:16:47 -0700 (PDT) Received: from [2620:15c:17:3:3a5:23a7:5e32:4598] ([2620:15c:17:3:3a5:23a7:5e32:4598]) by smtp.gmail.com with ESMTPSA id v16-v6sm76876940pfk.164.2018.05.25.13.16.46 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Fri, 25 May 2018 13:16:46 -0700 (PDT) Date: Fri, 25 May 2018 13:16:45 -0700 (PDT) From: David Rientjes X-X-Sender: rientjes@chino.kir.corp.google.com To: Andrew Morton cc: Mike Kravetz , "Aneesh Kumar K.V" , Naoya Horiguchi , Vlastimil Babka , linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [patch] mm, hugetlb_cgroup: suppress SIGBUS when hugetlb_cgroup charge fails Message-ID: User-Agent: Alpine 2.21 (DEB 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Signed-off-by: David Rientjes --- mm/hugetlb.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/mm/hugetlb.c b/mm/hugetlb.c --- 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; + } /* * 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; } /* @@ -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; + } 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); } int alloc_bootmem_huge_page(struct hstate *h)