Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp3572384rwb; Mon, 3 Oct 2022 17:51:34 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6I6A80CoCE893DdfbGmeqLEaEyaSi9CV3IMNAh8RZl/xDt6NGJHvTnWgh8O0D125pLA1yv X-Received: by 2002:a17:907:97c6:b0:783:dcad:3454 with SMTP id js6-20020a17090797c600b00783dcad3454mr17562498ejc.271.1664844693719; Mon, 03 Oct 2022 17:51:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1664844693; cv=none; d=google.com; s=arc-20160816; b=u/+K++4MyvKRFVSo6MaIFhETP7ofZ1JO5J1JsLaJV709PLM/21Xp2fbxTDVUH/82qw uM9983NsSR0QnaJMuBu+5vibOUSfAT1BjgrcqaicLrzAZGhoIl8FTDei4BRHudWJ8NpC 1jRJXsSisO1uY99rabsqBV6GlyFRoEAXb+X03VsnbAYCl6wL+BZut+/1nTKoZ4pLY4Tz NQ27vXHFDLrbAcwniy77sF/YTv5DHAaNujutLiv7B7oXJeV1tOMW4mu1CIhihtSu2nw3 JOqFu4Fnn/fqBxPi1kWxq2Px1u4zeJxl+oZF7u8HmIMt8m7KOvf4j9AgNBlF3XDjfuQ0 /J+g== 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=clbOVo6ui6rhZVYi6ypZyXSB2Q4+tqXLf5XrsaXYRJs=; b=D6oS8OIJQgd4dn2GeuzN8ZyUr8QWhZKaPuXW1tt2vgmRGTA9tpcwMyM/xuNDuWn/Ll C4+lqj2ZRyCLYnMXRSDGPPmbJcIVJT3YNTuk452/dQuvciN9qyQ2pCYjdewT0t/lsye8 cb6rM8MjsdyMN1/S5qKc4iQed2iM4Nf3QuT15SdtpIH8Euc0CzXIoz2RfeAKHsb8f8mo GAnvDaCKln4EENdcE/2gFZ4qziF9sBzjqHwcD8ZFTUA0G+BV334s7OoUEfNQq5uz3e4n X0AS9M6CMclqkU1rhs5M3j2eUOfPyJpOY2y9/OrUMgKE5nc4WamkgmU1BOfq39YrM/Yn fwng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=EZvh8XdO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dn18-20020a17090794d200b0073866c0672asi10103643ejc.73.2022.10.03.17.51.07; Mon, 03 Oct 2022 17:51:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=EZvh8XdO; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230025AbiJDAD6 (ORCPT + 99 others); Mon, 3 Oct 2022 20:03:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50120 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229881AbiJDADv (ORCPT ); Mon, 3 Oct 2022 20:03:51 -0400 Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32F3E193EA; Mon, 3 Oct 2022 17:03:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1664841829; x=1696377829; h=date:from:to:cc:subject:message-id:references: mime-version:in-reply-to; bh=Os63+EX8WH0KuFh3ggC0GBsbdgmNnf/a/c28uddDCRs=; b=EZvh8XdO1EBPFl2b4cjCcrZmrosIvJdkJXcT90hLU79P2EbNFS2B1WsB dfx1NGWcq6hqYvvnwayHO3SXUoEXDn0QKKnSIu0+evh9iGxDFIF30rqTY 72Ha8E/qHVWlBIpveJ4V6gaGdBI5bOR5pOFQU0+pEGRZN88pk1wFCWOhm HxZX4wlTHkBCNTt/TRvIggQvjo2tHQ5kI+Urfwy05bqoyVAhRW9IDgisU y5V7KQNUOaKO9acNf8IUmOvINnfdOw4nGrLscSLEzM4aKQX/XpWSioip/ mfVTPSNX+zd4crb5U4O1yYMYdDyuoQPyIBf4z2AX8oXzwczj61QmJbdNU w==; X-IronPort-AV: E=McAfee;i="6500,9779,10489"; a="290010298" X-IronPort-AV: E=Sophos;i="5.93,366,1654585200"; d="scan'208";a="290010298" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Oct 2022 17:03:47 -0700 X-IronPort-AV: E=McAfee;i="6500,9779,10489"; a="656943083" X-IronPort-AV: E=Sophos;i="5.93,366,1654585200"; d="scan'208";a="656943083" Received: from bandrei-mobl.ger.corp.intel.com (HELO box.shutemov.name) ([10.252.37.219]) by orsmga001-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Oct 2022 17:03:38 -0700 Received: by box.shutemov.name (Postfix, from userid 1000) id 659E3104CE4; Tue, 4 Oct 2022 03:03:36 +0300 (+03) Date: Tue, 4 Oct 2022 03:03:36 +0300 From: "Kirill A . Shutemov" To: Rick Edgecombe Cc: x86@kernel.org, "H . Peter Anvin" , Thomas Gleixner , Ingo Molnar , linux-kernel@vger.kernel.org, linux-doc@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, linux-api@vger.kernel.org, Arnd Bergmann , Andy Lutomirski , Balbir Singh , Borislav Petkov , Cyrill Gorcunov , Dave Hansen , Eugene Syromiatnikov , Florian Weimer , "H . J . Lu" , Jann Horn , Jonathan Corbet , Kees Cook , Mike Kravetz , Nadav Amit , Oleg Nesterov , Pavel Machek , Peter Zijlstra , Randy Dunlap , "Ravi V . Shankar" , Weijiang Yang , joao.moreira@intel.com, John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, Yu-cheng Yu Subject: Re: [PATCH v2 19/39] mm/mmap: Add shadow stack pages to memory accounting Message-ID: <20221004000336.cpuats6iamw5ob3h@box.shutemov.name> References: <20220929222936.14584-1-rick.p.edgecombe@intel.com> <20220929222936.14584-20-rick.p.edgecombe@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220929222936.14584-20-rick.p.edgecombe@intel.com> X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE autolearn=ham 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, Sep 29, 2022 at 03:29:16PM -0700, Rick Edgecombe wrote: > From: Yu-cheng Yu > > Account shadow stack pages to stack memory. > > Signed-off-by: Yu-cheng Yu > Co-developed-by: Rick Edgecombe > Signed-off-by: Rick Edgecombe > Cc: Kees Cook > > --- > > v2: > - Remove is_shadow_stack_mapping() and just change it to directly bitwise > and VM_SHADOW_STACK. > > Yu-cheng v26: > - Remove redundant #ifdef CONFIG_MMU. > > Yu-cheng v25: > - Remove #ifdef CONFIG_ARCH_HAS_SHADOW_STACK for is_shadow_stack_mapping(). > > mm/mmap.c | 5 +++++ > 1 file changed, 5 insertions(+) > > diff --git a/mm/mmap.c b/mm/mmap.c > index f0d2e9143bd0..8569ef09614c 100644 > --- a/mm/mmap.c > +++ b/mm/mmap.c > @@ -1682,6 +1682,9 @@ static inline int accountable_mapping(struct file *file, vm_flags_t vm_flags) > if (file && is_file_hugepages(file)) > return 0; > > + if (vm_flags & VM_SHADOW_STACK) > + return 1; > + > return (vm_flags & (VM_NORESERVE | VM_SHARED | VM_WRITE)) == VM_WRITE; Hm. Isn't the last check true for shadow stack too? IIUC, shadow stack has VM_WRITE set, so accountable_mapping() should work correctly as is. -- Kiryl Shutsemau / Kirill A. Shutemov