From patchwork Wed Nov 9 03:35:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baoquan He X-Patchwork-Id: 17330 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp122568wru; Tue, 8 Nov 2022 19:47:15 -0800 (PST) X-Google-Smtp-Source: AMsMyM4Sw6D7/uQ5GEvNXLjBApvAd9HtlgrhExFFSmPJLa3FZ9iagqNQ2qskq7/WGUwqAvg0aIiz X-Received: by 2002:aa7:ce8d:0:b0:461:50fd:e358 with SMTP id y13-20020aa7ce8d000000b0046150fde358mr57911237edv.194.1667965635248; Tue, 08 Nov 2022 19:47:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667965635; cv=none; d=google.com; s=arc-20160816; b=LfBubJYXLwJus6EI8lmn7dgI/vMXxHg4ceFC9NCuwrkxI5BtYxc4JyCpUQT1n4yYra PzBy5iNIhBaOBwC7RJBYjW/wHX0nreT6EX+cylWiXmNbZixwG9Fd6BGB4wAjuZYvk3pc wpG7++nYYYJQBD2fcZmU4ht3KiHA/nveSrwU8vjp0GYaIZDeLSCjsmfwDgq7/alh8els 1EMVejlNnFZ2mp2bRr0JrCCKeYN1I5lroo8ydnhl9sWj/XiwQpe18v6heYxkR4Zzlxao K7JmR86En2CVE+/5dqGLmpMjIp76CykXV65ECYLr91lKHxwwK3rwdXFvfRsvMluiHc0a uwkg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=LcTeN8CUp/OMny7mFhvKg/4OAsWnVU2lfPdAgkI4ha0=; b=bi2NJXxtoYSHJP455+JB42KMVKYtOcVeKuij9Du4m7pCAx/mxaDdVQXS3MLjt3dM4m dv440qbd2kju6mN3fwh32Mkwp0p7gyWC/QsD4tlwbZDLIW1XHNoKHEvB0dWzNsxWV/Zv fq8nhPh45LSG/PhnEWIWMcid/3qfjdLz6RY323Lt/kro+cYByfS7siS6D5aoaxzJhkc6 61yf/R7zhn58v6MXK0Sa0dI3i/ZiuOelqELjn2ctnZRvF6k6Yn3RyunzBnoYInGKflIo stkqCPae1V3MaBDYW468/iZvTMgoj4E/mdrOdE+8o4VQzw01gm/vgdUu10xsAI1n5Wx0 5tAA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=IaGPsGQr; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oy10-20020a170907104a00b00781df71dbc1si11812951ejb.174.2022.11.08.19.46.51; Tue, 08 Nov 2022 19:47:15 -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=IaGPsGQr; 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 S230248AbiKIDhJ (ORCPT + 99 others); Tue, 8 Nov 2022 22:37:09 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55664 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229899AbiKIDhD (ORCPT ); Tue, 8 Nov 2022 22:37:03 -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 AC9ED10FDF for ; Tue, 8 Nov 2022 19:36:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1667964960; 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=LcTeN8CUp/OMny7mFhvKg/4OAsWnVU2lfPdAgkI4ha0=; b=IaGPsGQr+Douursi/qFC9SJu2W0V4oMbgivFLrytn8GmC4y4FWPyRSgGfIapAT+94xllT5 H6J2Wduyb9q816aTABYEIQS2cjvTD/OFz5aeNiJU/X33qHiU+LtywBUIFGS8wMflESSb0d zlctVFne25JQrI22K1vekpv51c+2ubU= 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-517-p_3NSPWfPiGGUfTsv4bsoQ-1; Tue, 08 Nov 2022 22:35:55 -0500 X-MC-Unique: p_3NSPWfPiGGUfTsv4bsoQ-1 Received: from smtp.corp.redhat.com (int-mx05.intmail.prod.int.rdu2.redhat.com [10.11.54.5]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 616DD811E67; Wed, 9 Nov 2022 03:35:55 +0000 (UTC) Received: from MiWiFi-R3L-srv.redhat.com (ovpn-12-86.pek2.redhat.com [10.72.12.86]) by smtp.corp.redhat.com (Postfix) with ESMTP id A9D6C7AE5; Wed, 9 Nov 2022 03:35:51 +0000 (UTC) From: Baoquan He To: linux-kernel@vger.kernel.org Cc: linux-mm@kvack.org, akpm@linux-foundation.org, stephen.s.brennan@oracle.com, urezki@gmail.com, hch@infradead.org, Baoquan He Subject: [PATCH RFC 3/3] mm/vmalloc.c: allow vread() to read out vm_map_ram areas Date: Wed, 9 Nov 2022 11:35:34 +0800 Message-Id: <20221109033535.269229-4-bhe@redhat.com> In-Reply-To: <20221109033535.269229-1-bhe@redhat.com> References: <20221109033535.269229-1-bhe@redhat.com> MIME-Version: 1.0 Content-type: text/plain X-Scanned-By: MIMEDefang 3.1 on 10.11.54.5 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748988624280395192?= X-GMAIL-MSGID: =?utf-8?q?1748988734215358687?= 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 allocate a 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. Stephen Brennan Signed-off-by: Baoquan He Link: https://lore.kernel.org/all/87ilk6gos2.fsf@oracle.com/T/#u --- mm/vmalloc.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 6 deletions(-) diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 41d82dc07e13..5a8d5659bfb0 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3518,6 +3518,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 @@ -3548,7 +3588,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; addr = kasan_reset_tag(addr); @@ -3569,12 +3609,14 @@ long vread(char *buf, char *addr, unsigned long count) if (!count) break; - if (!va->vm) + if (!(va->flags & VMAP_RAM) && !va->vm) continue; vm = va->vm; - vaddr = (char *) vm->addr; - if (addr >= vaddr + get_vm_area_size(vm)) + vaddr = (char *) va->va_start; + size = vm ? get_vm_area_size(vm) : va_size(va); + + if (addr >= vaddr + size) continue; while (addr < vaddr) { if (count == 0) @@ -3584,10 +3626,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 ((va->flags & (VMAP_RAM|VMAP_BLOCK)) == (VMAP_RAM|VMAP_BLOCK)) + vb_vread(buf, addr, n); + else if ((va->flags & VMAP_RAM) || !(vm->flags & VM_IOREMAP)) aligned_vread(buf, addr, n); else /* IOREMAP area is treated as memory hole */ memset(buf, 0, n);