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 98C9FC433F5 for ; Wed, 11 May 2022 05:20:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 308E76B0073; Wed, 11 May 2022 01:20:57 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2B6FD6B0075; Wed, 11 May 2022 01:20:57 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1581F8D0001; Wed, 11 May 2022 01:20:57 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 00B7B6B0073 for ; Wed, 11 May 2022 01:20:56 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id CC5C7217A7 for ; Wed, 11 May 2022 05:20:56 +0000 (UTC) X-FDA: 79452312912.19.E916972 Received: from mail-pg1-f179.google.com (mail-pg1-f179.google.com [209.85.215.179]) by imf11.hostedemail.com (Postfix) with ESMTP id 73E184009B for ; Wed, 11 May 2022 05:20:51 +0000 (UTC) Received: by mail-pg1-f179.google.com with SMTP id r71so498550pgr.0 for ; Tue, 10 May 2022 22:20:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=gShjsFeiifoug2plNelUILG6jaYpeyVtnTsKqAkuZ4k=; b=g5r8R2+cpHQZ5CuBtznNGp56UWg6h/nYX4H8ueSja/VvsvkHE3qUB1mJEUQGlWEMti 56aNXjewXY2clD+mpzMl4Rwc4vUJXDifmqMkh8spI1Xdk3ySZfe/oHJgZJ35aHbAAFGg nJhSFm+draoBSxEhb95zDgJudUoTDVP3jzAld5Gc0q6i2eoRP1h0R2f2JjlAJhfzXc4N CZxLVPxUpZoizs1JmN5BG+TSir3fiaEYLLH69/oFUIoPhRCGlWh0Wqa2KBm4r/0leHwB 0YSdZAiHOvlOodAbIuy2/R5XZeF1KNeprd0ysKDeNZ+3PheTg4BU+3ndUd/e1DU3Gc3b UQ1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=gShjsFeiifoug2plNelUILG6jaYpeyVtnTsKqAkuZ4k=; b=xhYSIWwNfUdLqYS/rFft0/ibiubVcwqPlJMUm65b+jmEZ1i618dItV/1RucQQ7/biw Ccba2HYQtrZO9WYZMcKEyqhZrQoWd3dW0R08xZL/tbnbdMDT229rqNTdh+aPsJ2igQaI 4oBAMRU3y0i79PPWw+EFkV6+nBNB4RhizrW9y7IwdUAGXLQOX8ntMtqIxRrc0F+61Fkp LI/at1JHC4EvMbbbiX3BRwdmHf4TUb4fOw7st4E509/7mEJWP20SaDfIBvr7jqHJdclZ nn0xHSm7HhpOU7ogVW/MpmcorEoMp4B38GquhoVwCKELDR0WM16Ed4LJxjSpkPK0sK4J C/aA== X-Gm-Message-State: AOAM5300ZK713+Q5d/BygcVZhD5caXeaBhnI5QSvB0FnOu/7YkIYToU7 0TNNuKuVjNFiJTRzs1E8Yzo= X-Google-Smtp-Source: ABdhPJynh0hIEwsWsuoZ5ITbr5lsshxQJn43n4NSnv7tPSHLz5gURAYqSdvkCGVbhpqvgP0zjW17hQ== X-Received: by 2002:a05:6a00:1352:b0:50d:ecff:f06c with SMTP id k18-20020a056a00135200b0050decfff06cmr23674727pfu.6.1652246455250; Tue, 10 May 2022 22:20:55 -0700 (PDT) Received: from hyeyoo ([114.29.24.243]) by smtp.gmail.com with ESMTPSA id e186-20020a621ec3000000b0050dc7628171sm517238pfe.75.2022.05.10.22.20.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 May 2022 22:20:54 -0700 (PDT) Date: Wed, 11 May 2022 14:20:45 +0900 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Dave Hansen Cc: Tom Lendacky , Rick Edgecombe , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , x86@kernel.org, "H. Peter Anvin" , "Kirill A. Shutemov" , Tianyu Lan , "Aneesh Kumar K.V" , linux-kernel@vger.kernel.org, linux-mm@kvack.org, vbabka@suse.cz, akpm@linux-foundation.org, mgorman@techsingularity.net, willy@infradead.org Subject: Is _PAGE_PROTNONE set only for user mappings? Message-ID: References: <20220506051940.156952-1-42.hyeyoo@gmail.com> <56f89895-601e-44c9-bda4-5fae6782e27e@amd.com> <5fe161cb-6c55-6c4d-c208-16c77e115d3f@amd.com> <8c2735ac-0335-6e2a-8341-8266d5d13c30@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <8c2735ac-0335-6e2a-8341-8266d5d13c30@intel.com> X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 73E184009B X-Stat-Signature: nywby4metjj6u4b3ea4ydqacqp8b8fcm X-Rspam-User: Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=gmail.com header.s=20210112 header.b=g5r8R2+c; spf=pass (imf11.hostedemail.com: domain of 42.hyeyoo@gmail.com designates 209.85.215.179 as permitted sender) smtp.mailfrom=42.hyeyoo@gmail.com; dmarc=pass (policy=none) header.from=gmail.com X-HE-Tag: 1652246451-31917 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 Tue, May 10, 2022 at 07:39:30AM -0700, Dave Hansen wrote: > On 5/10/22 06:35, Tom Lendacky wrote: > > I'm wondering if adding a specific helper that takes a boolean to > > indicate whether to set the global flag would be best. I'll let some of > > the MM maintainers comment about that. > > First of all, I'm not positive that _PAGE_BIT_PROTNONE is ever used for > kernel mappings. This would all get a lot easier if we decided that > _PAGE_BIT_PROTNONE is only for userspace mappings and we don't have to > worry about it when _PAGE_USER is clear. After quickly skimming code it seems the place that actually sets _PAGE_PROTNONE is via mm/mmap.c's protection_map: > /* description of effects of mapping type and prot in current implementation. > * this is due to the limited x86 page protection hardware. The expected > * behavior is in parens: > * > * map_type prot > * PROT_NONE PROT_READ PROT_WRITE PROT_EXEC > * MAP_SHARED r: (no) no r: (yes) yes r: (no) yes r: (no) yes > * w: (no) no w: (no) no w: (yes) yes w: (no) no > * x: (no) no x: (no) yes x: (no) yes x: (yes) yes > * > * MAP_PRIVATE r: (no) no r: (yes) yes r: (no) yes r: (no) yes > * w: (no) no w: (no) no w: (copy) copy w: (no) no > * x: (no) no x: (no) yes x: (no) yes x: (yes) yes > * > */ > pgprot_t protection_map[16] = { > __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111, > __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111 > }; Where __P000, __S000 is PAGE_NONE (_PAGE_ACCESSED | _PAGE_PROTNONE). And protection_map is accessed via: > pgprot_t vm_get_page_prot(unsigned long vm_flags) > { > pgprot_t ret = __pgprot(pgprot_val(protection_map[vm_flags & > (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) | > pgprot_val(arch_vm_get_page_prot(vm_flags))); > > return arch_filter_pgprot(ret); > } > EXPORT_SYMBOL(vm_get_page_prot); I guess it's only set for processes' VMA if no caller is abusing vm_get_page_prot() for kernel mappings. But yeah, just quick guessing does not make us convinced. Let's Cc people working on mm. If kernel never uses _PAGE_PROTNONE for kernel mappings, it's just okay not to clear _PAGE_GLOBAL at first in __change_page_attr() if it's not user address, because no user will confuse _PAGE_GLOBAL as _PAGE_PROTNONE if it's kernel address. right? > > Second, the number of places that do these > __set_pages_p()/__set_pages_np() pairs is pretty limited. Some of them > are *quite* unambiguous over whether they are dealing with the direct map: > > > int set_direct_map_invalid_noflush(struct page *page) > > { > > return __set_pages_np(page, 1); > > } > > > > int set_direct_map_default_noflush(struct page *page) > > { > > return __set_pages_p(page, 1); > > } > > which would make it patently obvious whether __set_pages_p() should > restore the global bit. That would have been a problem in the "old" PTI > days where _some_ of the direct map was exposed to Meltdown. I don't > think we have any of those mappings left, though. They're all aliases > like text and cpu_entry_area. > > It would be nice if someone could look into unraveling > _PAGE_BIT_PROTNONE. We could even probably move it to another bit for > kernel mappings if we actually need it (I'm not convinced we do). -- Thanks, Hyeonggon