From patchwork Fri Oct 11 00:32:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13831616 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 4D3FAD24463 for ; Fri, 11 Oct 2024 00:32:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E10386B0083; Thu, 10 Oct 2024 20:32:26 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D9CC66B0088; Thu, 10 Oct 2024 20:32:26 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BEBC46B0089; Thu, 10 Oct 2024 20:32:26 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A4F986B0083 for ; Thu, 10 Oct 2024 20:32:26 -0400 (EDT) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 2D9851C4335 for ; Fri, 11 Oct 2024 00:32:22 +0000 (UTC) X-FDA: 82659445050.28.C773D4A Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) by imf04.hostedemail.com (Postfix) with ESMTP id B9A3640006 for ; Fri, 11 Oct 2024 00:32:21 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=WHKFlhjk; dmarc=none; spf=pass (imf04.hostedemail.com: domain of debug@rivosinc.com designates 209.85.215.174 as permitted sender) smtp.mailfrom=debug@rivosinc.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1728606700; a=rsa-sha256; cv=none; b=sL0jtT/pmEwIDVH+KszOJEdP17zb4/k0w4pyh4efVA5+YoEcW/jZTeSfOAlYmvDQnqCNM1 Cri7A+syBhwH34A49kJaBI+esHB/LHkmeSi1e1Gty9ws9SMrkCeD81QqI74U4KWM15txpy TSY5X/b/Bg1eL5n5qNT8+Oxb6wegrSA= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=WHKFlhjk; dmarc=none; spf=pass (imf04.hostedemail.com: domain of debug@rivosinc.com designates 209.85.215.174 as permitted sender) smtp.mailfrom=debug@rivosinc.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1728606700; 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=OwXMBbOWCv06xRC7kuAtikxfL3CuNBKfrSTtPkKqEqk=; b=6zHtNwSuXCmRgTxmh4+rI6D1YyZHCqHegmsxPyvcbTOWY7EylNiMZ9XzarkgDTHXQqZ44U iVOEUE8W9ieZyANqTh9mS8peuhR446QnYIsTf6vbx+ZMfnjjtFUer80oyg1SrF7aoOjE5O DqI4OsjdsAIjcwIqWgucpWKzOBEJwTM= Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-7e9ad969a4fso1083309a12.3 for ; Thu, 10 Oct 2024 17:32:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1728606743; x=1729211543; 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=OwXMBbOWCv06xRC7kuAtikxfL3CuNBKfrSTtPkKqEqk=; b=WHKFlhjk9MCwPwEBC8szytJwplD15ORXUv4N3PfhzqPMxLEb9zfZ9POb2MX3j4oZS6 qydJTdNEcx31uJ/Ho5tCJNPgav5dQAkJUNCNTR6QtdWIQgPKIMYCN2TTTBZ/M0m+wPLf /s9IHwIqD9YeYfW1i5HrWNYZ0PlHJqzze+XL9lyFQ/DoAJvY6ZG/bll/VRO03jFdHXyd vnZcIgFxPkitmRKJkpO1eSuhsMZSYsVSqF5yy4VUlUl+VSCzzvb2OH6bBKfS6/hgI0QX IZvPMtjsS0ZEyaGnEzG81OsGhlJxPU/dE/YY4YtRbf0CJ0wNmmNeTy50Y1sL21nMmO/P uz1w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728606743; x=1729211543; 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=OwXMBbOWCv06xRC7kuAtikxfL3CuNBKfrSTtPkKqEqk=; b=Ig1NTZTl2Pu4GE1JqxhZH9bhm0OkuJzaK8ZIYB6x9XgAmchZhllI3g0uWx7koS+uEP ESymJdhw3T9Qj0DpQntR4cbFlE893Dlinhwi3FWdEQ1hen+ptCikSDt8LxpbDLFy8nCZ NWHPtt9DRJLUNemP5gqGTSt/KSL/uf3WVXNPWCfYWl8LmKeiVr1WYMhTdeTXe8uYYDw0 yQgUGFXhzO7ne0+oHkD8J6cXU+27YWQ/oRkPsDA+3U1TQR0L/GwTJYYv5DcBctWmDKTy PZQwUAWL0VA48WvOhKBjME+zNNwpTykprhHOTimDcEDZM7Nv+H2GZz3QMnpPy3/1KRbN 7IgA== X-Forwarded-Encrypted: i=1; AJvYcCV8j4ENFixLDj19ZJ3BXTAoL9leOt3ThsBRA0ZV8mNPK2IL9haLmqApdTF0ieszicdN/FICQpZOig==@kvack.org X-Gm-Message-State: AOJu0Yzi2JM00NrBfqSoa0pnWXhAoS0VvbuIiV8dQ+qY2JnE7I+MJU/o lficKt7kxxHczQ1eske0kTEK/jodBRAKnm5T0+n4qFyLQPQCPDGP3ToblJ5WJeQ= X-Google-Smtp-Source: AGHT+IHY7zq/7mSxHwSor2mUQedwvphBbojX3qVK+YSVQyO1pCVsaX3K1rupXosm1zq+SyZ3LBJdSg== X-Received: by 2002:a05:6a20:c997:b0:1d2:e8d8:dd46 with SMTP id adf61e73a8af0-1d8bcf23701mr1509996637.15.1728606743039; Thu, 10 Oct 2024 17:32:23 -0700 (PDT) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id 41be03b00d2f7-7ea4496b1afsm1545600a12.94.2024.10.10.17.32.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Oct 2024 17:32:22 -0700 (PDT) From: Deepak Gupta Date: Thu, 10 Oct 2024 17:32:04 -0700 Subject: [PATCH RFC/RFT 2/3] mm: helper `is_shadow_stack_vma` to check shadow stack vma MIME-Version: 1.0 Message-Id: <20241010-shstk_converge-v1-2-631beca676e7@rivosinc.com> References: <20241010-shstk_converge-v1-0-631beca676e7@rivosinc.com> In-Reply-To: <20241010-shstk_converge-v1-0-631beca676e7@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 , Arnd Bergmann Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, linux-mm@kvack.org, linux-arch@vger.kernel.org, Rick Edgecombe , Mark Brown , Deepak Gupta X-Mailer: b4 0.14.0 X-Rspam-User: X-Rspamd-Queue-Id: B9A3640006 X-Rspamd-Server: rspam01 X-Stat-Signature: eadgmirm7ztm1t7u5d1usrpqrmy9s9gx X-HE-Tag: 1728606741-920304 X-HE-Meta: U2FsdGVkX1/uCmtXOSw5z1glhy9dwtksgY6wbKPCjU+MLPHfYB9M4zkU0HlWqtqX3PWPho2XQ6D0nYhnzYj6z6S1cTx9nABkGBOO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0TShhRI2osjEAVLP1qdJwkqpPwyfqQU5yHy5uBLQaiQDJYLPUnML1nQF5drwlsImwMZAnqnuY7UWkvT5skRSjtNMVnlwhNO0f/Prqp4FXkZEYwvOIlX0iRjCld97f+PiZIeMmRw6EL9fjSHWQ2BocI9BCV1x2AmS9MDD/F0fWjaDUgBVgP+jKBC2LAftAXJieR7oor7kdiSUBQCDlwymJ880YOLqL7ojiP0xbZG9rxljX8eNyInjOWcr6DsIKhL4DSpm15/9TMQ31yipUYr4UQfAK+QVXTdXx7KFEY7X0IuEHr4DntBod5SvxHYfaIXq5GVL7pXEt82TYCdubF76AtQ5QyfqgEbzUGEpGjGRzzt2iFa4J4SlXV4Hs= 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 --- mm/gup.c | 2 +- mm/vma.h | 10 +++++++--- 2 files changed, 8 insertions(+), 4 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/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) {