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=-5.2 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_SANE_1 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 7E4C0C388F9 for ; Fri, 23 Oct 2020 11:02:16 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id CDDE121D43 for ; Fri, 23 Oct 2020 11:02:15 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CDDE121D43 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=suse.de Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id E1BF36B005D; Fri, 23 Oct 2020 07:02:14 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DCD536B0062; Fri, 23 Oct 2020 07:02:14 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CBEA16B0068; Fri, 23 Oct 2020 07:02:14 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0153.hostedemail.com [216.40.44.153]) by kanga.kvack.org (Postfix) with ESMTP id A14C56B005D for ; Fri, 23 Oct 2020 07:02:14 -0400 (EDT) Received: from smtpin17.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 32A991EE6 for ; Fri, 23 Oct 2020 11:02:14 +0000 (UTC) X-FDA: 77402900988.17.pear29_2710bef27259 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin17.hostedemail.com (Postfix) with ESMTP id 15DE3180D0181 for ; Fri, 23 Oct 2020 11:02:14 +0000 (UTC) X-HE-Tag: pear29_2710bef27259 X-Filterd-Recvd-Size: 2369 Received: from mx2.suse.de (mx2.suse.de [195.135.220.15]) by imf17.hostedemail.com (Postfix) with ESMTP for ; Fri, 23 Oct 2020 11:02:13 +0000 (UTC) X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.221.27]) by mx2.suse.de (Postfix) with ESMTP id E30AFB1AA; Fri, 23 Oct 2020 11:02:11 +0000 (UTC) Date: Fri, 23 Oct 2020 13:02:08 +0200 From: Oscar Salvador To: Laurent Cremmer Cc: Mike Kravetz , Andrew Morton , Mina Almasry , David Rientjes , linux-mm@kvack.org, Shuah Khan Subject: Re: [PATCH] hugetlb: fix locking in region_add,region_cgh,allocate_file_region_entries Message-ID: <20201023110204.GA3925@linux> References: <20201023074759.46605-1-laurent@oss.volkswagen.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20201023074759.46605-1-laurent@oss.volkswagen.com> User-Agent: Mutt/1.10.1 (2018-07-13) X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, 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. -- Oscar Salvador SUSE L3