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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B2E7C6FD1D for ; Fri, 17 Mar 2023 17:12:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229875AbjCQRMj (ORCPT ); Fri, 17 Mar 2023 13:12:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230171AbjCQRMe (ORCPT ); Fri, 17 Mar 2023 13:12:34 -0400 Received: from mail-yb1-xb31.google.com (mail-yb1-xb31.google.com [IPv6:2607:f8b0:4864:20::b31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B2D27580C4 for ; Fri, 17 Mar 2023 10:12:31 -0700 (PDT) Received: by mail-yb1-xb31.google.com with SMTP id t6so391138ybb.9 for ; Fri, 17 Mar 2023 10:12:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; t=1679073150; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=3ikWb9GqbCHXDoNjDF2yyQsEog3dPXb54BKqYKGLZKo=; b=Zfo2sCJiLQjkcgp4hl850DgKMGKFeMrifVhcXlQv2qElaBsO7vaXPlKO/mdARlti23 8VPUEVXZngQedMVddPcy+xa7qlbkZuDci2xhcaUrExNMXCB0BLRPSznglejsnJNXw5ga RHzCNLPAoyv8psmkyR/QZtWDNz6zDpFfajtu9fd+byeuGP3OVNiTX1NwMkTXrRsmSiaM kwPuCZirTBcWpekpwTV60PfiSEURz6/awp/zWgGgnqKwCMh3QLkJmqKnQYqmXwIwAIlV kTtlgROVwfJgJkjXYAVD+QfBwuzQqod4NYECB2ZccqVLkcppcUvaY7Cc2QbGnU59+iYz YDbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1679073150; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3ikWb9GqbCHXDoNjDF2yyQsEog3dPXb54BKqYKGLZKo=; b=mdk+wFql1XOWJ+bTcw8GKaNoMXyQjXkGYMJ58/KkDPI28T2vpvNSNYbEbtnAcQqRv4 4RM5E2yEcVPalaA+slVlZmM9kT5bC5Ex8HfGpdTyYCE/yFqYsid+i+Zc5gMbW18TliMi pY/DPK0pAAlnThPPZ4zVRuxn4MNkrJbzPcowIxivNhW/L3uAPOfvCIc4E2IQZc/K7ksG SQcTbUwW+IItqyrirEktIFTFknByOYGrac5qPs9WqPPN51Dhv0sv0R7ComPORDSOvsdR zmdyEe0uwOwSueIB8adKBW+tBZ/+mknNMy1g4fEkncVRtw1jDizL1RYHqgCvSn6zyrNP 2A/w== X-Gm-Message-State: AO0yUKUCfiPgV3ntP3B7whJwaM55nt4JIaex38bRJEX59IZa4GUcl3lG 7LpVMYkF5bWF7WNHN7y4cMqIUN17VDh5Lsu2k82SRw== X-Google-Smtp-Source: AK7set/QfKKXHCQJ3mrdY3gq80ku8GQMwyT8c5IhgvAeBv6xKwxPXs/SU34oJvp29NZ60hId0CNTrh08jaWhgmevYpM= X-Received: by 2002:a5b:bc3:0:b0:ac2:a7a7:23c3 with SMTP id c3-20020a5b0bc3000000b00ac2a7a723c3mr154479ybr.12.1679073150497; Fri, 17 Mar 2023 10:12:30 -0700 (PDT) MIME-Version: 1.0 References: <20230227222957.24501-1-rick.p.edgecombe@intel.com> <20230227222957.24501-23-rick.p.edgecombe@intel.com> In-Reply-To: <20230227222957.24501-23-rick.p.edgecombe@intel.com> From: Deepak Gupta Date: Fri, 17 Mar 2023 10:12:21 -0700 Message-ID: Subject: Re: [PATCH v7 22/41] mm/mmap: Add shadow stack pages to memory accounting 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 , Weijiang Yang , "Kirill A . Shutemov" , John Allen , kcc@google.com, eranian@google.com, rppt@kernel.org, jamorris@linux.microsoft.com, dethoma@microsoft.com, akpm@linux-foundation.org, Andrew.Cooper3@citrix.com, christina.schimpe@intel.com, david@redhat.com, Yu-cheng Yu Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Feb 27, 2023 at 2:31=E2=80=AFPM Rick Edgecombe wrote: > > From: Yu-cheng Yu > > The x86 Control-flow Enforcement Technology (CET) feature includes a new > type of memory called shadow stack. This shadow stack memory has some > unusual properties, which requires some core mm changes to function > properly. > > Account shadow stack pages to stack memory. Do this by adding a > VM_SHADOW_STACK check in is_stack_mapping(). > > Tested-by: Pengfei Xu > Tested-by: John Allen > Tested-by: Kees Cook > Acked-by: Mike Rapoport (IBM) > Reviewed-by: Kees Cook > Signed-off-by: Yu-cheng Yu > Co-developed-by: Rick Edgecombe > Signed-off-by: Rick Edgecombe > Cc: Kees Cook > > --- > v7: > - Change is_stack_mapping() to know about VM_SHADOW_STACK so the > additions in vm_stat_account() can be dropped. (David Hildenbrand) > > v3: > - Remove unneeded VM_SHADOW_STACK check in accountable_mapping() > (Kirill) > > v2: > - Remove is_shadow_stack_mapping() and just change it to directly bitwis= e > 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/internal.h | 8 ++++---- > 1 file changed, 4 insertions(+), 4 deletions(-) > > diff --git a/mm/internal.h b/mm/internal.h > index 7920a8b7982e..1d13d5580f64 100644 > --- a/mm/internal.h > +++ b/mm/internal.h > @@ -491,14 +491,14 @@ static inline bool is_exec_mapping(vm_flags_t flags= ) > } > > /* > - * Stack area - automatically grows in one direction > + * Stack area > * > - * VM_GROWSUP / VM_GROWSDOWN VMAs are always private anonymous: > - * do_mmap() forbids all other combinations. > + * VM_GROWSUP, VM_GROWSDOWN VMAs are always private > + * anonymous. do_mmap() forbids all other combinations. > */ > static inline bool is_stack_mapping(vm_flags_t flags) > { > - return (flags & VM_STACK) =3D=3D VM_STACK; > + return ((flags & VM_STACK) =3D=3D VM_STACK) || (flags & VM_SHADOW= _STACK); Same comment here. `VM_SHADOW_STACK` is an x86 specific way of encoding a shadow stack. Instead let's have a proxy here which allows architectures to have their own encodings to represent a shadow stack. > } > > /* > -- > 2.17.1 >