From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pegase2.c-s.fr (pegase2.c-s.fr [93.17.235.10]) (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 527B23C6BA for ; Tue, 5 Nov 2024 09:56:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=93.17.235.10 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730800608; cv=none; b=lIVVINvcuBJFGoychovxq1nNL3lWfeVqFgbl+3WaZWJOCidOSP0BxcFyggI11CCGYsuqAZpua1AGwiSESVTwGRJq6PcKTfsVrMl4u0gFl3I5Hh5D6geidKcTAqIYy4xd8vHl3xI0I0nENUm92sP5tpTjMuogFuA0+qSdZSLSVWQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730800608; c=relaxed/simple; bh=R7fYE1ho6RL0rqvfjF3EYrY/xOTC+OyPnNaWsD9XQcY=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=reWaub2pGGU2FhSvFIlpaxeQVVjKBsjJd9i3nKXrHZU7hsiaztZgpQ0Ni0ytn/pcmwurdh10L++OMlf2ROK0QWSqHkJkqy4v+hzbhOCBMM1xQsp2kirbxJgwg+9ilEUdGoZXMQ4fZ5utSim2luZXyGph4YDyhS/ouYQTTb6dEAA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu; spf=pass smtp.mailfrom=csgroup.eu; arc=none smtp.client-ip=93.17.235.10 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=csgroup.eu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=csgroup.eu Received: from localhost (mailhub3.si.c-s.fr [172.26.127.67]) by localhost (Postfix) with ESMTP id 4XjNyz319Qz9sPd; Tue, 5 Nov 2024 10:56:43 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from pegase2.c-s.fr ([172.26.127.65]) by localhost (pegase2.c-s.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id CpEO93zW8bQ7; Tue, 5 Nov 2024 10:56:43 +0100 (CET) Received: from messagerie.si.c-s.fr (messagerie.si.c-s.fr [192.168.25.192]) by pegase2.c-s.fr (Postfix) with ESMTP id 4XjNyz27jdz9rvV; Tue, 5 Nov 2024 10:56:43 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 346688B770; Tue, 5 Nov 2024 10:56:43 +0100 (CET) X-Virus-Scanned: amavisd-new at c-s.fr Received: from messagerie.si.c-s.fr ([127.0.0.1]) by localhost (messagerie.si.c-s.fr [127.0.0.1]) (amavisd-new, port 10023) with ESMTP id BXNslob-hZDZ; Tue, 5 Nov 2024 10:56:43 +0100 (CET) Received: from [192.168.232.44] (unknown [192.168.232.44]) by messagerie.si.c-s.fr (Postfix) with ESMTP id 9E0918B763; Tue, 5 Nov 2024 10:56:42 +0100 (CET) Message-ID: <9ee9c21b-179f-49aa-8c65-304c8ef2c9a7@csgroup.eu> Date: Tue, 5 Nov 2024 10:56:42 +0100 Precedence: bulk X-Mailing-List: linux-m68k@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH 2/2] asm-generic: add an optional pfn_valid check to page_to_phys To: Christoph Hellwig , Arnd Bergmann Cc: linux-alpha@vger.kernel.org, linux-kernel@vger.kernel.org, linux-snps-arc@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-csky@vger.kernel.org, linux-hexagon@vger.kernel.org, loongarch@lists.linux.dev, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-openrisc@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-um@lists.infradead.org, linux-arch@vger.kernel.org References: <20241023053644.311692-1-hch@lst.de> <20241023053644.311692-3-hch@lst.de> Content-Language: fr-FR From: Christophe Leroy In-Reply-To: <20241023053644.311692-3-hch@lst.de> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Le 23/10/2024 à 07:36, Christoph Hellwig a écrit : > page_to_pfn is usually implemented by pointer arithmetics on the memory > map, which means that bogus input can lead to even more bogus output. > > Powerpc had a pfn_valid check on the intermediate pfn in the page_to_phys > implementation when CONFIG_DEBUG_VIRTUAL is defined, which seems > generally useful, so add that to the generic version. > > Signed-off-by: Christoph Hellwig > --- > include/asm-generic/memory_model.h | 10 ++++++++++ > 1 file changed, 10 insertions(+) > > diff --git a/include/asm-generic/memory_model.h b/include/asm-generic/memory_model.h > index a73a140cbecd..6d1fb6162ac1 100644 > --- a/include/asm-generic/memory_model.h > +++ b/include/asm-generic/memory_model.h > @@ -64,7 +64,17 @@ static inline int pfn_valid(unsigned long pfn) > #define page_to_pfn __page_to_pfn > #define pfn_to_page __pfn_to_page > > +#ifdef CONFIG_DEBUG_VIRTUAL > +#define page_to_phys(page) \ > +({ \ > + unsigned long __pfn = page_to_pfn(page); \ > + \ > + WARN_ON_ONCE(!pfn_valid(__pfn)); \ On powerpc I think it was a WARN_ON(). Will a WARN_ON_ONCE() be enough ? > + PFN_PHYS(__pfn); \ > +}) > +#else > #define page_to_phys(page) PFN_PHYS(page_to_pfn(page)) > +#endif /* CONFIG_DEBUG_VIRTUAL */ > #define phys_to_page(phys) pfn_to_page(PHYS_PFN(phys)) > > #endif /* __ASSEMBLY__ */