From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pf1-f171.google.com (mail-pf1-f171.google.com [209.85.210.171]) (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 5CAB9176ADE for ; Thu, 11 Dec 2025 00:33:47 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.210.171 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765413228; cv=none; b=mwLMIyCRgygGodI/K7ZAOn9p5tLjQq85SXTfmvkFoOFBYdF6CSNT2W5oKGgU9Vd4auADu/Nq9HUmfY1TohD1WgLuU5UBcnwv8PT34ne0+/UEyKf0OHWYeoT6WigVL45M5+JCQC1tlhHxVV3uiFtFvclC6S7+06AU7WGk/TN3++Y= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1765413228; c=relaxed/simple; bh=2JDmWBATpaUa6H2BcCIWxO0SvGynnnvWoeBMOOx9Drk=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=MNrdF2G/oyvnJsybaq3He+B/8OweZZMtP7KZYrEdM6SDPJ51AeZ6otrSm8Vj6SZ8gyacp9UgWpInrAV2Se83DlUlNBv6+C9DGyEbXHfFTX2sHqUEKqgq7cEoz52QULQpIOH8K+/FUYhs69GtPVD5ernpqIb87JshX9Zmxd3MYPY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com; spf=pass smtp.mailfrom=sifive.com; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b=T8FMIFHq; arc=none smtp.client-ip=209.85.210.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=sifive.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=sifive.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=sifive.com header.i=@sifive.com header.b="T8FMIFHq" Received: by mail-pf1-f171.google.com with SMTP id d2e1a72fcca58-7ba55660769so294854b3a.1 for ; Wed, 10 Dec 2025 16:33:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1765413227; x=1766018027; darn=vger.kernel.org; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=3QrmlcsyPJfUCC0ZcW/aA6sfMqx5l+Z163FBQ6ysu4g=; b=T8FMIFHqn/hM8JeS6uY3CfllpKUzV8BLY81iwqyoLQfzJG0jOkjPFvNABY4YTiS5B2 1m0uBmVoY9aImrqNl3xNsKyI5ooKpPc9HXmYy1oRUxFv57S6pLJr1PUDbN8GbMA6mLi/ FOekgp9AaRK5zUht6iCnFL42l1DQ7jA9N/r9ZYdEmNSmtY+HRHodivM2vqDBypY7PDte cAhMhqtNSdYE/yjCg5hzgRDhQbVHtslJyBRpnbNZEp3i0V+cxIFPCEC7Ob9okdMauaWW T2kkRdZwRFGRvJKUFMEux3rRvD/eSsunAT4S8NTwrS+ThZDhDUGpUZOL3vfcl3AjlBGl 1qXQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1765413227; x=1766018027; h=content-transfer-encoding:in-reply-to:content-language:from :references:cc:to:subject:user-agent:mime-version:date:message-id :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=3QrmlcsyPJfUCC0ZcW/aA6sfMqx5l+Z163FBQ6ysu4g=; b=WH3p6grHJwXjT68+7nq5xgk55jaxszJMScmZ59vDmaHmTgPJ5yyxBo3VGbOI39RJ3h aCDhrvsBgPOYl5olEgWv3B+OtBEFd/uQ9JcIy1oQXR1eyjRMTUxt1YUjOUzIIuUBzi15 mmRBoabmvseZYsQFakDZCuKvvmwM8OionBZBw5fdLItrIA09tmYhdBmgXU/MMSb5i9JI bSaPuoJ23X5ebMexYiy2jfaaScy/DAdFjlT0gdfctNcqvITuAC/4aMk+XNFlEXP3QqKP IvPcjygP5DhvoMOOx7hcyGDTpS2uq3/qCb+45PyiYcUAyVXpuXyGKNteOBRfq/CECoxL RpBg== X-Forwarded-Encrypted: i=1; AJvYcCV5A8FedCzoWtqXg5lSHryld4lzewcleoEdJbs/grHrD+Jn2w7uZWxp4PvFj1zTlehPqWM2Om5YsdZyqKQ=@vger.kernel.org X-Gm-Message-State: AOJu0YwWCClmZWHS2NcHEkxqqwBSYSrPUTsBl3HhGVSb+fk4QJh2uPAp C/6PqGzElmvPMKe//u/17hlX/EVVVEyI0h6IT/+pNVC7gaVr1j/NcK+/O5nuadmMOb83T/7nzYF RIYK5 X-Gm-Gg: ASbGncttrZNc1ItqnQK2jbZbrRvQIIZB3pDRJN9D66FErG+DbeeO0J1GqQmZiEWeB75 ZV00Su09UZmYfH/zPZUbBdXG5N0ZTuKTK9mwMeLpnrFPmpIAC2LLGm3Ok758oiPqf8rtHvyOej3 Ym9pgbmSUGnJ8z/7+FHLjYZfllRRSxJM2K+xcfhlJ1RjXDacTuGUhRiTHL6E432cDVRTAG8x/25 9UCOcVTnK1Ta3Ggc5wI6XvIdcVG2GqwobDTfONKeHR6iFdTGtlbJ6pyNxekLwpSShsN7nPjUKPg RNKUCVvb24YTPL7kXI6Th/uZH8hWQx2qckaACi6OiedlEHxW7JLTikdoAAcbayKo4srrQHgPcUR WVM9mtAGrMfqLc7eOtw7Kf7GDss9sA/K2qybWaLpe+VmmGyrxBdOkLusA3akz6gGKBP+QWl7lSp SZxcoKSGCxL1/lpg== X-Google-Smtp-Source: AGHT+IGjk/exFuz2Gv/i6l6p36w76njH4yBjUre8KbL1otNzyBmhPQsg1E1fJ2rghGyT0+Ekep5ekQ== X-Received: by 2002:a05:6a20:a10a:b0:366:14b0:4b0e with SMTP id adf61e73a8af0-366e3acee69mr4438378637.74.1765413226713; Wed, 10 Dec 2025 16:33:46 -0800 (PST) Received: from [100.64.0.1] ([167.103.29.104]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-c0c25b7d59dsm580312a12.6.2025.12.10.16.33.42 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 10 Dec 2025 16:33:46 -0800 (PST) Message-ID: Date: Thu, 11 Dec 2025 09:33:41 +0900 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 v3 08/22] mm: Allow page table accessors to be non-idempotent To: "David Hildenbrand (Red Hat)" , Ryan Roberts , Palmer Dabbelt , Paul Walmsley , linux-riscv@lists.infradead.org, Andrew Morton , linux-mm@kvack.org Cc: devicetree@vger.kernel.org, Suren Baghdasaryan , linux-kernel@vger.kernel.org, Mike Rapoport , Michal Hocko , Conor Dooley , Lorenzo Stoakes , Krzysztof Kozlowski , Alexandre Ghiti , Emil Renner Berthing , Rob Herring , Vlastimil Babka , "Liam R . Howlett" References: <20251113014656.2605447-1-samuel.holland@sifive.com> <20251113014656.2605447-9-samuel.holland@sifive.com> From: Samuel Holland Content-Language: en-US In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On 2025-11-28 2:47 AM, David Hildenbrand (Red Hat) wrote: > On 11/27/25 17:57, Ryan Roberts wrote: >> On 13/11/2025 01:45, Samuel Holland wrote: >>> Currently, some functions such as pte_offset_map() are passed both >>> pointers to hardware page tables, and pointers to previously-read PMD >>> entries on the stack. To ensure correctness in the first case, these >>> functions must use the page table accessor function (pmdp_get()) to >>> dereference the supplied pointer. However, this means pmdp_get() is >>> called twice in the second case. This double call must be avoided if >>> pmdp_get() applies some non-idempotent transformation to the value. >>> >>> Avoid the double transformation by calling set_pmd() on the stack >>> variables where necessary to keep set_pmd()/pmdp_get() calls balanced. >> >> I don't think this is a good solution. > > Agreed, > >     set_pmd(&pmd, pmd); > > is rather horrible. I agree that this patch is ugly. The only way I see to avoid code like this is to refactor (or duplicate) the functions so no function takes pointers to both hardware page tables and on-stack page table entries. Is that sort of refactoring the right direction to go for v4? Regards, Samuel