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=-11.4 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,NICE_REPLY_A,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable 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 18DD7C433E7 for ; Tue, 20 Oct 2020 11:27:49 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B2C5322240 for ; Tue, 20 Oct 2020 11:27:48 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="aVGdcwaC" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2393047AbgJTL1r (ORCPT ); Tue, 20 Oct 2020 07:27:47 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:53757 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2392925AbgJTL1q (ORCPT ); Tue, 20 Oct 2020 07:27:46 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1603193265; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vJlBrtx7b8MuYro3yQ5487UyppQfsd5wQW5QKM9zah0=; b=aVGdcwaCIkCgt35zM/xERdMEwg5ybxwE6ckISmuzfTnGbAz5PhXufNAfQ6uxiWw+60Fjfp MZKYXmFOPF7mE8R/ZXydDHgCYyH5pbcl+uMzp8r7pFqDNJpKb3nSnxtKw0lP/VuUs6eX+f pecuH8Nr6bGVricj7b4A/LDmm8v09TY= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-131-S1eb4lJ8M4CZawKTkyqNKA-1; Tue, 20 Oct 2020 07:27:41 -0400 X-MC-Unique: S1eb4lJ8M4CZawKTkyqNKA-1 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id EE45A18A076B; Tue, 20 Oct 2020 11:27:39 +0000 (UTC) Received: from [10.36.114.141] (ovpn-114-141.ams2.redhat.com [10.36.114.141]) by smtp.corp.redhat.com (Postfix) with ESMTP id A17515B4A3; Tue, 20 Oct 2020 11:27:38 +0000 (UTC) Subject: Re: [PATCH] mm/cma.c: remove redundant cma_mutex lock To: Lecopzer Chen , linux-kernel@vger.kernel.org, linux-mm@kvack.org Cc: matthias.bgg@gmail.com, akpm@linux-foundation.org, yj.chiang@mediatek.com References: <20201020102241.3729-1-lecopzer.chen@mediatek.com> From: David Hildenbrand Organization: Red Hat GmbH Message-ID: <458cdc24-f637-ef4b-19de-513ceab14f23@redhat.com> Date: Tue, 20 Oct 2020 13:27:37 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.3.1 MIME-Version: 1.0 In-Reply-To: <20201020102241.3729-1-lecopzer.chen@mediatek.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 20.10.20 12:22, Lecopzer Chen wrote: > The cma_mutex which protects alloc_contig_range() was first appeared in > commit 7ee793a62fa8c ("cma: Remove potential deadlock situation"), > at that time, there is no guarantee the behavior of concurrency inside > alloc_contig_range(). > > After the commit 2c7452a075d4db2dc > ("mm/page_isolation.c: make start_isolate_page_range() fail if already isolated") > > However, two subsystems (CMA and gigantic > > huge pages for example) could attempt operations on the same range. If > > this happens, one thread may 'undo' the work another thread is doing. > > This can result in pageblocks being incorrectly left marked as > > MIGRATE_ISOLATE and therefore not available for page allocation. > The concurrency inside alloc_contig_range() was clarified. > > Now we can find that hugepage and virtio call alloc_contig_range() without > any lock, thus cma_mutex is "redundant" in cma_alloc() now. > > Signed-off-by: Lecopzer Chen > --- > mm/cma.c | 4 +--- > 1 file changed, 1 insertion(+), 3 deletions(-) > > diff --git a/mm/cma.c b/mm/cma.c > index 7f415d7cda9f..3692a34e2353 100644 > --- a/mm/cma.c > +++ b/mm/cma.c > @@ -38,7 +38,6 @@ > > struct cma cma_areas[MAX_CMA_AREAS]; > unsigned cma_area_count; > -static DEFINE_MUTEX(cma_mutex); > > phys_addr_t cma_get_base(const struct cma *cma) > { > @@ -454,10 +453,9 @@ struct page *cma_alloc(struct cma *cma, size_t count, unsigned int align, > mutex_unlock(&cma->lock); > > pfn = cma->base_pfn + (bitmap_no << cma->order_per_bit); > - mutex_lock(&cma_mutex); > ret = alloc_contig_range(pfn, pfn + count, MIGRATE_CMA, > GFP_KERNEL | (no_warn ? __GFP_NOWARN : 0)); > - mutex_unlock(&cma_mutex); > + > if (ret == 0) { > page = pfn_to_page(pfn); > break; > I guess this is fine. In case there is a race we return with -EBUSY - which is suboptimal (as it could just be a temporary issue if the other user backs off), but should be good enough for now. Acked-by: David Hildenbrand -- Thanks, David / dhildenb