Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp2538217rwb; Fri, 20 Jan 2023 04:23:13 -0800 (PST) X-Google-Smtp-Source: AMrXdXvVPJvmcUYvWmk9dfrfv77KpLZ47NB0lbHd6ZBfkjaJLxKUmmzIYB/3PzC5fomPMurRA6eZ X-Received: by 2002:a17:907:8b09:b0:873:2612:e12c with SMTP id sz9-20020a1709078b0900b008732612e12cmr15732145ejc.21.1674217393767; Fri, 20 Jan 2023 04:23:13 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674217393; cv=none; d=google.com; s=arc-20160816; b=WP60okph/0UkFn1l5Ya18Yp7MQczWu8/PFdFqfuXDh9WUhaTwSEughFj2MVeqVYfy5 Bwbwi+nheqXQ7t/rPk4umRlk01NqZqnq34D/+PduIdOGwuCGaqPLRacZhYM6KMgukhcu gU0LcBY84Y6PM1uI7CM22m2nteMU6mafPhRGnIcafZGpt2S5pCchw8jkGekGoJCgHCcY 2SfMV6K3iT0dPAWYo4Wxdtw8KhL9U62zIAlO/Oq3FEst1wtVQIROC2OcBvO71VwkC3Qn 65eW73QIU3LPz04gXOcTp545Vayz8ZPJzgyZA8bZTBDAevStgTsr4yDof7uMfEfZigCw JE3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=RPwVKRrBRFK3jFjJvU5Sg6lMI3S9/OL0NPdp1XhCJto=; b=IX7/pAN3SsA7f/wpjIWVJc3sI5M84jIBjoFRoj95XDn6LBzeg6XKWejFkui1B6X/ug FZ9mmyzr+SUKoop3qbA+6XEU7bvJaVUgPzMJ5hR3xZfeYrwCzwJqbYI5br6gADP2WDm6 R0xUY2fhnxGLAJeJNQLcPG+lIoJf9PkcdhkoWmNECCyQ65lmlNNtMzYA74jofWa9semC kYr0F2Ci3jc3wxFW8ZPStoloeI6sVKbZvrmREqoMhb+pZC2igi/6n4AOC8UTinIqXuaZ EGynmWsiLNJkMc/2/noK6ysGiJTSkO1ceEj5ZFfOjBVJlDgUk57whqgZNK67QUnY95fr ByLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=HmBRtxFm; 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 y15-20020a056402358f00b0049df78b34efsi22061524edc.57.2023.01.20.04.23.01; Fri, 20 Jan 2023 04:23:13 -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=HmBRtxFm; 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 S229948AbjATLzF (ORCPT + 49 others); Fri, 20 Jan 2023 06:55:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229593AbjATLzE (ORCPT ); Fri, 20 Jan 2023 06:55:04 -0500 Received: from mail-ej1-x631.google.com (mail-ej1-x631.google.com [IPv6:2a00:1450:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 198FACA3B for ; Fri, 20 Jan 2023 03:55:01 -0800 (PST) Received: by mail-ej1-x631.google.com with SMTP id rl14so9998694ejb.2 for ; Fri, 20 Jan 2023 03:55:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=RPwVKRrBRFK3jFjJvU5Sg6lMI3S9/OL0NPdp1XhCJto=; b=HmBRtxFmYcIFCweRBMNq8Thv74hXRM0L2mgce9nbGVg0S8+P4nklS3yKaT0Wz7FfuH v8SZqvwZxN4pGhDGC8Quq5M4gW+yIYhL7C8JwgUZzLxCPeeTjPQ0OGwProzMWc7jVEil upe1a3/iJ2OsvrydAwFNINR3CTvQhvd9g8ldmQ1mE1ZbcxLxwY/aysLaJaviBN+TJJtR MxIdfYoNk2n3sG8VrOqNVsIOI+Jiaih1IuptF6Amlfuq6/UBlcecC1c8PGs0+pVZhrwp cpP0IOk6H+je5+ZveR5aMnjaSUamOjGZOc6383K3IRES+wjgfaJ8V+6SXuKdsaH7Q+TE zSsA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=RPwVKRrBRFK3jFjJvU5Sg6lMI3S9/OL0NPdp1XhCJto=; b=uoKjR5V/cJBjhoD5yUf5faIwdU9BryWMoF1t9a61zg7NxAmlYUZFZA8OSwtgC6Bfrw fXNpHfeSIMxKrr+oDEE2nr4Wq/MIfWGExQ9uZ6tt2J7QAsOsRMLGLxMMIRAeaDBKbbUF Y22Km0QOd1ytO1Y9TwYQOkvAwvy44JzRGyTz+lpCUtW4c14OrSdtPqzyHqqpIEXDY4Kj mI9uZjdWhB9tLVHKWcnVsbPCj/BtO5Gel8fzpqGFkZgHq0tLocaacsBPzPQGf6vgGla/ 7G4j3m6VJrYaiPmcjhyggGn1J0p2l/gHTobbYo79ju18nRDElaSwSqLeMS457zW5dG4p 6FoQ== X-Gm-Message-State: AFqh2kpfxTGGkrapg90HI5se6qGmIfiSwB+heEqlsPMQy9qb5SBDx5Qr FRDWs2vtHPBdZgju1or7zSehWXcb6vXkfBWIo+A= X-Received: by 2002:a17:906:5a54:b0:84c:4d1:5e9a with SMTP id my20-20020a1709065a5400b0084c04d15e9amr1000372ejc.297.1674215699383; Fri, 20 Jan 2023 03:54:59 -0800 (PST) MIME-Version: 1.0 References: <20230113031921.64716-1-bhe@redhat.com> <20230113031921.64716-4-bhe@redhat.com> In-Reply-To: From: Uladzislau Rezki Date: Fri, 20 Jan 2023 12:54:47 +0100 Message-ID: Subject: Re: [PATCH v3 3/7] mm/vmalloc.c: allow vread() to read out vm_map_ram areas To: Baoquan He Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, lstoakes@gmail.com, stephen.s.brennan@oracle.com, willy@infradead.org, akpm@linux-foundation.org, hch@infradead.org Content-Type: text/plain; charset="UTF-8" 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 01/19/23 at 05:52pm, Baoquan He wrote: > > On 01/16/23 at 12:50pm, Uladzislau Rezki wrote: > > > On Fri, Jan 13, 2023 at 11:19:17AM +0800, Baoquan He wrote: > > > > Currently, vread can read out vmalloc areas which is associated with > > > > a vm_struct. While this doesn't work for areas created by vm_map_ram() > > > > interface because it doesn't have an associated vm_struct. Then in vread(), > > > > these areas are all skipped. > > > > > > > > Here, add a new function vmap_ram_vread() to read out vm_map_ram areas. > > > > The area created with vmap_ram_vread() interface directly can be handled > > > > like the other normal vmap areas with aligned_vread(). While areas > > > > which will be further subdivided and managed with vmap_block need > > > > carefully read out page-aligned small regions and zero fill holes. > > > > > > > > Signed-off-by: Baoquan He > > > > --- > > > > mm/vmalloc.c | 80 +++++++++++++++++++++++++++++++++++++++++++++++----- > > > > 1 file changed, 73 insertions(+), 7 deletions(-) > > > > > > > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > > > > index ab4825050b5c..13875bc41e27 100644 > > > > --- a/mm/vmalloc.c > > > > +++ b/mm/vmalloc.c > > > > @@ -3544,6 +3544,65 @@ static int aligned_vread(char *buf, char *addr, unsigned long count) > > > > return copied; > > > > } > > > > > > > > +static void vmap_ram_vread(char *buf, char *addr, int count, unsigned long flags) > > > > +{ > > > > + char *start; > > > > + struct vmap_block *vb; > > > > + unsigned long offset; > > > > + unsigned int rs, re, n; > > > > + > > > > + /* > > > > + * If it's area created by vm_map_ram() interface directly, but > > > > + * not further subdividing and delegating management to vmap_block, > > > > + * handle it here. > > > > + */ > > > > + if (!(flags & VMAP_BLOCK)) { > > > > + aligned_vread(buf, addr, count); > > > > + return; > > > > + } > > > > + > > > > + /* > > > > + * Area is split into regions and tracked with vmap_block, read out > > > > + * each region and zero fill the hole between regions. > > > > + */ > > > > + vb = xa_load(&vmap_blocks, addr_to_vb_idx((unsigned long)addr)); > > > > + > > > > + spin_lock(&vb->lock); > > > > + if (bitmap_empty(vb->used_map, VMAP_BBMAP_BITS)) { > > > > > > > CPU-X invokes free_vmap_block() whereas we take the vb->lock and do > > > some manipulations with vb that might be already freed over RCU-core. > > > > > > Should we protect it by the rcu_read_lock() also here? > > > > Just go over the vb and vbq code again, seems we don't need the > > rcu_read_lock() here. The rcu lock is needed when operating on the > > vmap_block_queue->free list. I don't see race between the vb accessing > > here and those list adding or removing on vmap_block_queue->free with > > rcu. If I miss some race windows between them, please help point out. > > > > However, when I check free_vmap_block(), I do find a risk. As you said, > > Forgot to add details about why there's no race between free_vmap_block() > and vmap_ram_vread() because we have taken vmap_area_lock at the beginning > of vread(). So, except of the missing checking on returned value from > xa_load(), free_vmap_block() either is blocked to wait for vmap_area_lock > before calling unlink_va(), or finishes calling unlink_va() to remove > the vmap from vmap_area_root tree. In both cases, no race happened. > Agree. xa_load()s return value should be checked. Because it can be that there is no vmap_block associated with an address if xa_erase() was done earlier. -- Uladzislau Rezki