From patchwork Fri Dec 22 23:51:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Deepak Gupta X-Patchwork-Id: 13503825 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 1AA18C46CD2 for ; Fri, 22 Dec 2023 23:55:03 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 43A156B009C; Fri, 22 Dec 2023 18:55:03 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 3EA258D0002; Fri, 22 Dec 2023 18:55:03 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 2B1886B009E; Fri, 22 Dec 2023 18:55:03 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 175C26B009C for ; Fri, 22 Dec 2023 18:55:03 -0500 (EST) Received: from smtpin24.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id CE12EA05D1 for ; Fri, 22 Dec 2023 23:55:02 +0000 (UTC) X-FDA: 81596112444.24.0295D0F Received: from mail-ot1-f47.google.com (mail-ot1-f47.google.com [209.85.210.47]) by imf16.hostedemail.com (Postfix) with ESMTP id 2C988180004 for ; Fri, 22 Dec 2023 23:55:00 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=MSrEwhYN; spf=pass (imf16.hostedemail.com: domain of debug@rivosinc.com designates 209.85.210.47 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=1703289301; 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-transfer-encoding:content-transfer-encoding: in-reply-to:references:dkim-signature; bh=jovKxsj0YGOzwwNQclPyLUNNHjkrdGN438RuH3dRR2A=; b=NxmeqdjqPQmwXb2O5XI9sFSzJUQa5KOMmsKpD8XIyYSdyUT3zm+BRiGh4lYXrdAlWV6uFS ZnDlcBRvPZ8pimyOm6NalvZJH6oNy5x3YRSsqq7ug+Lu0Qg8hIozkmMFY3iWN+4l/SXURv TaTbD/ewCIXycBvU4oeLwBOk9UN1L4w= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=rivosinc-com.20230601.gappssmtp.com header.s=20230601 header.b=MSrEwhYN; spf=pass (imf16.hostedemail.com: domain of debug@rivosinc.com designates 209.85.210.47 as permitted sender) smtp.mailfrom=debug@rivosinc.com; dmarc=none ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703289301; a=rsa-sha256; cv=none; b=hMkPL+7S3hK60ZPwVOwrq+mqgivTO2y9cGYyrT0MxI/nLptV72J9gah02bVbBbdXI1ciYA k/7XD3ADoiV9t25TF2yY1+LlHMGkq4Cd0K0egREjLEvl8E3l0ocMoMKPQTV8lvZugvUlmP I+Msr+/k50bdDBqyKk+6wkGNJu/0lNU= Received: by mail-ot1-f47.google.com with SMTP id 46e09a7af769-6da2e360861so1414806a34.1 for ; Fri, 22 Dec 2023 15:55:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20230601.gappssmtp.com; s=20230601; t=1703289300; x=1703894100; darn=kvack.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=jovKxsj0YGOzwwNQclPyLUNNHjkrdGN438RuH3dRR2A=; b=MSrEwhYNjOJZp8OSnZQrh3iPX/O+uD10+bJyKuvLsID9DBRdk1/50YNUIZwTlrXU0W 3+RguL/dHZRXBgedMpmIMwvNGyVv0gaaikWG72fKaBG5aeO636BFNFrhq8bCPPD5w+pT Pq4KLMGSLW6MF6dBOrQndNnML9ddzowpIRDjKOFjem2e8JYOwJd99dpYprhA/jpL60Lb /r2+MiI8R2YlABiI5uQJ/V9Y4nCRQPW1/dw1mp/6FnLSCSJ4Lnn2Av1/dOk7ktZSn4L9 HlzDLle92YnkxkGbkoUzaZ9e16gwavXUGlnyBWGdcLuYxD4AYAMXCyeYq1R9cSM1JeRt S7fg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1703289300; x=1703894100; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=jovKxsj0YGOzwwNQclPyLUNNHjkrdGN438RuH3dRR2A=; b=A1tYBGvSW638RNU1DGIoP/stLrF6foDxySSqVAtjwD9AjGKqgMEWRkIxZBvgpEvRtJ m9VW184tRZg7oZgrtYyN+piIxFuwA8bGTQTl8cKVzyVHmmvV5kxpR3AnvDAZ+d9rGic2 vyNZyjPEBI8y8RlZoKC3FGBaEPi5nEJgjH3IZBntaiFMvjHFuyaMpe8v20j+NotIX9Ps ZCP/q2Akh4PjZyJa0sfDKjfbgPGUnv415uqeUomHWl7u2giVcUvPj9NdYTWwj4qGocuw tS14u/+hkj00PziKGVXTiqZFXWBz00nZ5oB59aUEP2mptaJqdVcnl9eBtgRIjHD3KbJ/ AoJw== X-Gm-Message-State: AOJu0Yy9vfs0qbPrYsEdF+5gvXkWLXPpqRgQbRx9Hd9NxiJbbIhx/WZs vXptXmH9LkxrICfbvjjJW+TyEVbchGwjMVpoeVtdGNX6QQo= X-Google-Smtp-Source: AGHT+IE4rFqSsXLWy2zn3NPZ8X3v1i6lWs26Lx4B22AXqvN9zx3xCPAcYyy9LfQcQBKoJdPCZEMkeQ== X-Received: by 2002:a05:6830:450f:b0:6db:b9db:4393 with SMTP id i15-20020a056830450f00b006dbb9db4393mr1209126otv.0.1703289300272; Fri, 22 Dec 2023 15:55:00 -0800 (PST) Received: from debug.ba.rivosinc.com ([64.71.180.162]) by smtp.gmail.com with ESMTPSA id q65-20020a4a4b44000000b005944c7f6bb6sm249999ooa.29.2023.12.22.15.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 22 Dec 2023 15:54:59 -0800 (PST) From: Deepak Gupta To: rick.p.edgecombe@intel.com, broonie@kernel.org Cc: Deepak Gupta , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: [PATCH v1] mm: abstract shadow stack vma behind arch_is_shadow_stack_vma Date: Fri, 22 Dec 2023 15:51:04 -0800 Message-ID: <20231222235248.576482-1-debug@rivosinc.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-Rspamd-Queue-Id: 2C988180004 X-Rspam-User: X-Stat-Signature: 41kryxewb699bpf3keaiahj9k7c8w3i8 X-Rspamd-Server: rspam01 X-HE-Tag: 1703289300-766904 X-HE-Meta: U2FsdGVkX1+7XDOFrZWbwaaY64ue1CeOpC6A8vr71ns38rBas1g0NNNjtgL8l+fNww++gVYWvmoySrVvvZbaabRkHyGNyvzTdIVls0v0V3sjuSK0SMNTaObvZlh7G0p2wA/2soCxxdyH1a3qnWH3hpJfSTgan9K6TEF57zhQbpvmitVXxVDS8DB7yDZGvt5j6PQOsH+AC0Kdej1gRNVJNH3uQ/Dx6sCQDI1nelp8UBlutFUDZngSXWDkwN+iFZbla1U9/C9h2qIMrKwa9Qmmxm6bt23sasdYi56bXb9LrNjN9tZ1PRnbXCQijpyRxygj3AjgCH9P5Z5akCIcQKjoIOhdpaqjj68qbSTeqBBDoqHfpK0al3aPm6Lrate6Z28ILV6th1L8ydUFY32fpeUCA+oR8L5kOFxWH0fvqAc/vj3BDY+0nlL0giBlFUqxl45YpEiqLrCV7ukz+wJ+ZeiETIr5E3ovPg0LDmfQ+OIlEECckiipqJndDouhHAQmAx17k6BvSrUWB34SCBbeZ9Zg/GSAR+MYa0RtyqEhkdaYkMzV/8L/A3fjwCB9VLz366JAryapkcC/YvufjxOyZwpQFvS2uNW10HgRKLHTUZi+ow2cUQDddJBMNN1CTnaXRQzTU/3mUbFRq5TI6mlYBSlY4jQE866LSuj2fB6h0w7fu3FwbVynKRBlaui1/U4pL/+IbwKRBlO8mWl+Q0NxkT7M38QYT4psJtK0vRl2RcKKeJNmPUgU8C5RKIOi5utlASs5Ceqa5fV/TcRCe91qQ7rJOrw0p3DWhSkHNcB2iHO/0SvJTjKrEy+0l6v6kB4DheX1gx0EkkX7juzIqyMOrbvA6nJIiufHDKjrP6GW2+y6UE286tT1lieTQ9Z+ULA6sevKYPwfNdNNMv90Zdj2xCBo+RWkqOdMRJ+5wq4ezFgOgo/vlA0Vj0XI4efuMVIlZ2i8NQZvZQ1SbWiigEmaerC Q9/89yIL LIbfVvhusJBQ4iUKYAnImOxvmVSscARm/rc75ymh9OwmKsYLR8YCXn3Gky4ghDps0ia0Tat4QhWBG1h1coGYKP21XPSuuVT66B622SyEYGT72etl2dvhinJZCRDi3TqORuMlc1xarpuVju7EPSTiwf4bOsIPTAMhUkyic9fSi28aJgSZfApUztBdibl/7+19yos2PKVdxt4XLQYQ= X-Bogosity: Ham, tests=bogofilter, spamicity=0.000614, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: x86 has used VM_SHADOW_STACK (alias to VM_HIGH_ARCH_5) to encode shadow stack VMA. VM_SHADOW_STACK is thus not possible on 32bit. Some arches may need a way to encode shadow stack on 32bit and 64bit both and they may encode this information differently in VMAs. This patch changes checks of VM_SHADOW_STACK flag in generic code to call to a function `arch_is_shadow_stack_vma` which will return true if arch supports shadow stack and vma is shadow stack else stub returns false. Signed-off-by: Deepak Gupta --- include/linux/mm.h | 15 ++++++++++++++- mm/gup.c | 2 +- mm/internal.h | 2 +- 3 files changed, 16 insertions(+), 3 deletions(-) diff --git a/include/linux/mm.h b/include/linux/mm.h index 418d26608ece..9586e7bbd2aa 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -352,8 +352,21 @@ extern unsigned int kobjsize(const void *objp); * for more details on the guard size. */ # define VM_SHADOW_STACK VM_HIGH_ARCH_5 + +static inline bool arch_is_shadow_stack_vma(vm_flags_t vm_flags) +{ + return (vm_flags & VM_SHADOW_STACK) ? true : false; +} + #else + # define VM_SHADOW_STACK VM_NONE + +static inline bool arch_is_shadow_stack_vma(vm_flags_t vm_flags) +{ + return false; +} + #endif #if defined(CONFIG_X86) @@ -3452,7 +3465,7 @@ static inline unsigned long stack_guard_start_gap(struct vm_area_struct *vma) return stack_guard_gap; /* See reasoning around the VM_SHADOW_STACK definition */ - if (vma->vm_flags & VM_SHADOW_STACK) + if (arch_is_shadow_stack_vma(vma->vm_flags)) return PAGE_SIZE; return 0; diff --git a/mm/gup.c b/mm/gup.c index 231711efa390..dcc2aa079163 100644 --- a/mm/gup.c +++ b/mm/gup.c @@ -1051,7 +1051,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) || arch_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/internal.h b/mm/internal.h index b61034bd50f5..05a6b47c3ca1 100644 --- a/mm/internal.h +++ b/mm/internal.h @@ -572,7 +572,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) || arch_is_shadow_stack_vma(flags); } /*