From patchwork Mon Nov 11 20:53:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13871339 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 C2102D3ABF5 for ; Mon, 11 Nov 2024 20:54:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 54F596B0082; Mon, 11 Nov 2024 15:54:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 4D7E46B009B; Mon, 11 Nov 2024 15:54:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 305C86B00A6; Mon, 11 Nov 2024 15:54:03 -0500 (EST) 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 0620F6B0082 for ; Mon, 11 Nov 2024 15:54:03 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id ADCAD121AD9 for ; Mon, 11 Nov 2024 20:54:02 +0000 (UTC) X-FDA: 82775013468.17.19BC942 Received: from mail-pj1-f52.google.com (mail-pj1-f52.google.com [209.85.216.52]) by imf18.hostedemail.com (Postfix) with ESMTP id A49931C0010 for ; Mon, 11 Nov 2024 20:53:42 +0000 (UTC) Authentication-Results: imf18.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=oX3+3LmW; spf=pass (imf18.hostedemail.com: domain of debug@rivosinc.com designates 209.85.216.52 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=1731358353; 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=/atH3Dmc2hDWuHIRnNBwkfWUhbP1w3P23HyX8egA5iY=; b=62jH+EjZ6ABBFSeTu43bkSNZd0jkw86Pxbz6PV8N7hwdt5U7u2Dz6m1UcQSZMG/vVgzZ4M 9rUzuCV7vAKP4NTs7YcPhxiE/hlaiEGSY6OyV41XOgvRDS3vqWTnsqyantjA50CO+lenRK qReaHCfPMk616D3auPMgySjiwJBWbK8= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1731358353; a=rsa-sha256; cv=none; b=4t60Cz/fhlQgtrrHblPSxRnQkOMFmLpgM5zbRFwO/jnSsLZL7eZvWpMGFGdpzcOLg4usF1 uS7846ayiFtumcvvVVcvEUp+0f0vPWgUtU8hyh64x17vGawT5MwYwvkAgbnrTYqHsIw3Zs 3usSX/j3VjAGkuUh0lmqQnjPRhMRSzo= ARC-Authentication-Results: i=1; imf18.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=oX3+3LmW; spf=pass (imf18.hostedemail.com: domain of debug@rivosinc.com designates 209.85.216.52 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none Received: by mail-pj1-f52.google.com with SMTP id 98e67ed59e1d1-2e2c6bc4840so3927830a91.2 for ; Mon, 11 Nov 2024 12:54:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1731358439; x=1731963239; 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=/atH3Dmc2hDWuHIRnNBwkfWUhbP1w3P23HyX8egA5iY=; b=oX3+3LmWo4X1r2AYtTleRJYnr/7h/WRZ3TfyuzYX2+Ke0SIIk4VyXgicQJ9Shu+QEz X/o5B5ga5CldLHFQmpmVurDa1qo00FzlWjFL2dVXpktGtMwr4ULyD2fM8DxFveWGBzPH 4dLYsAFQl6QxOg6vWLFY56XOWixxTYS3YkLo1dLwE+fwGqwVM3oaJds6+o5piaK2zDlv NjczMI3cDWGZnM8r+lLJ9HI8RYQAWo7s1z6CxJJHCnaeN6/cmQH+8rQOTyepaxUxwS0J Mu04CEEv2ICZZveOfYPPCQYigJxi6T9pRqke7e9vUdy/xqrUSEGWK2JTXGaJl9vZ4ANV Dlmg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731358439; x=1731963239; 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=/atH3Dmc2hDWuHIRnNBwkfWUhbP1w3P23HyX8egA5iY=; b=UsFpmGvAWWwC2pWnoCTJBtTNaFCwuSqgSibIblfMCfez5afxEp3tTmB3ZRvJdaXg8/ XV/tx0wLKu4Wn6c/HTrjV0lDTfrGQUjXQVodfzUbbX+wVdDV5YL4qMmfigaRcHq1+6lX 2ZwUMAkXVNuoUKNpzuQDW6g4r/bbXDcbWOrdf51CnwmHcSzfZ8vt4Pc9OixH8JzJWzQk j49nZnJbWgcD8in3xEy15DslU2y6ZKBrb8J+JDtZRykEBW4f8FwHqu/njQn56sQGhVdf KlQlFTvHw+/OASQzcps57AetbrBFto5vfjSPsD9ia2s70AYbraUEAZYYSrBbp3v8zP61 sXJA== X-Forwarded-Encrypted: i=1; AJvYcCUueAOo96GnI5TO4L0GdlRuHgu1uvVtNhTjatGM8/PcyMERHpO5+eYlzPeJBciJMVLJb7q16b69BA==@kvack.org X-Gm-Message-State: AOJu0YzxtArewRrspHXdviP7QKf3oVCQnHrmu2Yzhhfqs4LIb49/Bd5/ 07ZoIcn510IxdZweL1yE6C8j1uopGUyH9JqxCjRfo6ELFtH6hv5T2SBtdoKV2zI= X-Google-Smtp-Source: AGHT+IEvbaDX9G6RBqut4iScbl/I53KZSOyAqnYCopkb1nPpVHZJcEx6PnWjjFsFphBR/XrDfiSPvQ== X-Received: by 2002:a17:90b:2e07:b0:2e2:bd32:f60 with SMTP id 98e67ed59e1d1-2e9b1780a4bmr18569491a91.32.1731358439483; Mon, 11 Nov 2024 12:53:59 -0800 (PST) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 98e67ed59e1d1-2e9a5fd1534sm9059974a91.42.2024.11.11.12.53.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Nov 2024 12:53:59 -0800 (PST) From: Deepak Gupta Date: Mon, 11 Nov 2024 12:53:47 -0800 Subject: [PATCH v8 02/29] mm: helper `is_shadow_stack_vma` to check shadow stack vma MIME-Version: 1.0 Message-Id: <20241111-v5_user_cfi_series-v8-2-dce14aa30207@rivosinc.com> References: <20241111-v5_user_cfi_series-v8-0-dce14aa30207@rivosinc.com> In-Reply-To: <20241111-v5_user_cfi_series-v8-0-dce14aa30207@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: rspam10 X-Stat-Signature: 1hfy48qt1xhfunr9fmh5mzu9f9nbc16q X-Rspamd-Queue-Id: A49931C0010 X-Rspam-User: X-HE-Tag: 1731358422-192927 X-HE-Meta: U2FsdGVkX1+Jtx3oRQxlKZ+xa/g5woRjA4OtTEKSeVX88QLFMS0AzCbaDD1iOp8G/HnG5HowVcdKWH9L8N8rrMhHfpCbjxC6BlwxsyM6nweSZakAkCv7ODSLTc4Xlcx0GM0whczH3gQpF6g27PQQ8Z8FQjBMHPZ9OYf4137dlvcZ56wT+8HcdGh2I7orawyhXKgLPUGE3YRXt/o2kTSSey5axQ5CJVoS645LqXbfDwQMNCbAghVAIoYeMkWZXyv6cQfBKUd4wlyc2r/MknhBjpmaCUexKwEjFlls9qWDlwmpKubZn5PYM8LxnjnulIg+OOva+BmVdkJpLAUQgVJfzMXvS+Ku297r85DCbhCOQjORNBtqsHcx+sewNzTyi+rITMgSHirUJ6UvyskWAmaXPgm3Foi16rf+SbUG0pJq4tmLKUAxo44h564xyhxGpsF4hGJ03/BezPhViYYphhv0LleXZnEsieFSoHQXvMxqYQaTJ2oFLhuU7+a5fbjuWdO5KMjkNebHRPdVWpX5wZpwubRViF5RorWLSyTY0DPDB8RI2XHGWCOlnEJNRMuqI9nGLEqeJfzGS06jKSfmlRidcg65qsOQYVflc0f7ZJeRZ7E/4FmeWnGukxbEQ1JNQEnH8s36By+ewR4AFVKDRjn4ICbeNQuWAuUEBkgwvfqoFhmT8qJeiNVmPlvRAGcqvnN9fWHa0/0noFV/EhesZN+9/X5iTNtpz8WFYAQlUjhansqpeMPjWg1tT44pl1B4T3Tbs+JuVfLG3hkvOabc+L9m0eQ/91hxeOJ3dvsgheXV51i0Rb6JXtccLTAIIJLKV0KZmpaV2c1zPCFoEfwi3g8wOyWGL+DV+YzjPt8ffvK2rAXaOAViMSuILAfJMLGvW8kL3LMMCqHnkjSdApI6x+MIEp49oBWUeEpMOI9hu8p88mMRf8WCS8JLFT6EssVKjy9vK4PTq9rybFv5RzH8nTn wdFVz+Y4 L49fhPhrY8QwZ1VcfUK0YoxeTEc5HiywA7ETbPq1bsw6IN4mtXXagkh9LZS0Cx4WEl7lDYnocfCaKZKtqc5WeinuLBDgvDOyRc2ixUbpnNf6W6GOMydq5MJU7QpxxDl6w7RSyqmIm/eY0pQYnJN0vYMu7V4l+7xOYlOfa/E24hI5mLgTUpCAF9rYXXJ5U2zy7wvzzTXVBhS1gKcP/octUg89PGXRgAGeCCcCR5ii652ra6aVdGK5JoTXTTxZU8jl3ntR/ArVieFeVggsShthCKAiGScOP9+hH6nOfrAhE2qhiosd8t2skafmhNFcOfYOcJqyjE1oVQ+XH1yOeaqWVQx4cAqL0vtoXGceA7YCvzlwUTNLbQBXlE3JrcZa/KKsLbUAra6KbkjpJoIWImJ+/rhr2mlif2rcjINcGlARNcMi8RWH7EO/kPz2SLecFnIA/425BUeQWbprvPf7SSyVpo8qOdZx3c7JyCusqxdWfKouuRzaCP0rVp+a2y5Thbr8a5FDaTEy434B5iNze5xzM8qDVFA== 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 9c0fb43064b5..f17573469c42 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) {