Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp2432187rwj; Mon, 19 Dec 2022 04:38:37 -0800 (PST) X-Google-Smtp-Source: AMrXdXvjjFTpUFYGJM2/mzIbLfvUKmQnHOsibRXHA7ysP7TqgqeIVqDwvwmuKdki21VGaDQ/V9Uu X-Received: by 2002:a17:906:1444:b0:7c3:15cc:76d0 with SMTP id q4-20020a170906144400b007c315cc76d0mr10752059ejc.47.1671453516971; Mon, 19 Dec 2022 04:38:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671453516; cv=none; d=google.com; s=arc-20160816; b=p2kxGwOxh4R09fK+LBgtd6n25dZu4fB7c/LsLr93HMNRhlLkuUZHFf35Tmp3y6u+Zv q2+8skk/AZATUW5xON9Nwyi0Y5r7k4zDEDUUCcUTeFx5wHcfvvu/Oha8weMwi3nbgojc kTjptHT/a2SX3LU/Anvpwpschado3FYl1zaYUJ6QGSmiFGKK38m5UjtBOx8Gq+YzCXYi RWLtVyx062AMkCLL5ljn/GVbje5w4dPiIi7qAYBTQNLkt0iELqclelr9yNM9OAN8Xsja R68t8GnEQJYClvrLkYn+FUL0+0JrBe+o9nDeQN48O00T0EAhPApfZk/C/vTfbmA3DZGq IzZg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=ZJjKwl9viRzOtHWuPnaZZpLHGevx7oKmf4B2oFCUswI=; b=GE/sYSA7Y5e+H6XY8R4tZ5JgppKxEaxABZ6Adnr0BlqNdK7id0p+D+tsTNi6gF5rsP p9v1QhuHYZDtpvp6FEiNXbQ4s+qgBeKo2kHfKj5guQZjduuBYQlRa3NdaFnL0vATG+Qp aMCAVd5SEMYBZb5Bmn0tkFW1uWAZLlSA7HFcrHfF6+94BTxCIl29E2caMMFb5c4pWDv3 TTr/SqGtGI/9Lo9GXqSY/foMVY/gZ1GHYdlYqYio2LWWi1lV+2HCbJrS4g/fiWOSPe2y VrAJbbj3UYufvC2cqN9R8+LVcJadVHKMVdTm9cg1gV+JCOdNcebLRsp5p1J3ZDmRblAT A7Qw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SdHs9HtQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id qa34-20020a17090786a200b007f5e85a454csi7135504ejc.356.2022.12.19.04.38.14; Mon, 19 Dec 2022 04:38:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=SdHs9HtQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231447AbiLSMZr (ORCPT + 71 others); Mon, 19 Dec 2022 07:25:47 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37004 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229598AbiLSMZp (ORCPT ); Mon, 19 Dec 2022 07:25:45 -0500 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 02D36DEC2 for ; Mon, 19 Dec 2022 04:24:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1671452696; 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: in-reply-to:in-reply-to:references:references; bh=ZJjKwl9viRzOtHWuPnaZZpLHGevx7oKmf4B2oFCUswI=; b=SdHs9HtQ+GBdbnGKcGJKRYSNkxUxzFgFXUUw79E+P2AUSF5OQNHxCP6vv7kSIbBGw5dpQA 4X0zylzgdD1yVd35Ul6yYW9fQUX3/94rzVN/3pa/A4Ld5o/N3QO0S3fhWJVFzUIDwIHo5Q +eTQp2X9TdzGbiOpSqeq1FT1ZreGx74= Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-99-cGoprQawMYWMl6k7v-feqA-1; Mon, 19 Dec 2022 07:24:53 -0500 X-MC-Unique: cGoprQawMYWMl6k7v-feqA-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.rdu2.redhat.com [10.11.54.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 81DA01C07562; Mon, 19 Dec 2022 12:24:52 +0000 (UTC) Received: from localhost (ovpn-12-41.pek2.redhat.com [10.72.12.41]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 2413C1410DD7; Mon, 19 Dec 2022 12:24:50 +0000 (UTC) Date: Mon, 19 Dec 2022 20:24:47 +0800 From: Baoquan He To: Lorenzo Stoakes Cc: linux-kernel@vger.kernel.org, linux-mm@kvack.org, urezki@gmail.com, stephen.s.brennan@oracle.com, willy@infradead.org, akpm@linux-foundation.org, hch@infradead.org Subject: Re: [PATCH v2 2/7] mm/vmalloc.c: add flags to mark vm_map_ram area Message-ID: References: <20221217015435.73889-1-bhe@redhat.com> <20221217015435.73889-3-bhe@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 12/19/22 at 09:09am, Lorenzo Stoakes wrote: > On Mon, Dec 19, 2022 at 04:01:00PM +0800, Baoquan He wrote: > > On 12/17/22 at 11:44am, Lorenzo Stoakes wrote: > > > On Sat, Dec 17, 2022 at 09:54:30AM +0800, Baoquan He wrote: > > > > @@ -2229,8 +2236,12 @@ void vm_unmap_ram(const void *mem, unsigned int count) > > > > return; > > > > } > > > > > > > > - va = find_vmap_area(addr); > > > > + spin_lock(&vmap_area_lock); > > > > + va = __find_vmap_area((unsigned long)addr, &vmap_area_root); > > > > BUG_ON(!va); > > > > + if (va) > > > > + va->flags &= ~VMAP_RAM; > > > > + spin_unlock(&vmap_area_lock); > > > > debug_check_no_locks_freed((void *)va->va_start, > > > > (va->va_end - va->va_start)); > > > > free_unmap_vmap_area(va); > > > > > > Would it be better to perform the BUG_ON() after the lock is released? You > > > already check if va exists before unmasking so it's safe. > > > > It's a little unclear to me why we care BUG_ON() is performed before or > > after the lock released. We won't have a stable kernel after BUG_ON()(), > > right? > > BUG_ON()'s can be recoverable in user context and it would be a very simple > change that would not fundamentally alter anything to simply place the added > lines prior to the BUG_ON(). > > The code as-is doesn't really make sense anyway, you BUG_ON(!va) then check if > va is non-null, then immediately the function afterwards passes va around as if > it were not null, so I think it'd also be an aesthetic and logical improvement > :) In fact, I should not do the checking, but do the clearing anyway. If I change it as below, does it look better to you? diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 5e578563784a..369b848d097a 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -2253,8 +2253,7 @@ void vm_unmap_ram(const void *mem, unsigned int count) spin_lock(&vmap_area_lock); va = __find_vmap_area((unsigned long)addr, &vmap_area_root); BUG_ON(!va); - if (va) - va->flags &= ~VMAP_RAM; + va->flags &= ~VMAP_RAM; spin_unlock(&vmap_area_lock); debug_check_no_locks_freed((void *)va->va_start, (va->va_end - va->va_start)); > > > > > > > Also, do we want to clear VMAP_BLOCK here? > > > > I do, but I don't find a good place to clear VMAP_BLOCK. > > > > In v1, I tried to clear it in free_vmap_area_noflush() as below, > > Uladzislau dislikes it. So I remove it. My thinking is when we unmap and > > free the vmap area, the vmap_area is moved from vmap_area_root into > > &free_vmap_area_root. When we allocate a new vmap_area via > > alloc_vmap_area(), we will allocate a new va by kmem_cache_alloc_node(), > > the va->flags must be 0. Seems not initializing it to 0 won't impact > > thing. > > > > You are at this point clearing the VMAP_RAM flag though, so if it is unimportant > what the flags are after this call, why are you clearing this one? With my understanding, We had better do the clearing. Currently, from the code, not doing the clearing won't cause issue. If possible, I would like to clear it as below draft code. > > It is just a little confusing, I wonder whether the VMAP_BLOCK flag is necessary > at all, is it possible to just treat a non-VMAP_BLOCK VMAP_RAM area as if it > were simply a fully occupied block? Do we gain much by the distinction? Yeah, VMAP_BLOCK flag is necessary. vmap_block contains used region, or dirty/free regions. While the non-vmap_blcok vm_map_ram area is similar with the non vm_map_ram area. When reading out vm_map_ram regions, vmap_block regions need be treated differently. > > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > > index 5d3fd3e6fe09..d6f376060d83 100644 > > --- a/mm/vmalloc.c > > +++ b/mm/vmalloc.c > > @@ -1815,6 +1815,7 @@ static void free_vmap_area_noflush(struct vmap_area *va) > > > > spin_lock(&vmap_area_lock); > > unlink_va(va, &vmap_area_root); > > + va->flags = 0; > > spin_unlock(&vmap_area_lock); > > > > nr_lazy = atomic_long_add_return((va->va_end - va->va_start) >> > > > > > > > >