Received: by 2002:ab2:6857:0:b0:1ef:ffd0:ce49 with SMTP id l23csp609513lqp; Thu, 21 Mar 2024 10:07:14 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVOMPQJQAdU9KDVL4JryMnhocqP0wo3gIFpx5Fxi8gIsKP+hKoflwGqTnoRhjHx2VbjMHuM6TPY/s2cC7BVitnGUT0T73G/QB2QyqxHIQ== X-Google-Smtp-Source: AGHT+IEzUbz+5ixmprfPFjvFXyJmRSZ6P+RPvQVnHwKyQq+0vWgqY7DOZkMjFwCcUHpmOgxxV7tM X-Received: by 2002:a17:90a:8a91:b0:2a0:2a93:d937 with SMTP id x17-20020a17090a8a9100b002a02a93d937mr1213831pjn.24.1711040834595; Thu, 21 Mar 2024 10:07:14 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711040834; cv=pass; d=google.com; s=arc-20160816; b=qldln7xT6Pu6o41+1jneSYPwG1iJ2wGtnfbyIeNORDSZ1ftIfXHHYgDyee6508vk4z plwKNeK/g6g4/jubyWa3m1gjCglcvpWfLoAa2WYmN24k5sTF1mbX0t2RE+qVWfLPmDJv vyP6VuvBjhchVhIUmXa0eYS/E0YMfW98YLSDtJzubtcgF32J2tDy1RO0cmgfEkdRfzWc d/AMXHje3D2SYaLMcmDV8iGhMEwmGj+R4oedXW419BOKEmxtxuvTB3De93iWHW0BgmLZ 5kWrEMCzCOv3jVl1RVSicSeL+xDoYDVs1OycTs6kmjYl+jnN3N9zKWyYlCKb0GKvTlDb godw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-transfer-encoding:content-disposition :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:message-id:subject:cc:to:from:date; bh=BKTbYwQ5gcXN3TRRJ5BC/ttApNw9m6DYa4ZEIkNEXPQ=; fh=EIyMZbIVmYH2nkui55erzvsJCYmZh9QZJ6/jK1OFzcs=; b=UR4wD1IuFcyRmHrERZdqzyQp8yn0mjto0FGtvxTm88OhVveBCbntvnyPJQtQi734BH 8XcBBEJXt0jmpe5dhmdP4Xo8NOAskhy9qtDotxXj8wfPVRqa1ZiwM6ZsTo4GYsoILQwZ q3BvsKJwaG5dvgOMXbbUrj4X+a2n7orbbv7ieNeGcDxU07MFhzO+0BYAT+E0qKNohwkV DRX5SgxQYWZoPi1y9AZ7fWjRhPPby85evk2H6jKLHHzjvMtHpnEsCoNRT3i3/BcbNGGW bl2a60yoTi03tS7cYQJKIOBBwyAZhHgt+PIMs5cGVnQXhU+r/jlclGBQgOANXShIFuGL FI9Q==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-110455-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110455-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id bf12-20020a17090b0b0c00b0029b403cfa8esi196182pjb.145.2024.03.21.10.07.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 10:07:14 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-110455-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-110455-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-110455-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 96334282F76 for ; Thu, 21 Mar 2024 17:07:11 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C2456134CF2; Thu, 21 Mar 2024 16:57:11 +0000 (UTC) Received: from mail-yw1-f182.google.com (mail-yw1-f182.google.com [209.85.128.182]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 936702BB0A for ; Thu, 21 Mar 2024 16:57:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711040231; cv=none; b=PlAsqzBN9KZO+97ox30PwELq2+jgefovMwA2T+92hZoRAhT6cJ38lU85T9oOIadTLqw5Yf8XonOj2fX4a35kFcYJ0cDyzyyOY5qHK8fhj/LJboA8A+kQBDa58x0Gmn0se/d3Tf+xPHMTXcb4e8MuGhIYSDrxuAg8smd/9TRf9Vs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711040231; c=relaxed/simple; bh=Q4Vo7dY5LPdXaK2TNIIIt1Y10h8Od3JzFqfVFaPcOCg=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=PUqNGZxsTZPtmDB7jY5T6fYj82gLktn1Q5ElFjHrlqLgh4NRJGxYQjJx/gZ9IH9H5I1wrMTjQF+6AbpL4spxEt+Kr7Hwm7xsXQ1zuuqW6N0LJK4UU274j7Os1vr0qc0MeDJ0Xo9lhfOg0IX7kOEIXDYMpkbZnhymx/8yAQLtn2Q= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org; spf=pass smtp.mailfrom=gmail.com; arc=none smtp.client-ip=209.85.128.182 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-yw1-f182.google.com with SMTP id 00721157ae682-60a104601dcso12695007b3.2 for ; Thu, 21 Mar 2024 09:57:09 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711040228; x=1711645028; h=in-reply-to:content-transfer-encoding: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=BKTbYwQ5gcXN3TRRJ5BC/ttApNw9m6DYa4ZEIkNEXPQ=; b=pEzTqe9+ULU7uB6qxcXVJk7aPXjfGYm/lQlUF4q+blEJ4yFwQaR7CB9cGm/kFW7lB/ 4xnrSPfzT+uJOp+sRhfZZDytOYf5v4bxyWCXkAkCbV2MSREezjkjpR8iH030fwhemwKe uzl4a/hi6pJ2f2ZX9FnnJ7nHKVuuXPl5FgPm/+wghKnTjmBZo4Gqf0N5brPhH2orbMV3 /bzmNs+pj9gL34yP9XNBLRh+EL0SskJqW3t7oMWvY8noyQHUB0nMFQ1vNg7S64AkmZEA 6zpTA+b6/4WnS+lNB4olxVqSmto2sa+jxuM7z0XTJSctPlfjb/JVo6hCn6VWHgF85nBI ZzQg== X-Forwarded-Encrypted: i=1; AJvYcCXI6qchwjOXi4B19MTjRY1xnAMF4z+pozbX+M/Ze56rPQYj7Zi8zdrvlZLQkM/P6GZehVhVSbzPYwhIF8gSW+aOTKOFVdRTEBg7r8l2 X-Gm-Message-State: AOJu0YzUmexDsCdhbN+mIkAW8WRd4U5f76RdzoraRNxf4b9R8mmTADTF yHUf8DKI/GGp5m7n4AttcsB5YI39qSOjqpRrh24YehfBf5DeoO56 X-Received: by 2002:a0d:cdc5:0:b0:610:f906:d6c2 with SMTP id p188-20020a0dcdc5000000b00610f906d6c2mr4628198ywd.5.1711040228515; Thu, 21 Mar 2024 09:57:08 -0700 (PDT) Received: from V92F7Y9K0C (fixed-187-190-174-151.totalplay.net. [187.190.174.151]) by smtp.gmail.com with ESMTPSA id w125-20020a818683000000b0060cccc8a7b9sm7004ywf.69.2024.03.21.09.57.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Mar 2024 09:57:08 -0700 (PDT) Date: Thu, 21 Mar 2024 09:57:05 -0700 From: Dennis Zhou To: Yosry Ahmed , Andrew Morton Cc: Dennis Zhou , Tejun Heo , Christoph Lameter , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Uladzislau Rezki , Christoph Hellwig , Lorenzo Stoakes Subject: Re: [PATCH] percpu: clean up all mappings when pcpu_map_pages() fails Message-ID: References: <20240311194346.2291333-1-yosryahmed@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: On Tue, Mar 19, 2024 at 01:49:17PM -0700, Yosry Ahmed wrote: > On Tue, Mar 19, 2024 at 1:32 PM Dennis Zhou wrote: > > > > Hi Yosry, > > > > On Tue, Mar 19, 2024 at 01:08:26PM -0700, Yosry Ahmed wrote: > > > On Mon, Mar 11, 2024 at 12:43 PM Yosry Ahmed wrote: > > > > > > > > In pcpu_map_pages(), if __pcpu_map_pages() fails on a CPU, we call > > > > __pcpu_unmap_pages() to clean up mappings on all CPUs where mappings > > > > were created, but not on the CPU where __pcpu_map_pages() fails. > > > > > > > > __pcpu_map_pages() and __pcpu_unmap_pages() are wrappers around > > > > vmap_pages_range_noflush() and vunmap_range_noflush(). All other callers > > > > of vmap_pages_range_noflush() call vunmap_range_noflush() when mapping > > > > fails, except pcpu_map_pages(). The reason could be that partial > > > > mappings may be left behind from a failed mapping attempt. > > > > > > > > Call __pcpu_unmap_pages() for the failed CPU as well in > > > > pcpu_map_pages(). > > > > > > > > This was found by code inspection, no failures or bugs were observed. > > > > > > > > Signed-off-by: Yosry Ahmed > > > > > > Any thoughts about this change? Should I resend next week after the > > > merge window? > > > > > > > Sorry for the delay. > > > > I'm looking at the code from mm/kmsan/hooks.c kmsan_ioremap_page_range(). > > It seems like __vunmap_range_noflush() is called on error for > > successfully mapped pages similar to how it's being done in percpu-vm.c. > > You picked an unconventional example to compare against :) > > > > > I haven't read in depth the expectations of vmap_pages_range_noflush() > > but on first glance it doesn't seem like percpu is operating out of the > > ordinary? > > I was looking at vm_map_ram(), vmap(), and __vmalloc_area_node(). They > all call vmap_pages_range()-> vmap_pages_range_noflush(). > > When vmap_pages_range() fails: > - vm_map_ram() calls > vm_unmap_ram()->free_unmap_vmap_area()->vunmap_range_noflush(). > - vmap() calls vunmap()->remove_vm_area()->free_unmap_vmap_area()-> > vunmap_range_noflush(). > - __vmalloc_area_node() calls > vfree()->remove_vm_area()->free_unmap_vmap_area()-> > vunmap_range_noflush(). > Okay so I had a moment to read it more closely. If we're mapping > 1 pages, and one of the latter pages fails. Then we could leave some mappings installed. @Andrew, I think this makes sense. Would you please be able to pick this up? I'm not running a tree this window. I will try to send out the percpu hotplug changes I've been forward porting for a while now and try to get that in a branch for-6.10. Acked-by: Dennis Zhou > I think it is needed to clean up any leftover partial mappings. I am > not sure about the kmsan example though. > Yeah the kmsan example seems like it could be wrong for the same reason, but I haven't inspected that more closely. Thanks, Dennis > Adding vmalloc reviewers here as well here. > > > > > > > > --- > > > > > > > > Perhaps the reason __pcpu_unmap_pages() is not currently being called > > > > for the failed CPU is that the size and alignment requirements make sure > > > > we never leave any partial mappings behind? I have no idea. Nonetheless, > > > > I think we want this change as that could be fragile, and is > > > > inconsistent with other callers. > > > > > > > > --- > > > > mm/percpu-vm.c | 4 ++-- > > > > 1 file changed, 2 insertions(+), 2 deletions(-) > > > > > > > > diff --git a/mm/percpu-vm.c b/mm/percpu-vm.c > > > > index 2054c9213c433..cd69caf6aa8d8 100644 > > > > --- a/mm/percpu-vm.c > > > > +++ b/mm/percpu-vm.c > > > > @@ -231,10 +231,10 @@ static int pcpu_map_pages(struct pcpu_chunk *chunk, > > > > return 0; > > > > err: > > > > for_each_possible_cpu(tcpu) { > > > > - if (tcpu == cpu) > > > > - break; > > > > __pcpu_unmap_pages(pcpu_chunk_addr(chunk, tcpu, page_start), > > > > page_end - page_start); > > > > + if (tcpu == cpu) > > > > + break; > > > > } > > > > pcpu_post_unmap_tlb_flush(chunk, page_start, page_end); > > > > return err; > > > > -- > > > > 2.44.0.278.ge034bb2e1d-goog > > > >