Received: by 2002:a05:6358:a55:b0:ec:fcf4:3ecf with SMTP id 21csp3677618rwb; Mon, 16 Jan 2023 11:14:41 -0800 (PST) X-Google-Smtp-Source: AMrXdXuZjwj5vko9G5bC2B4w4ZbBstNwyQhUUInwr/0xJb+jPDCS/V0dfA7d665ViyC3IYotqs8H X-Received: by 2002:a05:6402:3786:b0:492:609a:f148 with SMTP id et6-20020a056402378600b00492609af148mr491917edb.3.1673896481398; Mon, 16 Jan 2023 11:14:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1673896481; cv=none; d=google.com; s=arc-20160816; b=ImTsfL6DV8v8P46qR8b4ewhCefh4mQqYLGLSVrzI9aMJoBnP3groBMfQnWdS91J+w9 rKxnLzVwI/Wpy88//OOv2najClDFzGMheIboGsdTcgiOTx1Hs5tiPj1cFzRVdb6DI0iT azchJk5l1M9klZnv5Fkz9g87f8rKtONWO4kmVZ/VJHX52qZ7ZToyydOWfrD7qSkmlvZu ikWhMOVYFrX+eYr41wVrbcucKKxTShfrfi5E7ZLp/jUmtB5zxL5Q/ECpgPHCt83zEByl /8wsjZ+rJRP1KAoIH+fA+fukFY77rak5DDmrQl6oyjYPuWwCb/8BvbPYAS431HXNMsy7 xAOg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=OTvEP0dk4mOnC2iv0N91tfWHpSStEQbuT03o4jsB+3k=; b=JM9Y6lRknaXoI06Cmd37T7fu7764ofukiH7JO8q1IrvgvyZneQvtoS9NanMbpbvCDl ezLfC9LY4Y3hfvpesR2kZpZZILb5NGqhgw+9+gR6O8F4SVGlg0cNjas1kMFa59aPV6gy 4+Bu8Ts6D5V6dg0aA9AbQSmb4BbiUrnbRWyEpnpXkb/QL4vltob8ym1oON4lsqPIVKbr tZcb9+hKyQFvftVKMqv7OZbqsMy2VgHaIdCfW77riyTO/Q9ygfD25UoRdTZaoB6AzoN3 b1VYZxgK4jV73lXp3cGbVSt5NbcN08GslsSdQbrg8HLSblficG9CWFhi1GRXgsg/4RfB 2GOw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=SJcYe70e; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s13-20020a508dcd000000b0047a5b2e747csi28253224edh.273.2023.01.16.11.14.28; Mon, 16 Jan 2023 11:14:41 -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=@infradead.org header.s=casper.20170209 header.b=SJcYe70e; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233820AbjAPTBm (ORCPT + 50 others); Mon, 16 Jan 2023 14:01:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60498 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230465AbjAPTB1 (ORCPT ); Mon, 16 Jan 2023 14:01:27 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8B233A9A for ; Mon, 16 Jan 2023 11:01:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=OTvEP0dk4mOnC2iv0N91tfWHpSStEQbuT03o4jsB+3k=; b=SJcYe70efrX8NSS8Oee1AV7oXk 9+KXywD1yVF9dgdzQNDkDQZsc2W3A3X7sBqpZ5JPqn63Ow7j8GgTrImpeRecy4QUIFl6ljfcUQqEa t87JAqa/QYU7shrT2vJTbdrGkqcaBcQBYp9KvWq3t74wTeYM7Xwr6zIqcWyMMKvjCu9W3BqE6/3rA YMnpnqqcYNrOafNGhECpltEHsNkGlaPwFsC3KqYJg/50+O/WC/MQZN3GKSApQ/Dg/WZ4JPe/vJCGM dSmUKDFurx2BcqKKe3Ri7baVFaWaUo6sjj7wlvWvISzoX+SDGE28lj9TDcd5qWnPh2Bf7A7M7jbmU hl85AbnQ==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1pHUjd-008zPN-Oh; Mon, 16 Jan 2023 19:01:33 +0000 Date: Mon, 16 Jan 2023 19:01:33 +0000 From: Matthew Wilcox To: Baoquan He Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, urezki@gmail.com, lstoakes@gmail.com, stephen.s.brennan@oracle.com, 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: <20230113031921.64716-4-bhe@redhat.com> X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,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 On Fri, Jan 13, 2023 at 11:19:17AM +0800, Baoquan He wrote: > + 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); > + while (addr < start) { > + if (count == 0) > + break; > + *buf = '\0'; > + buf++; > + addr++; > + count--; > + } > + /*it could start reading from the middle of used region*/ > + offset = offset_in_page(addr); > + n = ((re - rs + 1) << PAGE_SHIFT) - offset; > + if (n > count) > + n = count; > + aligned_vread(buf, start+offset, n); The whole vread() interface is rather suboptimal. The only user is proc, which is trying to copy to userspace. But the vread() interface copies to a kernel address, so kcore has to copy to a bounce buffer. That makes this spinlock work, but the price is that we can't copy to a user address in the future. Ideally, read_kcore() would be kcore_read_iter() and we'd pass an iov_iter into vread(). vread() would then need to use a mutex rather than a spinlock. I don't think this needs to be done now, but if someone's looking for a project ...