From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C82A2C55178 for ; Fri, 23 Oct 2020 11:33:09 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 1258420EDD for ; Fri, 23 Oct 2020 11:33:08 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=oss-volkswagen-com.20150623.gappssmtp.com header.i=@oss-volkswagen-com.20150623.gappssmtp.com header.b="K3RHLorU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1258420EDD Authentication-Results: mail.kernel.org; dmarc=fail (p=quarantine dis=none) header.from=oss.volkswagen.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 406D16B0068; Fri, 23 Oct 2020 07:33:08 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 3B8336B006C; Fri, 23 Oct 2020 07:33:08 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2A7FE6B006E; Fri, 23 Oct 2020 07:33:08 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0220.hostedemail.com [216.40.44.220]) by kanga.kvack.org (Postfix) with ESMTP id E72276B0068 for ; Fri, 23 Oct 2020 07:33:07 -0400 (EDT) Received: from smtpin22.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 9025282C1D28 for ; Fri, 23 Oct 2020 11:33:07 +0000 (UTC) X-FDA: 77402978814.22.waves69_600be7a27259 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin22.hostedemail.com (Postfix) with ESMTP id 679A818038E60 for ; Fri, 23 Oct 2020 11:33:07 +0000 (UTC) X-HE-Tag: waves69_600be7a27259 X-Filterd-Recvd-Size: 4487 Received: from mail-lf1-f68.google.com (mail-lf1-f68.google.com [209.85.167.68]) by imf30.hostedemail.com (Postfix) with ESMTP for ; Fri, 23 Oct 2020 11:33:06 +0000 (UTC) Received: by mail-lf1-f68.google.com with SMTP id a9so1665412lfc.7 for ; Fri, 23 Oct 2020 04:33:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oss-volkswagen-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=bFxiPwhw4pbZSiIdM94UUysHkhBByMWasSMRHtgUD4A=; b=K3RHLorURCsUc+L9pLkBq6R2DPtaIjFc4l2hOcZKaTvaAiuaH1fJm5KFlCDvC2Cfhy kt18gNex4elAj2N8aBZvjx3XXlPiWUxMQ8HFDta3qD51V55PgLghirmRRaMBo6WftefL nzjfWwGbCIcbLa/Q3sW1qJOsUVTIWQbZpIBLnbtj/4qAteKAxjKZljUCHUUK5RQSB8+J 6ugpQ80H5z6qNPJU+jw9cOaqmchiSiuQUTYDYc9EpVUgYWkjrtYwvLdxBu2YI3kvBPS9 LQ2By8T4CxwTtRLI0a26S8vmqbT7RbCOrJZLpjmSeR5vyYRuP+GMm/VKwwiIf/t4SWdE qyNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=bFxiPwhw4pbZSiIdM94UUysHkhBByMWasSMRHtgUD4A=; b=ZpVlbuRvOT5Kq2GEgT/PPRoo17FGjYKT7bACL0ksESjUpiiVHnFjAmKkzIA3tF7l/M K5TYUczFZ2YuGuzP3yokEmWZd6BwiYPxEEZK+qV5fbkUp7q2vmpp1caXwn3RuW9mfO4h vyh/A0RzpfWHf2Wx44qkuE8OwJ6/lDc1f2x/gtVbLuHoO6msw6/5tO+S+iLq/eTe26oo 4+i+YF+uTjAXlCsgqDIvN1vudBlBe2NLDA6siXuL2BVliwKu+bZevF9rpopd0N6u2yPM NAQsquhx/Y0Lc55xPeez2lFcvlxEgANVFRrlmGfPpwGvcY5jtIQ+/Nl6Tk+cIjaIeL9B +XAA== X-Gm-Message-State: AOAM533c1QdFo8hgVgwR9iTFc0kUm2LCM1VQ+giXkitG/xdhciqP/zpI k7Xof09GKV+FQxbiNNJernBEvQ6gWn4md2okW5Mt0Q== X-Google-Smtp-Source: ABdhPJzwTKLfHgCTgyhKgq5M0amcdEEwFjfWxcA4wnbzh5OfztevFkEEsK2K3p6Gq66vLfm4e49bj8PXGvmT1LkmtXE= X-Received: by 2002:a19:7e92:: with SMTP id z140mr637598lfc.299.1603452785389; Fri, 23 Oct 2020 04:33:05 -0700 (PDT) MIME-Version: 1.0 References: <20201023074759.46605-1-laurent@oss.volkswagen.com> <20201023110204.GA3925@linux> In-Reply-To: <20201023110204.GA3925@linux> From: Laurent Cremmer Date: Fri, 23 Oct 2020 13:32:54 +0200 Message-ID: Subject: Re: [PATCH] hugetlb: fix locking in region_add,region_cgh,allocate_file_region_entries To: Oscar Salvador Cc: Mike Kravetz , Andrew Morton , Mina Almasry , David Rientjes , linux-mm@kvack.org, Shuah Khan Content-Type: text/plain; charset="UTF-8" X-Bogosity: Ham, tests=bogofilter, spamicity=0.000270, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: > > On Fri, Oct 23, 2020 at 09:47:59AM +0200, Laurent Cremmer wrote: > > The third instance spotted by manual examination. > > It is friday, I might be overlooking something obvious, so bear with me. > > > In static long region_add(...) and static long region_cgh(...) , releasing > > the acquired lock when exiting via their error path was removed. > > This will cause these functions to return with a lock held if they do not > > succeed. > > If they do not suceed, it means that allocate_file_region_entries returned > non-zero, which means that we hit: > > spin_unlock(&resv->lock); > for (i = 0; i < to_allocate; i++) { > trg = kmalloc(sizeof(*trg), GFP_KERNEL); > if (!trg) > goto out_of_memory; > list_add(&trg->link, &allocated_regions); > } > > So, we do spin_unlock before jumping to out_of_memory. > > > A a new function allocate_file_region_entries was also introduced that > > must be called with a lock held and returned with the lock held. > > However the lock is temporarily released during processing but will not > > be reacquired on error. > > As stated above, region_add/region_chr exit immediately on allocate_file_region_entries > failure, so it does not need to acquire the lock. > I came to the same conclusion with the help of David's remarks :-) . And in the end, this patch would be more about fixing the readability of the code than fixing a live problem per-se. If it ain't broken, don't fix it as they say :-) It is friday, so thanks for taking the time to look into this. > > -- > Oscar Salvador > SUSE L3