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 Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1AB7C00A5A for ; Thu, 19 Jan 2023 09:52:17 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 72B2D6B0072; Thu, 19 Jan 2023 04:52:17 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 6DB556B0073; Thu, 19 Jan 2023 04:52:17 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 5C9F56B0074; Thu, 19 Jan 2023 04:52:17 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 4D9F16B0072 for ; Thu, 19 Jan 2023 04:52:17 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 1FEB3120D39 for ; Thu, 19 Jan 2023 09:52:17 +0000 (UTC) X-FDA: 80371083114.09.02FB904 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by imf11.hostedemail.com (Postfix) with ESMTP id 8196640005 for ; Thu, 19 Jan 2023 09:52:14 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="dfUP/umF"; spf=pass (imf11.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674121934; h=from:from:sender: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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fJ0BhK340QxC2FfzztYEdrbHd6f21nhkmEp3rkocFpc=; b=ne4/hA/k3hnwkj2DUP0m0RU3ocNcvRfiPvr9mGyYKfZGmXHFMOoIF0SCDJGvMvL3Br4XIo IkgQiBDEmac04eM/qd/QRx6kS6/hGSRVB2nAcjfPsrOBcT47cj1FTPVvMDsSPajF1k/u+0 sPg/bYT9EUof26HOgPhufHTWB8l8IQc= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b="dfUP/umF"; spf=pass (imf11.hostedemail.com: domain of bhe@redhat.com designates 170.10.129.124 as permitted sender) smtp.mailfrom=bhe@redhat.com; dmarc=pass (policy=none) header.from=redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674121934; a=rsa-sha256; cv=none; b=GknlfN+KNeE/dnl/QtZeDQqAVsl5NgDHt/8jCGrmIMH/y3dOB3+D5z4V8BzVgLZSkY6gaE 9OlyGk1AeS36C+sYlgz0Lh200OCV4bLCSJZPhw+imqSGqd+whUP1/ZIUBznqyksoKCZ6uH d+6M5Foq+WkU2fV1zSEkhuIts8lueG4= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1674121933; 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=fJ0BhK340QxC2FfzztYEdrbHd6f21nhkmEp3rkocFpc=; b=dfUP/umFXvs4d/UYtHfjczOsSokDWAnQ1axWgOKEOkpzFUqz+HnBhT+kt9b8MMgNpL46Jf QoLcxXVWRRsBb3ceXsDnP+IypD/OviuGTgdOsWgh+nl20/aLPSWAiwCBs2aNzCjom3kIrq xyt2f9vX3Xb0WJb265nQhwukH/bLTps= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-557-sRMK_3U4P5SpNPJqEfYMug-1; Thu, 19 Jan 2023 04:52:11 -0500 X-MC-Unique: sRMK_3U4P5SpNPJqEfYMug-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.rdu2.redhat.com [10.11.54.3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id CF80180D0F1; Thu, 19 Jan 2023 09:52:10 +0000 (UTC) Received: from localhost (ovpn-13-24.pek2.redhat.com [10.72.13.24]) by smtp.corp.redhat.com (Postfix) with ESMTPS id DEEF51121315; Thu, 19 Jan 2023 09:52:09 +0000 (UTC) Date: Thu, 19 Jan 2023 17:52:03 +0800 From: Baoquan He To: Uladzislau Rezki 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 Subject: Re: [PATCH v3 3/7] mm/vmalloc.c: allow vread() to read out vm_map_ram areas Message-ID: References: <20230113031921.64716-1-bhe@redhat.com> <20230113031921.64716-4-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.3 X-Rspamd-Server: rspam07 X-Rspamd-Queue-Id: 8196640005 X-Rspam-User: X-Stat-Signature: ajgutgi96wxrcrkf48oia5hchbpxdnu1 X-HE-Tag: 1674121934-273286 X-HE-Meta: U2FsdGVkX19O9WHYrZhZsMmF9cG33YJ00cx61jJjB0afNEuLIOBZe2S6f0IsDNY0b1N0jrlM+/jllgqBrkGsNtPYRUHKeJusnspoiwShxXBktRNsNltF1Fa67SRe3osj9SS5NeX3AMSi/PMsDo28l1Z+nK36oZgBsiHMKKZXyPYv7ngq5e3tRY+a4sVvjuhxK6IPGpg6AGw+4YyuvSsudDOgfT1XelzvuwUGcQcf4f5ZgMyxpR9GahopQz7mDBm/13saWLdg8hfsj02nZ4C2JS5Fu5xJCB46OJeS9V3Jmax2tfl4L8sbkqwz6g5oUZCtZpAdHcCvcZX/S2m4J5+I0az0B/dPFDVUXeMkWVzN/o+OLlgd+DmFMotdZl0eghR/w7ViMZppXB8mIfu3z9d4Dlpm0W++aj/4xBvfLI3mQ48qvWkhWPLbqxX0Vj0B26GmO0K7nCpBRTqEL4g0qrg18NRqHwmei1djEwUaMVWmQNjTN7cPL3tUueukps0E5OlZv+DBeXUhGeB19qLr+aeEgivI5VNat8uNHvMxXjONjOkxmiLbns0/79BbAI+UHLqZV0mg0Ch6VO28XT8CMrxtUzeT8ZTyJlvea79QoCy0mFlyzwncDXPwKKXC77yp9AbuK5JAAFyHRchl88kC5PaadOAMfUtpE0LRUQ/ZEo1CIVin8+jHVlzMg5XsB2ALbzX/p7A2tG+lP89lXlgv09KNYJ2P1eJ+7FYPCs8qwZWC4kQ/oKCXjuFNfeqMV4a1PvDY4Al7VH2cEvHOcOXEpNq6zGr0fiMzv4/Ww3hMVIq741jkQJUGFX8YUn+HT+aRpsVpk8Kc0Ax2qoIZH0WyjepJY8jUJTZBK5thqHVLsG+rI1s6YcoipLsr6YsgChB8LtzABG24JiNXOG1eoSSr4zwl+GC74CC1zY9aWI0Q5Z4VD58= 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 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, CPU-x invokes free_vmap_block() and executed xa_erase() to remove the vb from vmap_blocks tree. Then vread() comes into vmap_ram_vread() and call xa_load(), it would be null. I should check the returned vb in free_vmap_block(). static void vmap_ram_vread(char *buf, char *addr, int count, unsigned long flags) { ...... 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)); if (!vb) <-- vb need be checked here to avoid accessing erased vb from vmap_blocks tree memset(buf, 0, count); ...... }