From patchwork Sun Dec 4 01:30:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 13063706 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 F211BC352A1 for ; Sun, 4 Dec 2022 01:31:22 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 87B318E0006; Sat, 3 Dec 2022 20:31:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 82C198E0001; Sat, 3 Dec 2022 20:31:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 6CCAE8E0006; Sat, 3 Dec 2022 20:31:22 -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 5E4188E0001 for ; Sat, 3 Dec 2022 20:31:22 -0500 (EST) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 0D5E1A01C1 for ; Sun, 4 Dec 2022 01:31:22 +0000 (UTC) X-FDA: 80202896004.12.4D31599 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf01.hostedemail.com (Postfix) with ESMTP id 080684000E for ; Sun, 4 Dec 2022 01:31:19 +0000 (UTC) Authentication-Results: imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=L+HLHYdO; spf=pass (imf01.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.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=1670117480; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=B30MFqWNu+rcOTLOH6gG9qPqyD6wQQ4N98WacTEX/8c=; b=6TA/G7TzdyZXRsHo1TiEiY5l8IXVM/979gKQcFJSl1ewWtKmazat+I8vXbE8B49AMTXWh+ 3sHYKPQcsYUPMQvAabbe14xsLgO3/xkJ1NDKOGOtTIkk4clQcNt6taHQmWngkyhNSYu5vm NIdFr1F7gddLtVDbGjrSC1VSB6uJbp4= ARC-Authentication-Results: i=1; imf01.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=L+HLHYdO; spf=pass (imf01.hostedemail.com: domain of bhe@redhat.com designates 170.10.133.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=1670117480; a=rsa-sha256; cv=none; b=PbuKcxiPkPtHd1/7z9QxTR1FS0xmeEIX/jjnKnrzLrTOkVS92mzG0nbzxu97GEu3SLZh30 sOdVH4hUXFAriVD1EzKDAFRbuCLMvQNfq4WV3syWxfeqKZfXk46rrU7e0r5xAWRdL1dNJt gUTDmUpPmGAW8Zaj/loLNEzc/+FunLU= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1670117479; 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=B30MFqWNu+rcOTLOH6gG9qPqyD6wQQ4N98WacTEX/8c=; b=L+HLHYdOQuD8ZpH2EpOOeFGnyE0siqcgpEd2UIbH/zOnFeO8d2uwR9hAGND47f7elm5ue1 czrse5bouljW6oR0ZR03sz2sgUPDLakQuwhgU11vCpyk7XqM1MhdfpL4vbo5J0SZRsx9mz LJFlc24wORnL5allA86gWkpGID6i8fY= 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-208-Jh9T0IHRNhediakKabRqEg-1; Sat, 03 Dec 2022 20:31:15 -0500 X-MC-Unique: Jh9T0IHRNhediakKabRqEg-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 5B1C5101A52A; Sun, 4 Dec 2022 01:31:15 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-31.pek2.redhat.com [10.72.12.31]) by smtp.corp.redhat.com (Postfix) with ESMTP id 250D5141511E; Sun, 4 Dec 2022 01:31:10 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, stephen.s.brennan@oracle.com, urezki@gmail.com, willy@infradead.org, akpm@linux-foundation.org, hch@infradead.org, Baoquan He Subject: [PATCH v1 3/7] mm/vmalloc.c: allow vread() to read out vm_map_ram areas Date: Sun, 4 Dec 2022 09:30:42 +0800 Message-Id: <20221204013046.154960-4-bhe@redhat.com> In-Reply-To: <20221204013046.154960-1-bhe@redhat.com> References: <20221204013046.154960-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.7 X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 080684000E X-Stat-Signature: jqn6ppiexc1wtk6dwxxzqsyyk61bjymx X-Spamd-Result: default: False [-1.44 / 9.00]; BAYES_HAM(-5.04)[97.83%]; R_MISSING_CHARSET(2.50)[]; MID_CONTAINS_FROM(1.00)[]; SUBJECT_HAS_UNDERSCORES(1.00)[]; DMARC_POLICY_ALLOW(-0.50)[redhat.com,none]; R_DKIM_ALLOW(-0.20)[redhat.com:s=mimecast20190719]; R_SPF_ALLOW(-0.20)[+ip4:170.10.133.0/24]; MIME_GOOD(-0.10)[text/plain]; RCVD_NO_TLS_LAST(0.10)[]; RCPT_COUNT_SEVEN(0.00)[8]; FROM_EQ_ENVFROM(0.00)[]; DKIM_TRACE(0.00)[redhat.com:+]; RCVD_COUNT_THREE(0.00)[4]; MIME_TRACE(0.00)[0:+]; FROM_HAS_DN(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; TO_DN_SOME(0.00)[]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; ARC_NA(0.00)[] X-Rspam-User: X-HE-Tag: 1670117479-47445 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: 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 will be skipped. Here, add a new function vb_vread() to read out areas managed by vmap_block specifically. Then recognize vm_map_ram areas via vmap->flags and handle them respectively. Signed-off-by: Baoquan He --- mm/vmalloc.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 54 insertions(+), 7 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index d6f376060d83..e6b46da3e044 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3519,6 +3519,46 @@ static int aligned_vread(char *buf, char *addr, unsigned long count) return copied; } +static void vb_vread(char *buf, char *addr, int count) +{ + char *start; + struct vmap_block *vb; + unsigned long offset; + unsigned int rs, re, n; + + offset = ((unsigned long)addr & (VMAP_BLOCK_SIZE - 1)) >> PAGE_SHIFT; + 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)) { + spin_unlock(&vb->lock); + memset(buf, 0, count); + return; + } + for_each_set_bitrange(rs, re, vb->used_map, VMAP_BBMAP_BITS) { + if (!count) + break; + start = vmap_block_vaddr(vb->va->va_start, rs); + if (addr < start) { + if (count == 0) + break; + *buf = '\0'; + buf++; + addr++; + count--; + } + n = (re - rs + 1) << PAGE_SHIFT; + if (n > count) + n = count; + aligned_vread(buf, start, n); + + buf += n; + addr += n; + count -= n; + } + spin_unlock(&vb->lock); +} + /** * vread() - read vmalloc area in a safe way. * @buf: buffer for reading data @@ -3549,7 +3589,7 @@ long vread(char *buf, char *addr, unsigned long count) struct vm_struct *vm; char *vaddr, *buf_start = buf; unsigned long buflen = count; - unsigned long n; + unsigned long n, size, flags; addr = kasan_reset_tag(addr); @@ -3570,12 +3610,16 @@ long vread(char *buf, char *addr, unsigned long count) if (!count) break; - if (!va->vm) + vm = va->vm; + flags = va->flags & VMAP_FLAGS_MASK; + + if (!vm && !flags) continue; - vm = va->vm; - vaddr = (char *) vm->addr; - if (addr >= vaddr + get_vm_area_size(vm)) + vaddr = (char *) va->va_start; + size = flags ? va_size(va) : get_vm_area_size(vm); + + if (addr >= vaddr + size) continue; while (addr < vaddr) { if (count == 0) @@ -3585,10 +3629,13 @@ long vread(char *buf, char *addr, unsigned long count) addr++; count--; } - n = vaddr + get_vm_area_size(vm) - addr; + n = vaddr + size - addr; if (n > count) n = count; - if (!(vm->flags & VM_IOREMAP)) + + if ((flags & (VMAP_RAM|VMAP_BLOCK)) == (VMAP_RAM|VMAP_BLOCK)) + vb_vread(buf, addr, n); + else if ((flags & VMAP_RAM) || !(vm->flags & VM_IOREMAP)) aligned_vread(buf, addr, n); else /* IOREMAP area is treated as memory hole */ memset(buf, 0, n);