From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 2A0BC221DB3 for ; Mon, 24 Nov 2025 10:17:38 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763979459; cv=none; b=o8h1AHsigKLo5Y/5uN2RbJQGdMNPJ9l9wkynPFZ4z/LtpcFc6yNnpf+WvBD7Zp8Ir0g+01uLVLiXggMmLNVFhPouU/YqLnGC0GvZU8oq/mKP58DNul01BSRPLr7Orud56kGnlH5oIgzPbOjhh4n50Xs9mswdqyp+zb9o3yt2k50= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1763979459; c=relaxed/simple; bh=BHZLLVaKtHbJtuUBDAHntZWxmUQzmBKPu5HpOi8S0kE=; h=Message-ID:Date:MIME-Version:Subject:To:Cc:References:From: In-Reply-To:Content-Type; b=E8UPGM+xsp1CIU32cvQEHqEz5hOuxxITTzRKNOQGztm3jJ2aURQRzTXIrPHmHYsYaOOUkqKc/cOXfTqroiOQa4B8b29m3ay8LQzRPZpCSo/DRdr6dlEadbkcmjWO/MrD3nzqqcBFtJwyWXoNpJAtAZ+qBhGgfl9zn890CGye6eg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=H1uBk/yw; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="H1uBk/yw" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 734C0C4CEF1; Mon, 24 Nov 2025 10:17:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1763979458; bh=BHZLLVaKtHbJtuUBDAHntZWxmUQzmBKPu5HpOi8S0kE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=H1uBk/ywLkiHwnL5I8onigZKl9NS0kqoh0Oys4QUZVaCXMzNStaPvdVvExrgr+qlb RhxfLA+iWa9SiLItjfRTJ8yU/Fq3uihfniSEhC01afA+no34iudhP+rp/TlpehiZSv sXyRfVV+wWcVb+JDXYG2tAC4JUTWDd7HsO2MxsAM4JRcMnxpF9N4elAa78JTaqW9a9 09GfkoMmnQSI6FArP6RHzbrECNagf9lTcPlAVrwTLx6C75F2mYYBpbz2t/+VbNfvcm Ph01Kvo7IcjN+kd/pj1eklV8FDv0tbNuVTXnpSpFsMmdIxPaC+bNU4GCfP/QVtUnN+ fmfREVWcb5Nkg== Message-ID: Date: Mon, 24 Nov 2025 11:17:31 +0100 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 v9 1/7] treewide: provide a generic clear_user_page() variant To: "Christophe Leroy (CS GROUP)" , Ankur Arora , linux-kernel@vger.kernel.org, linux-mm@kvack.org, x86@kernel.org Cc: akpm@linux-foundation.org, bp@alien8.de, dave.hansen@linux.intel.com, hpa@zytor.com, mingo@redhat.com, mjguzik@gmail.com, luto@kernel.org, peterz@infradead.org, tglx@linutronix.de, willy@infradead.org, raghavendra.kt@amd.com, boris.ostrovsky@oracle.com, konrad.wilk@oracle.com References: <20251121202352.494700-1-ankur.a.arora@oracle.com> <20251121202352.494700-2-ankur.a.arora@oracle.com> <189bc218-8f19-4686-b2ee-5ddc6a0b4684@kernel.org> From: "David Hildenbrand (Red Hat)" Content-Language: en-US In-Reply-To: <189bc218-8f19-4686-b2ee-5ddc6a0b4684@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 11/23/25 12:53, Christophe Leroy (CS GROUP) wrote: > > > Le 21/11/2025 à 21:23, Ankur Arora a écrit : >> From: David Hildenbrand >> >> Let's drop all variants that effectively map to clear_page() and >> provide it in a generic variant instead. >> >> We'll use the macro clear_user_page to indicate whether an architecture >> provides it's own variant. >> >> We have to be a bit careful if an architecture provides a custom >> clear_user_highpage(), because then it's very likely that some special >> flushing magic is happening behind the scenes. >> >> Maybe at some point these should be CONFIG_ options. >> >> Note that for parisc, clear_page() and clear_user_page() map to >> clear_page_asm(), so we can just get rid of the custom clear_user_page() >> implementation. There is a clear_user_page_asm() function on parisc, >> that seems to be unused. Not sure what's up with that. >> >> Signed-off-by: David Hildenbrand >> Signed-off-by: Ankur Arora > > ... > >> diff --git a/include/linux/mm.h b/include/linux/mm.h >> index 7c79b3369b82..6fa6c188f99a 100644 >> --- a/include/linux/mm.h >> +++ b/include/linux/mm.h >> @@ -3879,6 +3879,28 @@ static inline void clear_page_guard(struct zone *zone, struct page *page, >> unsigned int order) {} >> #endif /* CONFIG_DEBUG_PAGEALLOC */ >> >> +#ifndef clear_user_page >> +/** >> + * clear_user_page() - clear a page to be mapped to user space >> + * @addr: the address of the page >> + * @vaddr: the address of the user mapping >> + * @page: the page >> + */ >> +static inline void clear_user_page(void *addr, unsigned long vaddr, struct page *page) >> +{ >> +#ifdef clear_user_highpage >> + /* >> + * If an architecture defines its own clear_user_highpage() variant, >> + * then we have to be a bit more careful here and cannot simply >> + * rely on clear_page(). >> + */ >> + clear_user_highpage(page, vaddr); >> +#else >> + clear_page(addr); >> +#endif >> +} >> +#endif >> + >> #ifdef __HAVE_ARCH_GATE_AREA >> extern struct vm_area_struct *get_gate_vma(struct mm_struct *mm); >> extern int in_gate_area_no_mm(unsigned long addr); > > > Isn't it chicken and egg with clear_user_highpage() in linux/highmem.h ? : No really, because we make use of clear_user_highpage() only when the arch defines it, so the highmem.h variant is ignored? Not that I particularly enjoy this way of handling it, so something cleaner would be nice :) (in particular, relying on highmem.h defines in mm.h is a bit suboptimal) > > #ifndef clear_user_highpage > static inline void clear_user_highpage(struct page *page, unsigned long > vaddr) > { > void *addr = kmap_local_page(page); > clear_user_page(addr, vaddr, page); > kunmap_local(addr); > } > #endif > > And at the end this function is the only caller of clear_user_page() so > there is apparently no need for a generic clear_user_page(), at least > not when clear_user_highpage() is defined. > > I think is would be simpler and cleaner to instead add the following in > linux/highmem.c: I assume you mean highmem.h It's not really highmem.h material, but if it makes things cleaner, sure. Might be that the compiler will not be happy about that. @Ankur can you play with that and see if we can make compilers happy one way or the other? -- Cheers David