From patchwork Mon Oct 14 14:44:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christoph Hellwig X-Patchwork-Id: 1997017 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=zmmr+87Y; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=ozlabs.org (client-ip=2404:9400:2221:ea00::3; helo=mail.ozlabs.org; envelope-from=srs0=amf+=rk=vger.kernel.org=sparclinux+bounces-2375-patchwork-incoming=ozlabs.org@ozlabs.org; receiver=patchwork.ozlabs.org) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XS0Rb43Dhz1xtb for ; Tue, 15 Oct 2024 01:46:35 +1100 (AEDT) Received: from mail.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by gandalf.ozlabs.org (Postfix) with ESMTP id 4XS0RZ3ghxz4x11 for ; Tue, 15 Oct 2024 01:46:34 +1100 (AEDT) Received: by gandalf.ozlabs.org (Postfix) id 4XS0RZ3dY7z4wy9; Tue, 15 Oct 2024 01:46:34 +1100 (AEDT) Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: gandalf.ozlabs.org; arc=pass smtp.remote-ip="2604:1380:45d1:ec00::1" arc.chain=subspace.kernel.org ARC-Seal: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1728917194; cv=pass; b=INCUzrfZRt21rcOsSsNwCqttx8U/BEuosidtX5t/g/FsSmOeDExWhh4Ar/4sY0wUcZPCU1SaNwfUf9dKudWlTpKkHBJD2ZryHgdKuJLiZngTjco/1sF8cTjZncfq0jmRJU0ocB4DoXScrsxAosqkdYy7m3snYYXzuC18DxbEFQSjjxReQgvTZ9mmThIXJfWYniD2ycpTZWhcBvFEDoOxe3HZsVNsa/BJ3tr+fn9wxiR1ncT1/a6ROQL1bfwHAAdj/WtAwLrC7jyjhJvWbac/rQdcEKitz4SCGUEQOje/INzASvH38N1m+SjiPXu7TI4smG1lzcd7jqrfLOO0dc4u0w== ARC-Message-Signature: i=2; a=rsa-sha256; d=ozlabs.org; s=201707; t=1728917194; c=relaxed/relaxed; bh=CBx8oOZP7muTRFWdnTWIX1ck/8Je7EEbolhZOJL2Cgo=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QtSDAOt6vMMAqpgT9YjC4BZNXLQqcUryvdwVhkQ6Wk7ACM3KLKyZDwWnE5RyeaPRke1/Uf8aMefpGMdw0fFUmisz+NJH0KthKvglgacTfBg1x2spISXQXxLkwf0j1UEUXzEUyXYAKRHZsy40adS7TRqL49ztlqAFEDoZbFLgUogo8qAvTzmwQ/ip+vx/onhmoG0G8+WyRAtDZQpLSQ+jt+/ovyI6F0zUcxsmzyG80UKXrLiqvYfkm8H5p0uCFRbAWbD0NMNc8YG9+NSI4DtAEzVgvPbWz4n3XFM/DgcYc5UEfywrNCsZ1qepSv8KKsPUOoX2Cq/Alabn4UmPoopNeQ== ARC-Authentication-Results: i=2; gandalf.ozlabs.org; dmarc=none (p=none dis=none) header.from=lst.de; dkim=pass (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=zmmr+87Y; dkim-atps=neutral; spf=pass (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=sparclinux+bounces-2375-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) smtp.mailfrom=vger.kernel.org Authentication-Results: gandalf.ozlabs.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: gandalf.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=zmmr+87Y; dkim-atps=neutral Authentication-Results: gandalf.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=2604:1380:45d1:ec00::1; helo=ny.mirrors.kernel.org; envelope-from=sparclinux+bounces-2375-patchwork-incoming=ozlabs.org@vger.kernel.org; receiver=ozlabs.org) Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org [IPv6:2604:1380:45d1:ec00::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by gandalf.ozlabs.org (Postfix) with ESMTPS id 4XS0RZ0SSQz4x11 for ; Tue, 15 Oct 2024 01:46:34 +1100 (AEDT) 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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 48B801C231AE for ; Mon, 14 Oct 2024 14:46:33 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AA7361B4F2C; Mon, 14 Oct 2024 14:45:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="zmmr+87Y" X-Original-To: sparclinux@vger.kernel.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (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 217951B4F25; Mon, 14 Oct 2024 14:45:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=198.137.202.133 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728917123; cv=none; b=eCjBR532hTs1ll+mMo3soaOspIONuQdyidCnpOyhOM5uNKfelGs/vuj2aiLA9GzD/uxQSQkEAK5xZDd53fEFyei9WOYFG14h8MzVyZejzseiUaYgCDdb2iziYeCLbxNMUezTsdg5AAuv7xH+TO8Q+hyz9fViKwVnTjO029cTYUg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1728917123; c=relaxed/simple; bh=y26+r13pUk6qsz13PsTCyN9nVWaOY2WbcrNpyxtSjdE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=oIgC0T+/7pWsPChGcf/f94hUj3xxFgpN5CNwD5IN0AfhK3JUoqs3ItqxG95wHdKjfWL4yPqwptacKs2YuQ9xo+sy99nc3FoIB4B1Tkm96YXaoEojQSVkIq9517fX6DAacuRTunKcBzH0AJlKEYPdhxO6c6SVTfDxfs720cq2msE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de; spf=none smtp.mailfrom=bombadil.srs.infradead.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b=zmmr+87Y; arc=none smtp.client-ip=198.137.202.133 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=lst.de Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=bombadil.srs.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:Cc:To:From:Sender :Reply-To:Content-Type:Content-ID:Content-Description; bh=CBx8oOZP7muTRFWdnTWIX1ck/8Je7EEbolhZOJL2Cgo=; b=zmmr+87Y9fBB2htyIn2LwLkL5/ hsChFqRyxCtK8dSibrcQ8PEvXM7QOaRtaKrym2h6jMMzO77s3lS2hn7Ds42Hha1klRD3lM+Hh+Ouy 6aq3QvpikKtFJ2F/rq0qXxEEGv112EOwBW14QmpkYktJfsn/t/8gKm0+NOK8hkF/781sbpX7DAr9e Wy9jviDzgvwT73cOdJu8yjmFDmQnePjJFT32ESCWmE2e+osAYE3e1CM3IpLuxXfIkRN1+7xy2ntbq J2YK67lQQmwotM1BaSYABBbzL+B1EFNJ+UJM7BuNOq5VinAEx1k3YZ+nFmu6LbSobVuhQIjj3RpVT JuhE5rtw==; Received: from 2a02-8389-2341-5b80-350d-7b06-b28a-173d.cable.dynamic.v6.surfer.at ([2a02:8389:2341:5b80:350d:7b06:b28a:173d] helo=localhost) by bombadil.infradead.org with esmtpsa (Exim 4.98 #2 (Red Hat Linux)) id 1t0MJz-00000005Wzd-3wyi; Mon, 14 Oct 2024 14:45:20 +0000 From: Christoph Hellwig To: 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 Subject: [PATCH 2/2] asm-generic: add an optional pfn_valid check to pfn_valid Date: Mon, 14 Oct 2024 16:44:59 +0200 Message-ID: <20241014144506.51754-3-hch@lst.de> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20241014144506.51754-1-hch@lst.de> References: <20241014144506.51754-1-hch@lst.de> Precedence: bulk X-Mailing-List: sparclinux@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SRS-Rewrite: SMTP reverse-path rewritten from by bombadil.infradead.org. See http://www.infradead.org/rpr.html 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 regult to it's 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 Reviewed-by: Thomas Huth --- 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 a73a140cbecdd7..6d1fb6162ac1a6 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)); \ + 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__ */