From patchwork Mon Jan 13 22:30:33 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yang Shi X-Patchwork-Id: 13938181 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4E034C02180 for ; Mon, 13 Jan 2025 22:31:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A03316B0083; Mon, 13 Jan 2025 17:31:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9B16E6B0085; Mon, 13 Jan 2025 17:31:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 82B406B0089; Mon, 13 Jan 2025 17:31:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 626E46B0083 for ; Mon, 13 Jan 2025 17:31:09 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id D7DC8A01F7 for ; Mon, 13 Jan 2025 22:31:08 +0000 (UTC) X-FDA: 83003875416.29.185BD6C Received: from CO1PR03CU002.outbound.protection.outlook.com (mail-westus2azon11020139.outbound.protection.outlook.com [52.101.46.139]) by imf09.hostedemail.com (Postfix) with ESMTP id 10710140014 for ; Mon, 13 Jan 2025 22:31:05 +0000 (UTC) Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=os.amperecomputing.com header.s=selector2 header.b="ewf/L6vc"; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf09.hostedemail.com: domain of yang@os.amperecomputing.com designates 52.101.46.139 as permitted sender) smtp.mailfrom=yang@os.amperecomputing.com; dmarc=pass (policy=quarantine) header.from=amperecomputing.com ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736807466; h=from:from:sender: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: references:dkim-signature; bh=DPiYl3XKN12zvZKhkqgCdZHnAQfAGYUWqOCmechygNQ=; b=Tf3i12M7h1yWHjZY0+WE7EiafkJ+4YV5hqVHifX/fJ8zTiwMTJvkYHgZPjnJh47fJNUccU FbFXVGks5k25bVjpgnAa3KOFQ6mIzURWL8Hncp9snL2LivGHo+Sjhu3aGMZah3prj/tvqI JACxHj8PR1orDDQxETDHTZUQqkHRz/Q= ARC-Seal: i=2; s=arc-20220608; d=hostedemail.com; t=1736807466; a=rsa-sha256; cv=pass; b=g+qBlFxg6UxBdZkWL5Af5JCYQDVxrFN78RlP8yjRIb/0KQ67poecnC1POLHjSHtt+2rqpz avquuEbLBLMQSvPDNMvuMiOQKlx9WgXpyh9ziWEf8VabkPTLHTlhuK5mn7/NA7kHoxltpu Y2gv8IEFM3aUtVPqHcBEXV5bBNq+OQg= ARC-Authentication-Results: i=2; imf09.hostedemail.com; dkim=pass header.d=os.amperecomputing.com header.s=selector2 header.b="ewf/L6vc"; arc=pass ("microsoft.com:s=arcselector10001:i=1"); spf=pass (imf09.hostedemail.com: domain of yang@os.amperecomputing.com designates 52.101.46.139 as permitted sender) smtp.mailfrom=yang@os.amperecomputing.com; dmarc=pass (policy=quarantine) header.from=amperecomputing.com ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=XSSd+FzhHrP8kOHNSPOUTmRIr9uILS31L3HgjmQycCs0KcSZ+GZ7OJmPvpWpf2LcILD6QFqQcf1wTqkGn1NFN1EphbEVVobUUIoDc3JPqDQc5p53q4rMZ2oT7krg0Du66HI7KH9nws4dqFkx98GCSbgHUaV3A/PL92VDsNPzVK55itXLiHJOe6nxks0ifPac0haXkIDV7J16nViEs3CkYBDGg6OTu63Bi4rTWBrl8dsJpiI9ad3qbaF0DlOc7qPsHl8LoHWc1MWrSq+UMrU3Uz9DkJNKLf9vBceuWzqOr4RNuC2kTpfxZxWT1hrutH5KCwwdfjZf5lahUTNoj1Jn3w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=DPiYl3XKN12zvZKhkqgCdZHnAQfAGYUWqOCmechygNQ=; b=sXnVStQwAyddwJbm/i4Knyk6wakDf0Nt7fu716JA0VKGwihtodSlRdm9YNW299L2dnEk+9eG8Gksk6mxpBYgKGFC3zfP1e0nTSXgdd75k//XyVRc8342nfXmAXzJFATI2GV0CVsTJ+h6XDiZdudwRCTlP8Ti58Jcj4QmnIeHHj/d/ZcNPDJrkv6HKYLhwRmfT3oIlhMBMsW3shczod+PjHxixJ2HG+pXEQA5I/A8eSqDpL//gsVaP9I5YP6jD+AAulPJjZdxPj3Wjrgl1lgDkeKlAT9zgablLkiLPZ7Epe9HiOyRE3xciYKGCKGmVs9uszFd4MonM5mAM235BLd5DA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=os.amperecomputing.com; dmarc=pass action=none header.from=os.amperecomputing.com; dkim=pass header.d=os.amperecomputing.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=os.amperecomputing.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=DPiYl3XKN12zvZKhkqgCdZHnAQfAGYUWqOCmechygNQ=; b=ewf/L6vcgFo/Wl5HmS43vJIe4mc9o34MWqV1TniVgmRw4AJPDFbhmFJu/N93O706F1va0mS4obowQUp7tky0WAoK0Pd1q6CNR+RyXeNSuQ2nXd3UNT4Sc1HNbheSFfAU9IH9qgRNb2ghT28JVNUERhXIfNAPTXD1k4sGDGjgXAk= Received: from CH0PR01MB6873.prod.exchangelabs.com (2603:10b6:610:112::22) by MW4PR01MB6419.prod.exchangelabs.com (2603:10b6:303:74::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8356.11; Mon, 13 Jan 2025 22:31:02 +0000 Received: from CH0PR01MB6873.prod.exchangelabs.com ([fe80::3850:9112:f3bf:6460]) by CH0PR01MB6873.prod.exchangelabs.com ([fe80::3850:9112:f3bf:6460%6]) with mapi id 15.20.8356.010; Mon, 13 Jan 2025 22:31:01 +0000 From: Yang Shi To: arnd@arndb.de, gregkh@linuxfoundation.org, Liam.Howlett@oracle.com, lorenzo.stoakes@oracle.com, vbabka@suse.cz, jannh@google.com, willy@infradead.org, liushixin2@huawei.com, akpm@linux-foundation.org Cc: yang@os.amperecomputing.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH] /dev/zero: make private mapping full anonymous mapping Date: Mon, 13 Jan 2025 14:30:33 -0800 Message-ID: <20250113223033.4054534-1-yang@os.amperecomputing.com> X-Mailer: git-send-email 2.47.0 X-ClientProxiedBy: SA9PR13CA0062.namprd13.prod.outlook.com (2603:10b6:806:23::7) To CH0PR01MB6873.prod.exchangelabs.com (2603:10b6:610:112::22) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: CH0PR01MB6873:EE_|MW4PR01MB6419:EE_ X-MS-Office365-Filtering-Correlation-Id: ff7bce2e-91ce-4480-cb6b-08dd3421f5a5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024|7416014|52116014|38350700014; X-Microsoft-Antispam-Message-Info: P0bkihRhNm7chvs3paVytaaYpQdL0ueS2Ljp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1P6CvvQ3uPKkCBV73unLTgR4c5uY1w4OBseKx2rahSK3nOgMmx62qmohzAF9ark8EI+vQqp71MHzrmAfe+fvjYNfnGHZNkEcsy9ei5uQfWhTn5aGD95Vs1irBaSKaz8K3CmLDuTgSIIntytKKEDggDDxNjTOrQezm1MrJraGcCc6OgyvDAYa1mRBvZ0AZrUvP+7dh1lbT2ZWNMC3fn9xdj9ItBPVJPj/fdFBKnz2gEGlt7xIv3rySMlgFWer8HLQChbJ/ouiVhitInWX6XZLuzZzoZ6OC//lgduvsm3NvuH27HMpCc4yeUsv5ARo5ud1QrGWHQJiciJvcHX7pm88yLDTPbn213b4psnto4w+s X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:CH0PR01MB6873.prod.exchangelabs.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(1800799024)(7416014)(52116014)(38350700014);DIR:OUT;SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: U9HJvBb+HvO24JuHQjJk+BXPeSdXXXLOKGN6jCcOmQlqg2KMzitp+nXrWbwpgpi+pXOHSAjbY6I8shojon4CUIgiq6ZAGbKWsO23HlgQ0KyXkPqaiQzhFNtoJlLMVQv14E2k1DJnpExp0Fz1ut3NTW/FVNR83geCazf3nF7ClylUMenqL3nAZNvGEjRZXXAmJLIDJ22zJFr39FxQEjPi8R5gBpp5pd9wjNsk+4nCHdnXFt3W269N8tvgx86gQOb/sXNDpV5nDWXOIsvesFgF6W6WGfzjGezkraTvyw164gdMwjVeOQvsNVdf1afqOBK5OqqfiqxHDjmMrUaDdl653GrVANjYe5hanz9b1h0UfJdd60sY9+e94NRgvHVMPE3Z9KArSnaii3pQF2u0f7qMo8E6YKeCrq7VWfwb4M0L7HijnNMeJ0ojrrRQvv0b+OSXosUJ2FaEEPHoEo2e7YbmVNFTAOjYZEBVQlsXulKZMw//tllbVC/Ja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wdWgFOIfsNXInK8jF58zse/IiElp1S2bXLO3WGcU= X-OriginatorOrg: os.amperecomputing.com X-MS-Exchange-CrossTenant-Network-Message-Id: ff7bce2e-91ce-4480-cb6b-08dd3421f5a5 X-MS-Exchange-CrossTenant-AuthSource: CH0PR01MB6873.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jan 2025 22:31:01.8541 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 3bc2b170-fd94-476d-b0ce-4229bdc904a7 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: ThS398FsjObjYtb0PM5R9hf5OpYWxqBuPrqBJNokBH9NA5dUw3GrvUcN5miEBxJvzZO4wQOGtqjSK2pVdQU8XTdkTU7uaC32A6RXVYVKn2I= X-MS-Exchange-Transport-CrossTenantHeadersStamped: MW4PR01MB6419 X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 10710140014 X-Stat-Signature: 6ga9thei3qjpuqj4r6eigkeraqfpdg69 X-Rspam-User: X-HE-Tag: 1736807465-708372 X-HE-Meta: U2FsdGVkX18I+M06vhiasaXmTRTjXccSA56qieuZikMlqRPXmrBfD5CYEK0hUn14eqqwdZfimAYGW/vA4sGX0GAsD2ZWOlwrzQy1DeFmCzKc92tIeMv9QVnMQq17WjywPJAw9MwWaFIsd7/LhFMueJYIjFy/bLehP9hDcE52Og5cY9NEKHE9/yJFuGLSSFaFSdAT0pMWtQz6cszG5jk9Pr6nZTQrHyGdSKU05fT15Eu0Y6oo4J7tQ1ONaK0N377CLBv+Pe/J2RY+LlxZGN6vuuNhgUlNn9U4rdj+tzb+JVHT5NThy04OigRgqp4OuKKBYTyEet8AoRTDvjqd6hwc7GrJuAdHKckYF9c58JunYLoehJ66gNxwzqX4ObbBVCbHnw4pR7hZetKRtkpgNQsSI2Uijw3SFYaMsixmvUKupJ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T3xX7RfENOy X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: When creating private mapping for /dev/zero, the driver makes it an anonymous mapping by calling set_vma_anonymous(). But it just sets vm_ops to NULL, vm_file is still valid and vm_pgoff is also file offset. This is a special case and the VMA doesn't look like either anonymous VMA or file VMA. It confused other kernel subsystem, for example, khugepaged [1]. It seems pointless to keep such special case. Making private /dev/zero mapping a full anonymous mapping doesn't change the semantic of /dev/zero either. The user visible effect is the mapping entry shown in /proc//smaps and /proc//maps. Before the change: ffffb7190000-ffffb7590000 rw-p 00001000 00:06 8 /dev/zero After the change: ffffb6130000-ffffb6530000 rw-p 00000000 00:00 0 [1]: https://lore.kernel.org/linux-mm/20250111034511.2223353-1-liushixin2@huawei.com/ Signed-off-by: Yang Shi --- drivers/char/mem.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/char/mem.c b/drivers/char/mem.c index 169eed162a7f..dae113f7fc1b 100644 --- a/drivers/char/mem.c +++ b/drivers/char/mem.c @@ -527,6 +527,10 @@ static int mmap_zero(struct file *file, struct vm_area_struct *vma) if (vma->vm_flags & VM_SHARED) return shmem_zero_setup(vma); vma_set_anonymous(vma); + fput(vma->vm_file); + vma->vm_file = NULL; + vma->vm_pgoff = vma->vm_start >> PAGE_SHIFT; + return 0; }