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 X-Spam-Level: X-Spam-Status: No, score=-9.2 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8427AC433EF for ; Wed, 22 Sep 2021 10:41:47 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 2C4796113E for ; Wed, 22 Sep 2021 10:41:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 2C4796113E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=kvack.org Received: by kanga.kvack.org (Postfix) id BDCB66B006C; Wed, 22 Sep 2021 06:41:46 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id B8BFA6B0072; Wed, 22 Sep 2021 06:41:46 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A2E44900002; Wed, 22 Sep 2021 06:41:46 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0156.hostedemail.com [216.40.44.156]) by kanga.kvack.org (Postfix) with ESMTP id 957E26B006C for ; Wed, 22 Sep 2021 06:41:46 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 3F47F22BF9 for ; Wed, 22 Sep 2021 10:41:46 +0000 (UTC) X-FDA: 78614868612.18.2247EBD Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) by imf30.hostedemail.com (Postfix) with ESMTP id 03124E001989 for ; Wed, 22 Sep 2021 10:41:45 +0000 (UTC) Received: by mail-lf1-f53.google.com with SMTP id u8so9898745lff.9 for ; Wed, 22 Sep 2021 03:41:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:date:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to:user-agent; bh=LrlsF27efhqSDhHZ0+WQsLB4CuB2tcAlNXfIpnl+oEE=; b=GMmTYRJcTJdQGPcaTgetE5LYtgfc/H+tD56rqgSQRsp9mf2hSQIyrCiH1aBSLDK0aE Yx+/xUVG3vMw3760RnA8Odn+c7vQJap5oULMunjXjD5Yd7ufQiK1L8MTJBpjUoT34djt ME3xtKij0kXNBqtebcXo7kmvDmZSmbZdUQa2VpIYmXTaT3hYUrLdQKqNXD/M6hVNIo6e kg7fj5L9rKJ5lTYwZKCYBfyObVs6T7BLFfd88a4RQLYnaMosEF26hfTv/1MBcvRz9J+d Xfn4BMG0eDOUemLQN2BjS4ydNVtaaPtbnSbvq7LxdR0rkL34CZxMLzVl3KlWzIVG4qRP hp2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:date:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to:user-agent; bh=LrlsF27efhqSDhHZ0+WQsLB4CuB2tcAlNXfIpnl+oEE=; b=IUef8HGehJ0TQEg6X9R1EgSWuYrRXbIYw4TnmhH4e8/v0dj6FrvUH+bnJE+rozwUZG N8i93fXmL7PU5gC8q4m7X3jDWzz5rIWp4Rlq3GDIs/bjD/LFkMjydr1it3UTDoplZjwF uKvECcD9XmZ/UpIL/YH9/oXVy3lZxzk03GeTv+SbDIrHVdQWsrn+VMgMiNjJU7aJ1yH7 0C19to3qiLqJUPoDhgPs5naJS+cg36i4tmDHWvszBlWXhDLZrmcHhEy6pgYBQ3/5Bovr KP9Wzj7S7b+KuvAtZOrSx5FrzuXFlJ1JkBh87daJeuYk33lX4Euq1OgDK1ROOoiJmk2F Lpkw== X-Gm-Message-State: AOAM532U7s0bab5rGQo0K6uO5oowHx4VpU58pRe2mv69OEoRkuEPQhrF hBDEWoPivacA/6a78QEnOyY= X-Google-Smtp-Source: ABdhPJyJUpacwUYeRFhhpEJarhl42wzLcUFfWzfijADMAFHIALZ68YbT3IetphSwLtq/8+J36y+tPw== X-Received: by 2002:a2e:a814:: with SMTP id l20mr21622219ljq.380.1632307304012; Wed, 22 Sep 2021 03:41:44 -0700 (PDT) Received: from pc638.lan (h5ef52e3d.seluork.dyn.perspektivbredband.net. [94.245.46.61]) by smtp.gmail.com with ESMTPSA id u3sm53372lfm.4.2021.09.22.03.41.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Sep 2021 03:41:43 -0700 (PDT) From: Uladzislau Rezki X-Google-Original-From: Uladzislau Rezki Date: Wed, 22 Sep 2021 12:41:41 +0200 To: David Hildenbrand Cc: Uladzislau Rezki , LKML , Ping Fang , Andrew Morton , Roman Gushchin , Michal Hocko , Oscar Salvador , Linux Memory Management List Subject: Re: [PATCH v1] mm/vmalloc: fix exact allocations with an alignment > 1 Message-ID: <20210922104141.GA27011@pc638.lan> References: <20210908132727.16165-1-david@redhat.com> <20210916193403.GA1940@pc638.lan> <221e38c1-4b8a-8608-455a-6bde544adaf0@redhat.com> <20210921221337.GA60191@pc638.lan> <7f62d710-ca85-7d33-332a-25ff88b5452f@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <7f62d710-ca85-7d33-332a-25ff88b5452f@redhat.com> User-Agent: Mutt/1.10.1 (2018-07-13) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=GMmTYRJc; spf=pass (imf30.hostedemail.com: domain of urezki@gmail.com designates 209.85.167.53 as permitted sender) smtp.mailfrom=urezki@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 03124E001989 X-Stat-Signature: 6zpsdpkezweushq3uyjayxpqopggodzt X-HE-Tag: 1632307305-96034 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 Wed, Sep 22, 2021 at 10:34:55AM +0200, David Hildenbrand wrote: > > > No, that's leaking implementation details to the caller. And no, increasing > > > the range and eventually allocating something bigger (e.g., placing a huge > > > page where it might not have been possible) is not acceptable for KASAN. > > > > > > If you're terribly unhappy with this patch, > > Sorry to say but it simple does not make sense. > > > > Let's agree to disagree. > > find_vmap_lowest_match() is imprecise now and that's an issue for exact > allocations. We can either make it fully precise again (eventually degrading > allocation performance) or just special-case exact allocations to fix the > regression. > > I decided to go the easy path and do the latter; I do agree that making > find_vmap_lowest_match() fully precise again might be preferred -- we could > have other allocations failing right now although there are still suitable > holes. > > I briefly thought about performing the search in find_vmap_lowest_match() > twice. First, start the search without an extended range, and fallback to > the extended range if that search fails. Unfortunately, I think that still > won't make the function completely precise due to the way we might miss > searching some suitable subtrees. > > > > > > > please suggest something reasonable to fix exact allocations: > > > a) Fixes the KASAN use case. > > > b) Allows for automatic placement of huge pages for exact allocations. > > > c) Doesn't leak implementation details into the caller. > > > > > I am looking at it. > I am testing this: diff --git a/mm/vmalloc.c b/mm/vmalloc.c index dcf23d16a308..cdf3bda6313d 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -1161,18 +1161,14 @@ find_vmap_lowest_match(unsigned long size, { struct vmap_area *va; struct rb_node *node; - unsigned long length; /* Start from the root. */ node = free_vmap_area_root.rb_node; - /* Adjust the search size for alignment overhead. */ - length = size + align - 1; - while (node) { va = rb_entry(node, struct vmap_area, rb_node); - if (get_subtree_max_size(node->rb_left) >= length && + if (get_subtree_max_size(node->rb_left) >= size && vstart < va->va_start) { node = node->rb_left; } else { @@ -1182,9 +1178,9 @@ find_vmap_lowest_match(unsigned long size, /* * Does not make sense to go deeper towards the right * sub-tree if it does not have a free block that is - * equal or bigger to the requested search length. + * equal or bigger to the requested search size. */ - if (get_subtree_max_size(node->rb_right) >= length) { + if (get_subtree_max_size(node->rb_right) >= size) { node = node->rb_right; continue; } @@ -1192,16 +1188,30 @@ find_vmap_lowest_match(unsigned long size, /* * OK. We roll back and find the first right sub-tree, * that will satisfy the search criteria. It can happen - * only once due to "vstart" restriction. + * due to "vstart" restriction or an alignment overhead. */ while ((node = rb_parent(node))) { va = rb_entry(node, struct vmap_area, rb_node); if (is_within_this_va(va, size, align, vstart)) return va; - if (get_subtree_max_size(node->rb_right) >= length && + if (get_subtree_max_size(node->rb_right) >= size && vstart <= va->va_start) { + /* + * Shift the vstart forward, so we do not loop over same + * sub-tree force and back. The aim is to continue tree + * scanning toward higher addresses cutting off previous + * ones. + * + * Please note we update vstart with parent's start address + * adding "1" because we do not want to enter same sub-tree + * one more time after it has already been inspected and no + * suitable free block found there. + */ + vstart = va->va_start + 1; node = node->rb_right; + + /* Scan a sub-tree rooted at "node". */ break; } } so it handles any alignment and is accurate when it comes to searching the most lowest free block when user wants to allocate with a special alignment value. Could you please help and test the KASAN use case? Thanks! -- Vlad Rezki