From mboxrd@z Thu Jan 1 00:00:00 1970 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 9BA5CC05027 for ; Thu, 26 Jan 2023 09:16:38 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D51D48E0002; Thu, 26 Jan 2023 04:16:37 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D01F46B0072; Thu, 26 Jan 2023 04:16:37 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BF1398E0002; Thu, 26 Jan 2023 04:16:37 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id AF7046B0071 for ; Thu, 26 Jan 2023 04:16:37 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 863A480730 for ; Thu, 26 Jan 2023 09:16:37 +0000 (UTC) X-FDA: 80396394834.22.583BC3F Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.220.29]) by imf24.hostedemail.com (Postfix) with ESMTP id 967E018000F for ; Thu, 26 Jan 2023 09:16:35 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=QznN9I0o; spf=pass (imf24.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674724595; a=rsa-sha256; cv=none; b=kGhLqFUcN1EoV6qFzUYGH4nZIyDiWlgRUJ7MhADg0A3scmt1A3r+29Hh8/0fVkPRHUGGg5 2sgty7xVt0sQrg/0YUJPKAlMmwcE7+7VahrmVnfPZaanVTxeaCdFkpmmHaDLbFuSTzNVZr 2VWB74OHQIh5CaHNEBi86iduXgbvIOs= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=suse.com header.s=susede1 header.b=QznN9I0o; spf=pass (imf24.hostedemail.com: domain of mhocko@suse.com designates 195.135.220.29 as permitted sender) smtp.mailfrom=mhocko@suse.com; dmarc=pass (policy=quarantine) header.from=suse.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1674724595; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=3DTYXj8VSHobiZCY9tKel9t1EoPg2gUvPAxKNcpDsbE=; b=sDpM9Nr2y0QpgAYtIeWG3hF6KaBIFWz4AfkZaJf1XLrz+rI6PeAxPgGEAuDT/CF5MS00da o7/RgB181wTzuoObn4LgJhe4Da6Sg4DPGUxeGbAinIQV1sL6CTGD/T/MbBZF8x1hQlFSNY V6/LaEFWsKOFcB2RWIbh3ZqFlkO0EpQ= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 3B3361FECD; Thu, 26 Jan 2023 09:16:34 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1674724594; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: in-reply-to:in-reply-to:references:references; bh=3DTYXj8VSHobiZCY9tKel9t1EoPg2gUvPAxKNcpDsbE=; b=QznN9I0oGIk1pLDC73kelRvx30oJwLBq4dgggTTmVtBGAPsHcTF12MzZe7ufG+bOPfVUTb JN6caK85+9Cel9MtzrsOa61ZRgggEml2TO7EQ92Bb1xAe/5bTJzJ08dMdh8G6e8CPd2ho+ UfEftX5dDFtu+kpx3zy/Dvkl871XcsY= Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 1B1B1139B3; Thu, 26 Jan 2023 09:16:34 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id BnqaA/JE0mPiUQAAMHmgww (envelope-from ); Thu, 26 Jan 2023 09:16:34 +0000 Date: Thu, 26 Jan 2023 10:16:33 +0100 From: Michal Hocko To: Mike Kravetz Cc: linux-mm@kvack.org, Naoya Horiguchi , David Rientjes , Matthew Wilcox , David Hildenbrand , Peter Xu , James Houghton , Muchun Song Subject: Re: A mapcount riddle Message-ID: References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Rspam-User: X-Rspamd-Queue-Id: 967E018000F X-Rspamd-Server: rspam01 X-Stat-Signature: 1ynnntzdgdsodtcr93czrmgz6ym9wwfj X-HE-Tag: 1674724595-635910 X-HE-Meta: U2FsdGVkX18qyps3YJ4s1VKZVyOJJUqAFNNAga/bfkpGbVaWh8uEZAeIA3qTHrCls3FTolDRuG8GVJBkr0kPtxue/kxMsvmDVlBRa/teIWKza49LcPN162rNnAb8Vp3lqY74keloqeE8NRWgd4yffNQ7US+mYeSvgptrbWIn5VNfxou9kpcsn0+dsLsbndqNT2hmqBDUgsX8s7N2XABTXzL92nGobD8hT16aXQ/bQmfcTOwu3Hmem+CDh8GbgRAk4NWczzZgKORicN/K8Yd5Vvibwzfo7/GxpAh/GB//wmU66mNkeSZhHH50hq1pCV2Ck4BS3jHcXjhs4fzgdzmlHyad9MWE78rDCajGt12+V3n0h50CUOfpVki3IltYQZZgf5D+CkSeZxKNxzDyzgRS16v5zhV3eEGEAisMmzMdC7cS5Jn2nwmtdxxt6VzASrfKWgv7ZlIleZ1H8GKF45HNmxHzq/yAiMTMFMZObNnLUic93u5yqssOKxUrFYgH29e2Jlhi/ZwYOvrBnxEvV7vU3JKMgWN4o5iGX8YSBCLqwY0lNjgameG47Pl4xE2ap25+QnHMRZJrKVriiqSRXibsb4hd6Q92iSbmjjjdoQT67h4OyCnngl2B8E59RhQsK//1OM63G9NL3rfQhakcOEKxRT9788ZKeqMCr7dKsNEw7sc7U3Nxkj6u0pg0uWeVYypC6RQ0GQxNCpIvUeqKtGSqDdAxXC7463Q2wLuO2xODTAh/j683HtZnsdmbgZ6CyL7BailX60Ju4XBdR6PhX0wdkMWrcQZvZLkNOXgTdmwKYAOpwnFkCKXVQ9fsQeSzKl6aJgbj1bfJ0s7ENZGwuUMyOnbL8FBJc/XU10WElA57TJts2UmIBsvGoAZo5WWqpfqWbkwxtyNI5PclOteAk5bTbJgmkBxgCJl+UNXJCkqYXjQm5s2krmjaNFW7xbjqza7mtji44nHbLSF2pY6mbw3 Hk4UZ33n X0o0FohY76W55U+jsqnHLymKTGg8ESv+X69OPt5alBO5e+3izpXSVV4cFeZsXflWQb0pLGkWxTWR9EZYq63e/S6L3wT9Oq4a4viaFshASzpPAECPJlEwmVwNTBS8rxeNJ41zVMjTy+Y8EVvewAjmAQZGoY/za//fq2ni9dKYQ7cFFYHM= 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: On Wed 25-01-23 09:59:15, Mike Kravetz wrote: > On 01/25/23 09:24, Michal Hocko wrote: > > On Tue 24-01-23 12:56:24, Mike Kravetz wrote: > > > At first thought this seems bad. However, I believe this has been the > > > behavior since hugetlb PMD sharing was introduced in 2006 and I am > > > unaware of any reported issues. I did a audit of code looking at > > > mapcount. In addition to the above issue with smaps, there appears > > > to be an issue with 'migrate_pages' where shared pages could be migrated > > > without appropriate privilege. > > > > > > /* With MPOL_MF_MOVE, we migrate only unshared hugepage. */ > > > if (flags & (MPOL_MF_MOVE_ALL) || > > > (flags & MPOL_MF_MOVE && page_mapcount(page) == 1)) { > > > if (isolate_hugetlb(page, qp->pagelist) && > > > (flags & MPOL_MF_STRICT)) > > > /* > > > * Failed to isolate page but allow migrating pages > > > * which have been queued. > > > */ > > > ret = 1; > > > } > > > > Could you elaborate what is problematic about that? The whole pmd > > sharing is a cooperative thing. So if some of the processes decides to > > migrate the page then why that should be a problem for others sharing > > that page via page table? Am I missing something obvious? > > Nothing obvious. It is just that the semantics seem to be that you can > only move shared pages if you have CAP_SYS_NICE. Correct > Certainly cooperation > is implied for shared PMDs, but I would guess that most applications are > not even aware they are sharing PMDs. How come? They have to explicitly map those hugetlb pages to the same address. Or is it common that the mapping just lands there by accident? > Consider a group of processes sharing a hugetlb mapping. If the mapping > is PUD_SIZE - huge_page_size, there is no sharing of PMDs and a process > without CAP_SYS_NICE can not migrate the shared pages. However, if nothing > else changes and the mapping size is PUD_SIZE (and appropriately aligned) > the PMDs are shared. Should we allow a process to migrate shared pages > without CAP_SYS_NICE in this case? I am not sure I follow. I have likely got lost in the above. So the move_pages interface requires CAP_SYS_NICE to allow moving shared pages. pmd shared hugetlb pages fail the "I am shared" detection so even processes without CAP_SYS_NICE are allowed to migrate those. This is not ideal because somebody unpriviledged (with an access to the address space) could impose additional latencies. The question is whether this really matters for workloads that opt-in for pmd sharing. It is my understanding that those are in cooperative mode so an adversary player is not a threat model. Or am I wrong in that assumption? I haven't checked very closely but wouldn't be mprotect a bigger problem? I do not remember any special casing for hugetlb pmd sharing there. -- Michal Hocko SUSE Labs