From patchwork Tue Oct 29 23:44:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13855718 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 9103BD7494D for ; Tue, 29 Oct 2024 23:44:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D16736B008C; Tue, 29 Oct 2024 19:44:24 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CC9626B0093; Tue, 29 Oct 2024 19:44:24 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id ACA1E6B0095; Tue, 29 Oct 2024 19:44:24 -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 8A0F56B008C for ; Tue, 29 Oct 2024 19:44:24 -0400 (EDT) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id DF2FAC065D for ; Tue, 29 Oct 2024 23:44:23 +0000 (UTC) X-FDA: 82728269526.17.8E44E22 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by imf30.hostedemail.com (Postfix) with ESMTP id 9FFF980006 for ; Tue, 29 Oct 2024 23:43:34 +0000 (UTC) Authentication-Results: imf30.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=M+ubaysV; spf=pass (imf30.hostedemail.com: domain of debug@rivosinc.com designates 209.85.215.172 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1730245249; 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:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=c+Jub7HVMuRDhaa+pd538ONaRqIx67oBmBuHa5UsgJY=; b=1M/vin6JTydAGvbpLFUueXotwx+YzIuNFhIZ3Q0YGqXZuIN5p74cgjCbdfyvo7EbFLziOU vlQ955lBoCWMw/29MJKW5IVzSlmBWxrBzOGwueGu/WIvcl5MyHUKhkOWRbnPyYsDRDmYeI NWBMaVwZTM17/CNHEOr+6SbmYmzMIuA= ARC-Authentication-Results: i=1; imf30.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=M+ubaysV; spf=pass (imf30.hostedemail.com: domain of debug@rivosinc.com designates 209.85.215.172 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1730245249; a=rsa-sha256; cv=none; b=QnrlOLkv5hUZbxkNuOmfw16srk25Kt9E4q3XKbj7pxJYn8eUrGzLSA55npCC6db7sy+xO1 nf9u6KOHH/fBeXY5ObpKsUkhKeHiwP/awzrqd71kKzZCPThb8R/EeEjhjrTBxu6Hjx9mKf 5gZFAuOB63wKLMsucqNvkfrqEQJ+Lis= Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-7ed9f1bcb6bso4111171a12.1 for ; Tue, 29 Oct 2024 16:44:21 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1730245461; x=1730850261; darn=kvack.org; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:from:to:cc:subject:date:message-id :reply-to; bh=c+Jub7HVMuRDhaa+pd538ONaRqIx67oBmBuHa5UsgJY=; b=M+ubaysVBgYYHORul+E0BId8e/yn8E/IhQIK9QmKj+4bfO+fZTyZA2KV6zdQDHz6xm uZgMsbi6qfS4v9L5n5poxk/AO+LgosBFkqaP/aD9Tn2m2C5zQovBOgekcAktx+rhRJU/ 3B+OW/X1w3aLPtOb/oCbDkImwbgNasLA36aOKIg3u3R6K79XAkmM7lBm/CtiQw1mUouV ZBGAQU6STbpLL0J40ER7g3HegYG97c5uZPgnOcfqYPwleLULd84SIE6u+kiRdWxr3hHI /2cKHZnNr/vSQHco/u6JS3KtX1ATbsGn3vCprJvlz/4t/jBre5HbgdBkn9jVOD0sWifS COIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730245461; x=1730850261; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:subject:date:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=c+Jub7HVMuRDhaa+pd538ONaRqIx67oBmBuHa5UsgJY=; b=alnb+ax5+XO5e/lnJq0Z+U2krkWA9bvhwS34NTSoHSnhJ4Ly40z+Z21l+A2MqFQ/ye zy5NdYKzLasNVHUiLYcr2pW6uMj/bZjxl9sNnnJImjIetKt1C3FF/zU0eodZe1OhhQxk L1H/AU6C2Kw/rFLXy6/IDSP8bIUvJYYAj2TLD/hQZpspcxuEqOgq6M9EkRCbymMnyoIn NHENk6syY74Pc6DSjx7CI8rFSfq2tQNAiXevuQFk5MVa5FCdiKnU1UNnKs+sRmYEfiRB m6BdkaUUSI7toYy7yPYdLu71KJixLRgK8Td1g4XS64SUD12M00OPfTyJu0vArwoTeipl j5OQ== X-Forwarded-Encrypted: i=1; AJvYcCVOkqaRJ2kizCmZ7cCNuqoU2GV+zugdrA+bSNKPoG65nIbcDAI49RDIZ9oGbsQGm8cF0Og83jgIhg==@kvack.org X-Gm-Message-State: AOJu0YxMb3OZH9ASiyeo2tW3NlamvtsBSsCs/h6aFfSXjMTHZuBhxFqi YfLB4om+iLnRuIhYFrlxZ3C2xaGBoKI5p6K5RXtyDvstAyzYk4kRu0V/0tpGooQ= X-Google-Smtp-Source: AGHT+IHoPlZyTKRFIXDxqY1vxKZ9N2lRuciBVtR3dVasMoQZpZgRn99fcKxS5v1VlmJJEo1cy5cChA== X-Received: by 2002:a05:6a20:2d0a:b0:1d8:ac0b:2f63 with SMTP id adf61e73a8af0-1d9a853aa7amr16243300637.47.1730245460885; Tue, 29 Oct 2024 16:44:20 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-72057921863sm8157643b3a.33.2024.10.29.16.44.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Oct 2024 16:44:20 -0700 (PDT) From: Deepak Gupta Date: Tue, 29 Oct 2024 16:44:02 -0700 Subject: [PATCH v7 02/32] mm: helper `is_shadow_stack_vma` to check shadow stack vma MIME-Version: 1.0 Message-Id: <20241029-v5_user_cfi_series-v7-2-2727ce9936cb@rivosinc.com> References: <20241029-v5_user_cfi_series-v7-0-2727ce9936cb@rivosinc.com> In-Reply-To: <20241029-v5_user_cfi_series-v7-0-2727ce9936cb@rivosinc.com> To: Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Andrew Morton , "Liam R. Howlett" , Vlastimil Babka , Lorenzo Stoakes , Paul Walmsley , Palmer Dabbelt , Albert Ou , Conor Dooley , Rob Herring , Krzysztof Kozlowski , Arnd Bergmann , Christian Brauner , Peter Zijlstra , Oleg Nesterov , Eric Biederman , Kees Cook , Jonathan Corbet , Shuah Khan Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-riscv@lists.infradead.org, devicetree@vger.kernel.org, linux-arch@vger.kernel.org, linux-doc@vger.kernel.org, linux-kselftest@vger.kernel.org, alistair.francis@wdc.com, richard.henderson@linaro.org, jim.shu@sifive.com, andybnac@gmail.com, kito.cheng@sifive.com, charlie@rivosinc.com, atishp@rivosinc.com, evan@rivosinc.com, cleger@rivosinc.com, alexghiti@rivosinc.com, samitolvanen@google.com, broonie@kernel.org, rick.p.edgecombe@intel.com, Deepak Gupta X-Mailer: b4 0.14.0 X-Rspamd-Server: rspam06 X-Rspamd-Queue-Id: 9FFF980006 X-Stat-Signature: ce8cnt3m4ziptbo8pyjb8fjfmdwm9jep X-Rspam-User: X-HE-Tag: 1730245414-593500 X-HE-Meta: U2FsdGVkX1+vtSAjr621+4mbHjZkHoQnaheRhMnSPgJOlGB0hN5m6oM7LbeRkDatRiZNlcD8G6sEUTxnQ75mEXeuVhUs62y0bNVkGZrnyZSll+oieQHujJkMXKUv4Df8nVGpEqJLrhdY8s1S06p6yxv5R0TnfqDYlmay0DTQL5Ir67qDtcwV5vAFNBziILKQbWcaRZlFiAvuaHfkOj1sj4H3WafxeerIB0BvpjA1baaDR6LpRQekMDOIlYmlIC+xEJL1JrkJ/CdfvX6MNJ+wLLcSKmivQKbbVH7dBEGWar18croC7WkA45+HLVLr6vioPIgFNrJNnmAxeT39fFyLO4d3dt2zfrxksX8mNK0xK5+Hz5lamsJdhaPMDKBj5K2GvsImQtTea9GoN1HpKKXl5BmbqjMtpM7waz9iEOHvufyNWuE9qiquGx/ULd82gTrl85zRqggGJKPjMibKPvnaKUYjk81ps7q7sSyuqP6Lg434JUUWSbEptmTdaB1h5qLkOWbasUslUxkSZO4jGr4n6lqasIyM6BBnOo5TUla0vIZpwKUBXlgWNy4SswinkkXoJDjMGolWPCGj50yV3FG4T7Nkaj1RrENTxLdXcTd+53tED2ev0i43sHjn/E3FWmKkGaqCTdWD0eZDm6pC1a0l/HHCRwnvfnnyfbB6PF6vSeS4Fg3FRCH41uqxtBEPR85XY9PrJo8jgX52mCxAE3GtCxidaAWIsgQAof+b5qVklEGqQ5wPehApO1nBTv0trdJF3dXz6l03cIEwal5qJb9QlZGmTzacQ3v6i4aDud2oZQIKfMTtLbFfpkWIe7uSXlZKIY6l0pOZqhnvzcT8WLMG/pE770C1i2UVWQFlqBsYGs99PWY4YhcuvJGMhkXqjgQYM15WxTfC7jpp1czr7ePd/tS3xks8SP/LOi2gIttmsx/ONT0uOKthGcKbEc1MZMIpNQnrXG2b/iZFi4sHM0G 7JzAq2Mm Ct6ROC9WO7c4Vsqk7ulGtKQ0L4uz1apOBQK1xvP6j4jFGjW7Bojbqh3+zbBcZb1BLXhkcGY9zsbQvUEziqZiR2nL/2Sv/R46IOdTw/7vymnjclXblZ9f2b5cOcRMEM1xRNApOKn6Tl8tTPAKBQzMPYg15A04MLlN4j9feTyaJ0vu561Wh56NzIem3JZAoS3wXx/Lr967PX5xDpA/eN0COHHVQJjRLR7QYVFQYo0BeyhBEsQ1rozimTEgikdGQAtkZAW3ncteQQtfkfPWiKmA+0MGGMaWqQA0wqPedqN8Gx/vt7UWoRrOkV2PM/ZP2odhvAyIp5HvgQ6t71pW082welhSTNtKo6n72AB9xIdtY46LR9Dp7jB7Ka2m/chanPB/UM8IvFn0KoBdBUsXY6MBnw4MXK6OQQ3oLeMQDF889mn+eVHwlPs4m92wC6zzNg9oK4G1BvgUcnaSExztKgozUkfsZvpNT72qPrGSo/KnsV5A+sfeISD80kvpS/+j5MnvCcYIMv25TwKwAnyht3HVo4TZs/w== 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: List-Subscribe: List-Unsubscribe: VM_SHADOW_STACK (alias to VM_HIGH_ARCH_5) is used to encode shadow stack VMA on three architectures (x86 shadow stack, arm GCS and RISC-V shadow stack). In case architecture doesn't implement shadow stack, it's VM_NONE Introducing a helper `is_shadow_stack_vma` to determine shadow stack vma or not. Signed-off-by: Deepak Gupta Reviewed-by: Mark Brown --- mm/gup.c | 2 +- mm/mmap.c | 2 +- mm/vma.h | 10 +++++++--- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/mm/gup.c b/mm/gup.c index a82890b46a36..8e6e14179f6c 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1282,7 +1282,7 @@ static int check_vma_flags(struct vm_area_struct *vma, unsigned long gup_flags) !writable_file_mapping_allowed(vma, gup_flags)) return -EFAULT; - if (!(vm_flags & VM_WRITE) || (vm_flags & VM_SHADOW_STACK)) { + if (!(vm_flags & VM_WRITE) || is_shadow_stack_vma(vm_flags)) { if (!(gup_flags & FOLL_FORCE)) return -EFAULT; /* hugetlb does not support FOLL_FORCE|FOLL_WRITE. */ diff --git a/mm/mmap.c b/mm/mmap.c index dd4b35a25aeb..0853e6784069 100644 --- a/mm/mmap.c +++ b/mm/mmap.c @@ -708,7 +708,7 @@ static unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info) */ static inline unsigned long stack_guard_placement(vm_flags_t vm_flags) { - if (vm_flags & VM_SHADOW_STACK) + if (is_shadow_stack_vma(vm_flags)) return PAGE_SIZE; return 0; diff --git a/mm/vma.h b/mm/vma.h index 819f994cf727..0f238dc37231 100644 --- a/mm/vma.h +++ b/mm/vma.h @@ -357,7 +357,7 @@ static inline struct vm_area_struct *vma_prev_limit(struct vma_iterator *vmi, } /* - * These three helpers classifies VMAs for virtual memory accounting. + * These four helpers classifies VMAs for virtual memory accounting. */ /* @@ -368,6 +368,11 @@ static inline bool is_exec_mapping(vm_flags_t flags) return (flags & (VM_EXEC | VM_WRITE | VM_STACK)) == VM_EXEC; } +static inline bool is_shadow_stack_vma(vm_flags_t vm_flags) +{ + return !!(vm_flags & VM_SHADOW_STACK); +} + /* * Stack area (including shadow stacks) * @@ -376,7 +381,7 @@ static inline bool is_exec_mapping(vm_flags_t flags) */ static inline bool is_stack_mapping(vm_flags_t flags) { - return ((flags & VM_STACK) == VM_STACK) || (flags & VM_SHADOW_STACK); + return ((flags & VM_STACK) == VM_STACK) || is_shadow_stack_vma(flags); } /* @@ -387,7 +392,6 @@ static inline bool is_data_mapping(vm_flags_t flags) return (flags & (VM_WRITE | VM_SHARED | VM_STACK)) == VM_WRITE; } - static inline void vma_iter_config(struct vma_iterator *vmi, unsigned long index, unsigned long last) {