Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp993360iob; Fri, 13 May 2022 18:55:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZd5Z5zz4xhgynFnOVf9Odu5SUQMMJ6aBdF5bwpo9NIIHNXL3B9PrHWvhlL5/oHeKJnnJ9 X-Received: by 2002:a05:6000:1d93:b0:20c:58f8:f530 with SMTP id bk19-20020a0560001d9300b0020c58f8f530mr5900976wrb.254.1652493343041; Fri, 13 May 2022 18:55:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652493343; cv=none; d=google.com; s=arc-20160816; b=bXtXeV0J1CzxWTXOy8v0Ab7Josx+Q40oJK+cR/KsA+AmMDPLqbKePj3IOWN/L6hDmp gBEk+4oKckSOIvITV3jqtVMCT5ikWowknzoUoSnbX0nlTz6IfL1tzOvm3aS8y7thaX5P TlSrZEjnqbpPSTb8pTI47Uoip24kwjQWLp3XnIsRV5a0krVRDJ7CG/yh6ceOuBygNxiO HfEopaZhidQ9pIyP0XTKL4qqxsQxVo+AVsziIQGdey83En7WYXIyDuMAQg9kQyNEwgrx no+6yO6vvj6Y2g3EW3HUarwlMFTdhL7eVUNCI3TEIXy0UNuVdwk5rST4eKzXnhIiUFqv C0gg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=45P3BUfFsVexFqPhisLDrPcZ+PguqAtbUCDFuvnZQ4o=; b=nAk0n77acAGp10Vf9q7f9pSMUFnFsc0UNZ9RLkBs/gRfhDrON8bRJAMUJnkrvhXaGu e45YPXB+/6w53nTrOKwmXP0JMBr6g3UBw3IB8c+a86+M2lPiwjsX37k8VVbBNBgPWIuH 3Aq3VUYVK0j4427gZ0jCaQx6BK7RAVXxnpO+jCOVD9vpNkZ8WN5MWhraLjOhEB8txjAU 8VEcrAQzHvaaksJh0Phx9Y2lfddWgKvX4gr65G3zHsxc9gUJH+lTUr0ypp8a/MvpimjZ 8p7gK+WHVXpBydLNeAMYMn0ak/50SJGz2+NTgqENUnbVkA2hKa2TnQDFrsLnv+ZsGiaZ 6myg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=hB2VGxyS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id v5-20020a05600c214500b0038c77be9b98si6540811wml.179.2022.05.13.18.55.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 18:55:43 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=hB2VGxyS; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 8E5D345FCAE; Fri, 13 May 2022 17:18:51 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1377084AbiEMFdw (ORCPT + 99 others); Fri, 13 May 2022 01:33:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42286 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344254AbiEMFdu (ORCPT ); Fri, 13 May 2022 01:33:50 -0400 Received: from mail-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BFB813C360 for ; Thu, 12 May 2022 22:33:48 -0700 (PDT) Received: by mail-pg1-x52d.google.com with SMTP id v10so6520633pgl.11 for ; Thu, 12 May 2022 22:33:48 -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=45P3BUfFsVexFqPhisLDrPcZ+PguqAtbUCDFuvnZQ4o=; b=hB2VGxySOCnZ6hzyjobSttjhGlnl0ir50A3N6LoQ4kuBhQJ6YzUcI7Rv+4+YiY9YuJ UV3Ix2lLblfECTY9EgZrq8ApgqzF4Nx54nW2M3B2vdUTmfifZu3m0IXR1q6xrhrx+qU0 cj6h14XBi/pT5kesJaE5Nm5/ZyNAhocEHTejsJKGzhWz9eckUPuAeMrujV6gn+8WvSzy TFyFE+YSPxvqfEKKrAVJHA6ltMl2LSCfDXBkZvuS6lMR4icYU6l9ZVu13Y0R7eca1NAe VEzFNX1mWV047CqnmP8s/JEKVC+ZZ7kFIOUqp5/AVO3O/nDd+wfLRkjNcNGMGrMOAZrq H4bw== 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=45P3BUfFsVexFqPhisLDrPcZ+PguqAtbUCDFuvnZQ4o=; b=evKEXEy7ff0X4R7qMzgn2VgDst8jsq0jc1r1HW0Cbq7XsQEuauX4pOGLxFjT8b9DQh 0FVz+X77JLj0tb/7xlXxGxVYB79wpBKVXQflhaNHFwC6U53izX2th2OKZf1hcT/JLQjS 6sx104cBvIQr+g9duqnvQSDu1Wi73CNrkY/VRTVg8F6YGYZ8q58cKrBXftAZOAGWz1hv C77U6eBFzwvKpHiMXEcY++rth2DJJn/qUR8IwsOP3UmAK4t8lHQNr0CrObIpPjUXIQcY ITYGTtPK9YULhPNkJtitBxeNR71fNS/jyZBh8eEqCvmFFmBvwyFbDanF2W9Jk/OkJCof oXLQ== X-Gm-Message-State: AOAM531slzIA/41LvLaEt+m1BnP56A953xkaqgXCjnTuuVIyT7ZQGIqh Q7J5dLkcrXSD1ZfwvHfjfrY= X-Received: by 2002:a05:6a00:174a:b0:50d:44ca:4b with SMTP id j10-20020a056a00174a00b0050d44ca004bmr3047546pfc.0.1652420027865; Thu, 12 May 2022 22:33:47 -0700 (PDT) Received: from hyeyoo ([114.29.24.243]) by smtp.gmail.com with ESMTPSA id i17-20020a056a00225100b0050dc7628161sm762640pfu.59.2022.05.12.22.33.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 22:33:47 -0700 (PDT) Date: Fri, 13 May 2022 14:33:38 +0900 From: Hyeonggon Yoo <42.hyeyoo@gmail.com> To: Mel Gorman Cc: Dave Hansen , 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, willy@infradead.org Subject: Re: 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> <20220512103748.GH3441@techsingularity.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220512103748.GH3441@techsingularity.net> X-Spam-Status: No, score=-0.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HK_RANDOM_FROM,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, May 12, 2022 at 11:37:48AM +0100, Mel Gorman wrote: > On Wed, May 11, 2022 at 02:20:45PM +0900, Hyeonggon Yoo wrote: > > > 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? > > > > I'm not aware of a case where _PAGE_BIT_PROTNONE is used for a kernel > address expecting PROT_NONE semantics instead of the global bit. NUMA > Balancing is not going to accidentally treat a kernel address as if it's > a NUMA hinting fault. By the time a fault is determining if a PTE access > is a numa hinting fault or accesssing a PROT_NONE region, it has been > established that it is a userspace address backed by a valid VMA. > Thanks Mel, and IIUC nor does do_kern_addr_fault() in arch/x86/mm/fault.c expect _PAGE_PROTNONE instead of _PAGE_GLOBAL. I want to make it clear in the code that _PAGE_PROTNONE is only used for user mappings. How does below look? diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h index 40497a9020c6..f8d02b91a90c 100644 --- a/arch/x86/include/asm/pgtable_types.h +++ b/arch/x86/include/asm/pgtable_types.h @@ -35,7 +35,10 @@ #define _PAGE_BIT_DEVMAP _PAGE_BIT_SOFTW4 /* If _PAGE_BIT_PRESENT is clear, we use these: */ -/* - if the user mapped it with PROT_NONE; pte_present gives true */ +/* + * if the user mapped it with PROT_NONE; pte_present gives true + * this is only used for user mappings (with _PAGE_BIT_USER) + */ #define _PAGE_BIT_PROTNONE _PAGE_BIT_GLOBAL #define _PAGE_PRESENT (_AT(pteval_t, 1) << _PAGE_BIT_PRESENT) @@ -115,7 +118,8 @@ #define _PAGE_DEVMAP (_AT(pteval_t, 0)) #endif -#define _PAGE_PROTNONE (_AT(pteval_t, 1) << _PAGE_BIT_PROTNONE) +#define _PAGE_PROTNONE ((_AT(pteval_t, 1) << _PAGE_BIT_USER) | \ + (_AT(pteval_t, 1) << _PAGE_BIT_PROTNONE)) /* * Set of bits not changed in pte_modify. The pte's -- Thanks, Hyeonggon