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 8786AC5479D for ; Mon, 9 Jan 2023 07:15:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EE52D8E0002; Mon, 9 Jan 2023 02:15:07 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E95428E0001; Mon, 9 Jan 2023 02:15:07 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D5CCB8E0002; Mon, 9 Jan 2023 02:15:07 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id C59BF8E0001 for ; Mon, 9 Jan 2023 02:15:07 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9426716015A for ; Mon, 9 Jan 2023 07:15:07 +0000 (UTC) X-FDA: 80334399054.09.A16FB2D Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) by imf21.hostedemail.com (Postfix) with ESMTP id D23B41C0007 for ; Mon, 9 Jan 2023 07:15:05 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=DpQGjS7q; spf=pass (imf21.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.51 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1673248505; 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=djYroUcP7LJj8Vfu0pfc16kXU2pouT3NI2vQqAjt8UI=; b=lap9tNwP9PiepYrtLhTq85T07/sxxjkWVp6+yW3qufTQWyNQu+vB+5vdHmNud4dr1RckzF S3xy1Fd/IPS+04BNJ1aGMz7ArY/S0OjVtZCqLdY5NJqOTf245PNkYUPP+8nUHe4WYr0FzB 8LA8M5w1pRMSIFWUrsJq6BRZ4mlj8hI= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=DpQGjS7q; spf=pass (imf21.hostedemail.com: domain of lstoakes@gmail.com designates 209.85.221.51 as permitted sender) smtp.mailfrom=lstoakes@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1673248505; a=rsa-sha256; cv=none; b=x8sSEaojZ2/Y3RGWkSfHvVawt80hisGOejVr5NJ1Pka03Oc5+Uvkc4OeIfjuRsRLfWl4qd oeq6LsivjWAWJP/B5hFknU092NxdQuJjI+xjvxvJZ+SyKC9J4yjHSgX/GtrnxFeq/enoK/ Ksde1m3mWF9CI7dMXYa4sGQFudnv7oY= Received: by mail-wr1-f51.google.com with SMTP id s9so7171585wru.13 for ; Sun, 08 Jan 2023 23:15:05 -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=djYroUcP7LJj8Vfu0pfc16kXU2pouT3NI2vQqAjt8UI=; b=DpQGjS7qf86KkinejfalItV4JhAijE15LdUeORGx3G0QoIyi6QF2V9zEpbYoKBZlER oEDcENQGrZV1AQ/8EyWz3oL9oWfZu/ytzJ9oRb2zNnJI52QTqu7Q1Q22x+wSBfvTdTEl pW906imxH22HP8HVImsKWQhuq9XXl3u3+RHZJl3fzEX13/nr/Scw2OAdyJQg0FLLoLFN mEeTSGer75fQ58gc5EOFkjL/2Q1vd/B2F3fsjtKXSN6UCbZgznSJlbgUe79HwL+GncP0 3IXOYvYaZS2GYPA4ohNQYFTT1iDOUAefOhbFP7eGuQ6qTWC4yqnlVNnSXN9irzS2kol8 YOKA== 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=djYroUcP7LJj8Vfu0pfc16kXU2pouT3NI2vQqAjt8UI=; b=sPHxvvMP7JlDZb1dsbSuEq8OFxJPOTCs7T7U4nCPeMsgs0izoKYI4um28cwqebWXQU jTDocMHnAp/Ub69oH/UyCHRrJfzNgu2hO9RsuSbS/Y5jisjrVgRoqlifYGCTDh5VEo57 j1kI9lKGJ6uDRJt1thjOqv5ukpNdmR8hzQdlTZsqibNhjU1axp1Oux6qSG0Kj4oeZcT+ w2WsfK/6qhMEAJUqqi3kdtT9iSXd8wK3Hd2M9RKRQNYnkWlWj1kJq7BXHcWGNzJSzx6k 2Gy+BK4O68r9P4QA5834L8hYqFroybiVZVkMbKK42N85qp8q39am1yOdYZNzwUV691wx Ihog== X-Gm-Message-State: AFqh2krLp8JS2Gi97YHQfCK3CmEe7pJofhCRlK050q/nOSs9cB5fiWes J5MFWKWokbC4Ncquk2RYirg= X-Google-Smtp-Source: AMrXdXtILkYsNlifUW/4HmfuMMvgCLwzy9sTLAQ7wc1VavGSmqqHInOsBs+CSk6DW2ePzJl/p8ff1w== X-Received: by 2002:a05:6000:1042:b0:2bc:804e:4c78 with SMTP id c2-20020a056000104200b002bc804e4c78mr143774wrx.59.1673248504120; Sun, 08 Jan 2023 23:15:04 -0800 (PST) Received: from localhost (host81-157-153-247.range81-157.btcentralplus.com. [81.157.153.247]) by smtp.gmail.com with ESMTPSA id c10-20020a056000104a00b002238ea5750csm8986002wrx.72.2023.01.08.23.15.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Jan 2023 23:15:03 -0800 (PST) Date: Mon, 9 Jan 2023 07:12:53 +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 3/7] mm/vmalloc.c: allow vread() to read out vm_map_ram areas Message-ID: References: <20221217015435.73889-1-bhe@redhat.com> <20221217015435.73889-4-bhe@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: D23B41C0007 X-Stat-Signature: c6bu1q8w754wqx1zgfhgbpbddn5gi8ic X-HE-Tag: 1673248505-85819 X-HE-Meta: U2FsdGVkX1/m5oOjyWKA8iwrCqD8OtceUKVhT1XEX0vW7hbzGs74H17Q+dmOSZvg8cb8EFedVX0+shG/Hwkx1KzZP0b8/IJTurhKd4YV9rHlFWm1f8a9EZdibMRL6UAud3oo1LkvmNj1mQgkfLBYTODSbI9uTMFfM1LK6KDXrIU2rR4qq10VUT/nPy3j8FsHN5lo/k3/LY1xkQDsxpO2XAnz/hiaw41hZPOactE/7iJQnRjO0vgBpA2zf25vxRCZH9XhXmsw0JSLIyKmAYyqpU8TEcbqimWphDCgi9EgRSThpyfUXLQJVTUY9pWJnYd4HjPyiHdxcluGIeXAc2EXHjOxX2l5hi2sLLNT8gH16hNQC1Ks2uKffx7wGIhq66LUa2HGpB8uA1drASWkOY8Btf1xQ/JZBBSrQ/KvGAMac2XLrLw1UjCZU1FplK8j7R6eYp6aSShy5oG3W4pG4jOydJy6zN+ntdi3vYswCn/LHEYDFo3oEix/YYpAv0lTM19uvdqzNgdwKgxqthG3u8jJ6kiqt4w9Y/jSOnF4bVwMXMyo+of8YQLfbZy+Bt0umgxtsCCHQ1fokmQUF6pEYizyeIvMRjLesys0jhBvrKkx7dGNdhwxkOC2vwhHN9Pzcag1ZSUOCyXDugqHUViyOG1UWY/PPc1x4khmLXN5TdGjLyWB3UYIlMe0PLVsBRZ9HeHNvpp2dCjwNa0iGlsqKTxyt0uxGXAIqCbJh4bQPhyEPkuWDHVTIwgHgFj3TBO+VBSSyaZq/gmZ97/2lwQBm2aLjVe1JLDrjHTJZ51HNYYh/NKzL0EtSaTGqih5hcVu+HtUEpgNQMINfe17fCer0vpzz2HUno7GMHzCcA5LUeUl/2BYDO6P1L+ctLGzHvFrMW0cOE1lpFlG+b6y/ysPm4WFbsfu85bkfUXWPCzNWWZDgn3IL1m4GZIMhAdBgYSAcIoXHjz6xrkihY0NzA6kg1/ PObVuyBp QF5iuBvIpGTCau+vi/gvbQAU9jpH+Z1CfPvKbZ4PlI32FnobrdcYToAIpFMcbjkU4ZmrA1VyBWTeBwl6rQoj0pyDY78mMt+UZOOo+P/AqwPGGEs048YcQZGrab/DycvsYy62L7YMnt38f91A= 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 Mon, Jan 09, 2023 at 12:35:04PM +0800, Baoquan He wrote: > Sorry for late reply, just come back from vacation. Hope you had a great time! :) > > Lei + mutt sounds like a good idea. I relied too much on mbsync in the > past. > Yeah I'm finding it works well, https://josefbacik.github.io/kernel/2021/10/18/lei-and-b4.html is a handy guide! [snip] > > Maybe let me rephrase:- > > > > - We want to read `count` bytes from `addr` into `buf` > > - We iterate over _used_ blocks, placing the start/end of each block in `rs`, `re` > > respectively. > > - If we hit a block whose start address is above the one in which we are interested then:- > > - Place a zero byte in the buffer > > - Increment `addr` by 1 byte > > - Decrement the `count` by 1 byte > > - Carry on > > > > I am seriously confused as to why we do this? Surely we should be checking > > whether the range [addr, addr + count) overlaps this block at all, and only then > > copying the relevant region? > > I guessed this could be your concern, but not very sure. That > code block is copied from vread(), and my considerations are: > 1) We could starting read from any position of kcore file. /proc/kcore > is a elf file logically, it's allowed to read from anywhere, right? We > don't have to read the entire file always. So the vmap_block reading is > not necessarily page aligned. It's very similar with the empty area > filling in vread(). > 2) memset() is doing the byte by byte reading. We can > change code as below. While we don't save the effort very much, and we > need introduce an extra local variable to store the value of > (start - end). > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index b054081aa66b..dce4a843a9e8 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -3576,6 +3576,15 @@ static void vmap_ram_vread(char *buf, char *addr, int count, unsigned long flags > + if (addr < start) { > + int num = min(count, (start - add)); > + memset(buf, 0, count); > + count -= num; > + if (count == 0) > + break; > + buf -= num; > + addr -= num; > + } > /*it could start reading from the middle of used region*/ > offset = offset_in_page(addr); > n = ((re - rs + 1) << PAGE_SHIFT) - offset; > The difference with vread() is that uses a while loop rather than an if clause so operates over the whole region byte-by-byte, your original would only do this for 1 byte so now things make a lot more sense! This approach makes sense though I'd put the count == 0 check first and nit 'add' should be 'addr'. I am happy with either this or a while loop instead of an if which it seems is what the original issue was! > void *memset(void *s, int c, size_t count) > { > char *xs = s; > > while (count--) > *xs++ = c; > return s; > } > > > > > It's the fact that blocks are at base page granularity but then this condition > > is at byte granularity that is confusing to me (again it's _very_ possible I am > > just being dumb here and missing something, just really want to understand this > > better :) > > I like this kind of reviewing with careful checking and deep thinking. > For above code block, I think it's a very great point. From my point of > view, I like the memset version better, it's easier to understand. If we > all agree, we can change it to take memset way. When I made patches, > several issues related to patches were hovering in my mind at the same > time, I did not consider this one so deeply. > Thanks :) I have a particular interest in vmalloc so am happy to dive in with reviews here! > > > > > > > - 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); > > > > > > > > For example here, I feel that this ternary should be reversed and based on > > > > whether vm is null, unles we expect vm to ever be non-null _and_ flags to be > > > > set? > > > > > > Now only vm_map_ram area sets flags, all other types has vm not null. > > > Since those temporary state, e.g vm==NULL, flags==0 case has been > > > filtered out. Is below you suggested? > > > > > > size = (!vm&&flags)? va_size(va) : get_vm_area_size(vm); > > > or > > > size = (vm&&!flags)? get_vm_area_size(vm):va_size(va); > > > > > > > Sorry I didn't phrase this very well, my point is that the key thing you're > > relying on here is whether vm exists in order to use it so I simply meant:- > > > > size = vm ? get_vm_area_size(vm) : va_size(va); > > > > This just makes it really explicit that you need vm to be non-NULL, and you've > > already done the flags check before so this should suffice. > > Sounds reasonable, I will copy above line you pasted. Thanks a lot. > Cheers!