Received: by 2002:a05:6358:f14:b0:e5:3b68:ec04 with SMTP id b20csp2505956rwj; Mon, 19 Dec 2022 05:37:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf4LSFoONFSjoaX5luMX4CE4a9rHN363xNaXRb/dMZgG7kjsP+mO+DAnSuoj1z/l1peQwjol X-Received: by 2002:a05:6a20:a58e:b0:ac:44ab:be3b with SMTP id bc14-20020a056a20a58e00b000ac44abbe3bmr54132526pzb.60.1671457022872; Mon, 19 Dec 2022 05:37:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1671457022; cv=none; d=google.com; s=arc-20160816; b=cLCwAcvoELabSX0usWSVAO+lBKeGIh0eKPehHTGGknO4Q9XFnIsV6jGQQtolbrbSaX BBfYqRTCeqN/bkigxs4TIkXLoeU36EZ0x3ojvbxvHexExnOp1DV8clTCVitX65jLDA1P VWotnIrZjOB5bGn9CCezWBzJsry4OOmrpBGiZ/gMRNRnfWtfWtR5faJeRZiyQh8ALt64 G8nAvJ9y49qa4IRAQ6ZQyE9GY1Ot7r5XVxjZu9DsBXDMHxH8rxKyqk/HIXBUg4Z/Ckjg 4NCczrIQjwgKJ39CsdqmkNLCbzxbC5thnHN1xUNZ5YYu1wZkSmDLxk5L+Fbp1lYnhy/L wUJw== 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=nF7ws8r0mp70NFZAKD6xZ2YaUyIewxpp+mfAcRmI/lE=; b=gvoEnmixOkG6r//V5xEB0X4/978vrzql5MY8VHU5RnftVz3PiFS68wkkkcmBNxelD3 TLsTYT6OixWYWZXpfYmD0sN8vwiVARP5PPl1UMrElu4gZjdcD9prt4fBkBr+paQAa97E wervPR7W4uqfHu3WqIDGh3K2Ewt+FZpuToS8DbJ4lmJZiQ00RjzUBvJ3N3ElQV9KvN0P GAG3HGtr62VYjRqOyM9gqDhtH1lZxL1+1mjraQcHvQmBvvnkBfj6HZW7gUcKanzB8GNg qkzMhhCZKojFbJ8bs2+J7bqnY/H2WmM7WoYEOFZCioOsGbBFf/xYU8ib8R9unzGqJ3vX I88w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=g1HxN9Ao; 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=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id l185-20020a6388c2000000b004786230ec57si10381071pgd.454.2022.12.19.05.36.53; Mon, 19 Dec 2022 05:37:02 -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=@gmail.com header.s=20210112 header.b=g1HxN9Ao; 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=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231996AbiLSNBu (ORCPT + 70 others); Mon, 19 Dec 2022 08:01:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59798 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231292AbiLSNBr (ORCPT ); Mon, 19 Dec 2022 08:01:47 -0500 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4CA4E1151 for ; Mon, 19 Dec 2022 05:01:46 -0800 (PST) Received: by mail-wr1-x434.google.com with SMTP id f18so8548071wrj.5 for ; Mon, 19 Dec 2022 05:01:46 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=nF7ws8r0mp70NFZAKD6xZ2YaUyIewxpp+mfAcRmI/lE=; b=g1HxN9AozAKS9+jMF74tB5TvmlEFBJjcfudBC89GlKCAfEzYdjhDlTOMLw1v4GC9M2 GjP8gr8OOZ4Q/ezCBFDN7bJEDpnktEOT9WwtJVkTjC4TBI/ufyWIk+sfNm9SsrWbqbtY MgL7ZYMN8yOR9jgz7hp0Ob/3r4KEG27krKhra7ZeWBTjlsDg/ZVtT+jnYcZtPiPrs+yW deq9GwpLyALBVNLtShuymUfT3H5fhTGpSra60MRx5O7eFmJWFKgX7QTwG988WOtA8sS5 fGXNWssXt10JVr1UEZaaEeqqhlXoRrIycDX0nQIqWH0I68kEUhNRfw40y4IW3qSbkSvo yfUg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=nF7ws8r0mp70NFZAKD6xZ2YaUyIewxpp+mfAcRmI/lE=; b=UqNtAuJ2HlTUCszsOMKLEPzcROOVAZEutmSolJzSu5IuldZ5sz42z0JJCnMlc50N2J bAp4JzzK0cj6RPCL+L5kUOSMB5pAfgsjanHrxRiawkM3G0X3e1BZVqTvu/uuKfKDp/tv OS7diIaTVIzjrIZKismsVZ4UBcMMb2HGH31zzW82/fFwb2qb1IP62FOKksG4D+XPB53Z btlTrgn/YQ9eH6soAQ1YUhLo2ZZ0ai7ES84so1rk9LFZ8irR4gVor9LDSnxzNMqGBYbG KXpSD3birpeMtKhWz2GB/OuhatKkoZy7I5Hu8487B4/On44LNjC0zkH1UT1b1KVrSL7q U1lg== X-Gm-Message-State: ANoB5pksC0Rxsr3TmG1//+vSD5PEPvrHYCUJ3t0IL4nS6S2wRWf3yD7m DPVCvyaJ1Jtwf8E7Id9Wrco= X-Received: by 2002:a05:6000:170b:b0:242:806c:8612 with SMTP id n11-20020a056000170b00b00242806c8612mr31079743wrc.7.1671454904778; Mon, 19 Dec 2022 05:01:44 -0800 (PST) Received: from localhost ([2a00:23c5:dc8c:8701:1663:9a35:5a7b:1d76]) by smtp.gmail.com with ESMTPSA id u1-20020a5d6ac1000000b00241cfe6e286sm9921878wrw.98.2022.12.19.05.01.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Dec 2022 05:01:44 -0800 (PST) Date: Mon, 19 Dec 2022 13:01:43 +0000 From: Lorenzo Stoakes To: Baoquan He 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-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS 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 Mon, Dec 19, 2022 at 08:24:47PM +0800, Baoquan He wrote: > 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)); This is better as it avoids the slightly contradictory situation of checking for a condition we've asserted is not the case, but I would still far prefer keeping this as-is and placing the unlock before the BUG_ON(). This avoids explicitly and knowingly holding a lock over a BUG_ON() and is simple to implement, e.g.:- spin_lock(&vmap_area_lock); va = __find_vmap_area((unsigned long)addr, &vmap_area_root); if (va) va->flags &= ~VMAP_RAM; spin_unlock(&vmap_area_lock); BUG_ON(!va); > > 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. > Sure, it seems appropriate to clear it, I'm just unsure as to why you aren't just clearing both flags? Perhaps just set va->flags = 0? > > > > 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. OK looking through again closely I see you're absolutely right, I wondered whether you could somehow make a non-VMAP_BLOCK vread() operation be equivalent to a block one (only across the whole mapping), but I don't think you can.