From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 507E025179A for ; Fri, 8 Aug 2025 08:02:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754640139; cv=none; b=FQr6eY6V0qrmCRfRsa6cZHKF7EekYy9GSDx7OWL3uYYqK4R0ZfYsowrpUfYCY6N7aaDm22/LOXCwC2/PP8OJJgvXY41n2WJRRJOZJvo7pM0YEpdRljb412SrYWH4CziGI6uGJ98plnk91mQo0RRNDPPTnwjSwXI3eXGpIHKTG9I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1754640139; c=relaxed/simple; bh=jMSpEBEGrlHFEXytlN1Vqldbpo66hRZEypVpxIN5KOQ=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=I0ece6Tl0YTTdXG3hObUwaMymwvzm8eUJYv9kXcmAIlcSrXkrFAk1tmHnJtBiRJZgn7rsR7pyHNqWWG1xIuMXRHcmSqNIhkZMA///+d27WZ7OGqGBUcgAjONVl6Uh9yr0TleBSb14GD7mDd43LieICTyXL0ZmCgP3DuraaYYeD4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=DhU3L+cs; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="DhU3L+cs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1754640135; 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:autocrypt:autocrypt; bh=BAno96tpxFYMgcAPgmjun2K1NToihw19tP0g9bAlXR0=; b=DhU3L+cs20EatGgmoHS98zCNpLhmWN3jyCppMbwlGztL0XKXCu8d1u6LYQx17TUJvTGHqi Wjg5IAMLNrvMP5hZvHphyVXlNm0uXSA9K4/Fb1oGpvtdys2v/1E5sbgnmX+CZxrs5Vynrv ieDGc9Tc6M6Qsjz9S1+S0J0bMhuO1Vg= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-160-Cy7Wxl7FMOGEwd30LmNYXg-1; Fri, 08 Aug 2025 04:02:13 -0400 X-MC-Unique: Cy7Wxl7FMOGEwd30LmNYXg-1 X-Mimecast-MFC-AGG-ID: Cy7Wxl7FMOGEwd30LmNYXg_1754640132 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-459d7ed90baso13047575e9.2 for ; Fri, 08 Aug 2025 01:02:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1754640132; x=1755244932; h=content-transfer-encoding:in-reply-to:organization:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=BAno96tpxFYMgcAPgmjun2K1NToihw19tP0g9bAlXR0=; b=JuYDy/U2XV8JfNXbcrfuIgapPW3658k+g2hlaMwaVK76abshRYHHFfi1UrGpfp+kNB +Li2bZPloA75HrARW+5wrvTEA7/E8EgnSfTzyO6IqEFWWjfSg85xm9gqHg8MODrc4scl jHY1FXMLpTNpJSnH00CcDPssmmNQ/on082/T/7zGxk2g1NlrVGR2DwaMvB6A8vz+8018 EbpvYaptEMHot5jvyjipCYYFvmEJdyWJNBtqvSNfr9+hfIU8t2XBzIo1Ek6P+wSQngPT EqdvM118OrTCqNXWXucerlI9NBchDGdr9OuXh16+jQvabhl5Rg+wW+1d0CBfIJbI2Q/W 2Nqw== X-Forwarded-Encrypted: i=1; AJvYcCUnRqKmOXPYrKz8yJorkuof/oPEASdJj4n8rcZrqHNdYoUufCGMjf9RV/lR7FYwyFOnWA8pBe78qdU/bho=@vger.kernel.org X-Gm-Message-State: AOJu0YxudlpNWhTHk351D+EIAPu3Ek9c5QN8z/gU2utYd5qvdb3UG+h4 my3vFhaEnl0Uu8pw/IXIPcsD3iG9vWvrMafAbbM+HZBZYx+tzECI1cItzQXqs6J2ptqquTDZm7W xwpSMh7GJCjC/YAaC6XUsd/6uVfb+GnjFCTD3CJXyu8fVQp0IPx3Mz4Qw8bX95KIIRw== X-Gm-Gg: ASbGncsnd6OwgJmjrmUvjy/EuJi0A8RO01wIrKlOzeW0UAmxRL9sY04rC2SQfpcoHnx 5OxXk2chtNUkoQRz30nD+g45RFU1zqX9oAiQkrEeOJ9RylCNBecxkU4MXq+N9YdIp6OC5tyvVHI E+kAEAE0RbUsxRejilxgPf/uD+8exijbkY2S+ao8XxTcdqb9Z4Wt3apflfBBJFWrJ0Ye6bkf9Ou YW4KCkqEKmvhXHUtPkSJR7nkHuZJ6KZ9znVYVjPj0R7cerCnpnpafWKWe2ZjeaRe1LDOnMkJGjx RmOKtlv6eoXamz1q5J5gAE1UHyywUYwEEFofMrgamyZGsW2h33GB6fzsHvjM81ypoHrs1dk= X-Received: by 2002:a05:600c:3b0c:b0:456:43d:1198 with SMTP id 5b1f17b1804b1-459f4f2d990mr13934505e9.32.1754640131831; Fri, 08 Aug 2025 01:02:11 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEgZzUg3wr1SifXE4t4yhDMq7cAU5j7L/vtRZVGMfKFh0NEsEhGPcGUTafUnKO5iZcAXqC1uw== X-Received: by 2002:a05:600c:3b0c:b0:456:43d:1198 with SMTP id 5b1f17b1804b1-459f4f2d990mr13934055e9.32.1754640131356; Fri, 08 Aug 2025 01:02:11 -0700 (PDT) Received: from [192.168.3.141] (p57a1a580.dip0.t-ipconnect.de. [87.161.165.128]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-459e5862be7sm133209415e9.15.2025.08.08.01.02.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 08 Aug 2025 01:02:10 -0700 (PDT) Message-ID: <5b9c775c-35a1-4cd6-8387-00198e768b9a@redhat.com> Date: Fri, 8 Aug 2025 10:02:08 +0200 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH] mm/userfaultfd: fix missing PTE unmap for non-migration entries To: Sasha Levin Cc: Andrew Morton , peterx@redhat.com, aarcange@redhat.com, surenb@google.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org, stable@vger.kernel.org References: <20250630031958.1225651-1-sashal@kernel.org> <20250630175746.e52af129fd2d88deecc25169@linux-foundation.org> <214e78a0-7774-4b1e-8d85-9a66d2384744@redhat.com> <593b222e-1a62-475c-9502-76e128d3625d@redhat.com> From: David Hildenbrand Content-Language: en-US Autocrypt: addr=david@redhat.com; keydata= xsFNBFXLn5EBEAC+zYvAFJxCBY9Tr1xZgcESmxVNI/0ffzE/ZQOiHJl6mGkmA1R7/uUpiCjJ dBrn+lhhOYjjNefFQou6478faXE6o2AhmebqT4KiQoUQFV4R7y1KMEKoSyy8hQaK1umALTdL QZLQMzNE74ap+GDK0wnacPQFpcG1AE9RMq3aeErY5tujekBS32jfC/7AnH7I0v1v1TbbK3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WlDnD/4k2TW+HyOOOePVm23F5HOhNNd7nNv3 Vq2cLcW1DteHUdxMO0X+zqrKDHI5hgnE/E2QH9jyV8mB8l/ndElobciaJcbl1cM43vVzPIWn 01vW62oxUNtEvzLLxGLPTrnMxWdZgxr7ACCWKUnMGE2E8eca0cT2pnIJoQRz242xqe/nYxBB /BAK+dsxHIfcQzl88G83oaO7vb7s/cWMYRKOg+WIgp0MJ8DO2IU5JmUtyJB+V3YzzM4cMic3 bNn8nHjTWw/9+QQ5vg3TXHZ5XMu9mtfw2La3bHJ6AybL0DvEkdGxk6YHqJVEukciLMWDWqQQ RtbBhqcprgUxipNvdn9KwNpGciM+hNtM9kf9gt0fjv79l/FiSw6KbCPX9b636GzgNy0Ev2UV m00EtcpRXXMlEpbP4V947ufWVK2Mz7RFUfU4+ETDd1scMQDHzrXItryHLZWhopPI4Z+ps0rB CQHfSpl+wG4XbJJu1D8/Ww3FsO42TMFrNr2/cmqwuUZ0a0uxrpkNYrsGjkEu7a+9MheyTzcm vyU2knz5/stkTN2LKz5REqOe24oRnypjpAfaoxRYXs+F8wml519InWlwCra49IUSxD1hXPxO WBe5lqcozu9LpNDH/brVSzHCSb7vjNGvvSVESDuoiHK8gNlf0v+epy5WYd7CGAgODPvDShGN g3eXuA== Organization: Red Hat In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 07.08.25 21:51, Sasha Levin wrote: > On Fri, Aug 01, 2025 at 10:29:17AM -0400, Sasha Levin wrote: >> On Fri, Aug 01, 2025 at 04:06:14PM +0200, David Hildenbrand wrote: >>> Sure, if it's prechecked by you no problem. >> >> Yup. Though I definitely learned a thing or two about Coccinelle patches >> during this experiment. > > Appologies if it isn't the case, but the two patches were attached to > the previous mail and I suspect they might have been missed :) Whoop's not used to reviewing attachments. I'll focus on the loongarch patch. From a547687db03ecfe13ddc74e452357df78f880255 Mon Sep 17 00:00:00 2001 From: Sasha Levin Date: Fri, 1 Aug 2025 09:17:04 -0400 Subject: [PATCH 2/2] LoongArch: fix kmap_local_page() LIFO ordering in copy_user_highpage() The current implementation violates kmap_local_page()'s LIFO ordering requirement by unmapping the pages in the same order they were mapped. This was introduced by commit 477a0ebec101 ("LoongArch: Replace kmap_atomic() with kmap_local_page() in copy_user_highpage()") when converting from kmap_atomic() to kmap_local_page(). The original code correctly unmapped in reverse order, but the conversion swapped the mapping order while keeping the unmapping order unchanged, resulting in a LIFO violation. kmap_local_page() requires unmapping to be done in reverse order (Last-In-First-Out). Currently we map vfrom and then vto, but unmap vfrom and then vto, which is incorrect. This patch corrects it to unmap vto first, then vfrom. This issue was detected by the kmap_local_lifo.cocci semantic patch. Fixes: 477a0ebec101 ("LoongArch: Replace kmap_atomic() with kmap_local_page() in copy_user_highpage()") Co-developed-by: Claude claude-opus-4-20250514 Signed-off-by: Sasha Levin --- arch/loongarch/mm/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/loongarch/mm/init.c b/arch/loongarch/mm/init.c index c3e4586a7975..01c43f455486 100644 --- a/arch/loongarch/mm/init.c +++ b/arch/loongarch/mm/init.c @@ -47,8 +47,8 @@ void copy_user_highpage(struct page *to, struct page *from, vfrom = kmap_local_page(from); vto = kmap_local_page(to); copy_page(vto, vfrom); - kunmap_local(vfrom); kunmap_local(vto); + kunmap_local(vfrom); /* Make sure this page is cleared on other CPU's too before using it */ smp_wmb(); } -- 2.39.5 So, loongarch neither supports a) Highmem nor b) ARCH_SUPPORTS_KMAP_LOCAL_FORCE_MAP, disabling DEBUG_KMAP_LOCAL_FORCE_MAP Consequently __kmap_local_page_prot() will not do anything: if (!IS_ENABLED(CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP) && !PageHighMem(page)) return page_address(page); So there isn't anything to fix here and the whole patch subject+description should be rewritten to focus on this being purely a cleanup -- unless I am missing something important. Also, please reduce the description to the absolute minimum, nobody wants to read the same thing 4 times using slightly different words. "LIFO ordering", "LIFO ordering", "unmapped in reverse order ... LIFO violation" ... "reverse order (Last-In-First-Out)" More importantly: is the LIFO semantics clearly documented somewhere? I read Documentation/mm/highmem.rst Nesting kmap_local_page() and kmap_atomic() mappings is allowed to a certain extent (up to KMAP_TYPE_NR) but their invocations have to be strictly ordered because the map implementation is stack based. See kmap_local_page() kdocs (included in the "Functions" section) for details on how to manage nested mappings. and that kind-of spells that out (strictly order -> stack based). I think one could have clarified that a bit further. Also, I would expect this to be mentioned in the docs of the relevant kmap functions, and the pte map / unmap functions. Did I miss that part or could we extend the function docs to spell that out? -- Cheers, David / dhildenb