From mboxrd@z Thu Jan 1 00:00:00 1970 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 7F46DC48BF8 for ; Tue, 20 Feb 2024 02:02:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 14E2F6B0074; Mon, 19 Feb 2024 21:02:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0FECB6B0083; Mon, 19 Feb 2024 21:02:29 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EE18D6B0085; Mon, 19 Feb 2024 21:02:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id DE8F66B0082 for ; Mon, 19 Feb 2024 21:02:28 -0500 (EST) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 84805120478 for ; Tue, 20 Feb 2024 02:02:28 +0000 (UTC) X-FDA: 81810532776.09.17E1AD7 Received: from mail-pg1-f172.google.com (mail-pg1-f172.google.com [209.85.215.172]) by imf16.hostedemail.com (Postfix) with ESMTP id A74E518000B for ; Tue, 20 Feb 2024 02:02:26 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=mhABvBWv; spf=pass (imf16.hostedemail.com: domain of thiago.bauermann@linaro.org designates 209.85.215.172 as permitted sender) smtp.mailfrom=thiago.bauermann@linaro.org; dmarc=pass (policy=none) header.from=linaro.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1708394546; 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: in-reply-to:in-reply-to:references:references:dkim-signature; bh=gGuBNyvpaV2ObDTkL/I2kZTcUQ/VEw4s3L6Fk4TZnkY=; b=FXy49WP3KabC5M8sfaLcqi+NeR6I3LDzgqwNRgkY+ClnhByAJsyWkX9D0IyxPucLhed786 mOhfFofRYR1MEbv8pjjeNh/E/HmV/+btuqUKSHqLWe4m/rTFrT6SGHmVslh+5gcYqG6W66 1MWGX2R1tnaBN5fS3bkvAYXQWWxRJ8c= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1708394546; a=rsa-sha256; cv=none; b=ILGcPO1KcK/s8qcIE+wesr57hZbrIJOWn00DWR8GJywoxY2s1i+R8dzfLHVhO4TsyrqgRb 9Ip3RCIhKwHC/3GnsbuNmxe4V/l/oScKfz6/2Q1eHIReCOYAkbcB/b4Hg32du4Fl7XiktW 5at0ZpBS6FP4XSiQQxYABZUo7yft6/E= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=mhABvBWv; spf=pass (imf16.hostedemail.com: domain of thiago.bauermann@linaro.org designates 209.85.215.172 as permitted sender) smtp.mailfrom=thiago.bauermann@linaro.org; dmarc=pass (policy=none) header.from=linaro.org Received: by mail-pg1-f172.google.com with SMTP id 41be03b00d2f7-5ce07cf1e5dso3857038a12.2 for ; Mon, 19 Feb 2024 18:02:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1708394545; x=1708999345; darn=kvack.org; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from :user-agent:references:from:to:cc:subject:date:message-id:reply-to; bh=gGuBNyvpaV2ObDTkL/I2kZTcUQ/VEw4s3L6Fk4TZnkY=; b=mhABvBWvWzjsvQ5X5lf75kNCQm5JUKRcQOnNKPEwgdRf8sd0m8D+Qo0lblRpbB0GKO Z/jt6iWUmLGJJ8jajoJtEYT+QO4hwYMLX25CAJ/Emdx2pdpM9S3cWLDroBOVLV1rcyDC iqU4ehqDN3n9AasY1j3qKIO32EzWEss0vX+6sLUL7Vn6Wnw1P19GhMc1+hZDPF6XGAbv 27baOLrIPlTVzzIjg/8HfLFK61t8rdBGYZ3WROgZDFVBDtHwhCVJTPT1LEBnpwuL/nR/ 1qL07h2AAQZzmZNG9MoP2Rl8s6vi5zLCzzBFMyh7e//8pQZMb8eenrz8M7Tq3Ri5VJ7w xJag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708394545; x=1708999345; h=mime-version:message-id:date:in-reply-to:subject:cc:to:from :user-agent:references:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=gGuBNyvpaV2ObDTkL/I2kZTcUQ/VEw4s3L6Fk4TZnkY=; b=jn7lrPahzxjj40puLsjHrBOg6Xno6P76DTMB/LK2Lz0KdfqFD27txHVEHKSleLVYL2 7EqXkP6iOztlFc/gko5Q6uAX1ymCDniTpIgPt9TdgKemRSXhJ8gncgIouP9ra1OWJUWd 566D81gqDr3LDdpSJKxDtz32RxoeQHSu6uH+WyBTLLSLork3CAnyFhLwQzlOjslJ9oFi PTsrc7agryETkbNvK/4k9e4qXaCyCehLRY+KoREQwq6e4MLi1YntOuUbh93DCa7QoSil 6ckySuneSMYPAYDCwVcLj28CHC0/vca4a0dcqad3mLGldiFtcQECYZbY1ao2zhSpcfNG Z8Xg== X-Forwarded-Encrypted: i=1; AJvYcCUIqsOkDAScC8mdYI76qGq2V2rl4+5qPiwwMu3OJ6rrD8E4eI8+AHmmGUNTuDmDFkMx4Yi4KyCuILRhBIR4fmcgcP8= X-Gm-Message-State: AOJu0YyMUKHOG8zoMI3KYRbohHn8qFwEsqxSEEqVAVp6IC10fZhGU3bp x1sIb5dfW6iF2V5nYpxlDvIoXE4/qyH4hw7ivdiEm+dBikk8toJL4E1szoePwmQ= X-Google-Smtp-Source: AGHT+IF+n0ZLGWj8WZb6XJ83RSBfvZlmkL20FWmLTPsaWPlBrtsNjb413QMtpYGMBguWkAb2CMTxlg== X-Received: by 2002:a05:6a20:354c:b0:19c:8d73:721e with SMTP id f12-20020a056a20354c00b0019c8d73721emr9670649pze.36.1708394545367; Mon, 19 Feb 2024 18:02:25 -0800 (PST) Received: from localhost ([2804:14d:7e39:8470:a328:9cae:8aed:4821]) by smtp.gmail.com with ESMTPSA id s8-20020a17090a948800b00299354e8828sm5949155pjo.51.2024.02.19.18.02.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Feb 2024 18:02:24 -0800 (PST) References: <20240203-arm64-gcs-v8-0-c9fec77673ef@kernel.org> <20240203-arm64-gcs-v8-20-c9fec77673ef@kernel.org> User-agent: mu4e 1.10.8; emacs 29.1 From: Thiago Jung Bauermann To: Mark Brown Cc: Catalin Marinas , Will Deacon , Jonathan Corbet , Andrew Morton , Marc Zyngier , Oliver Upton , James Morse , Suzuki K Poulose , Arnd Bergmann , Oleg Nesterov , Eric Biederman , Kees Cook , Shuah Khan , "Rick P. Edgecombe" , Deepak Gupta , Ard Biesheuvel , Szabolcs Nagy , "H.J. Lu" , Paul Walmsley , Palmer Dabbelt , Albert Ou , Florian Weimer , Christian Brauner , linux-arm-kernel@lists.infradead.org, linux-doc@vger.kernel.org, kvmarm@lists.linux.dev, linux-fsdevel@vger.kernel.org, linux-arch@vger.kernel.org, linux-mm@kvack.org, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org Subject: Re: [PATCH v8 20/38] arm64/gcs: Ensure that new threads have a GCS In-reply-to: <20240203-arm64-gcs-v8-20-c9fec77673ef@kernel.org> Date: Mon, 19 Feb 2024 23:02:22 -0300 Message-ID: <874je399ld.fsf@linaro.org> MIME-Version: 1.0 Content-Type: text/plain X-Stat-Signature: b1a4gtg7fk1duk4p4fhzb8rmi5tocy3g X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: A74E518000B X-Rspam-User: X-HE-Tag: 1708394546-502584 X-HE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SfTeoWS/nie5RB0VcYNsHTjNIAO1Lmb4TmusZe+eL7pUlvAqxcNLCKH7lvPixBH5QVtcdTlTYkbejiMeyjKcM9htgUHcy/fKxSyII+uXy/OcoZIniJKO8eeZIdoW0TfYfivYePqp4+m77NmYMOeZKMBi/ZjMjNECvkGIucSvN3isg8UrYDU6248m13LDSkgtIXB1/X0cJ+1rCQJFdr09dS9W2xiL3L+fSvpNshYdnwePPdXVJVgmLxwk15FGC4TfDKuOCFCLQdCLitr+ZFjFPKLN+gZhmGFeLG2etxgCggMW0KrS7uDg5QW9806E5x1M5wkuD5gN1gGeDOIv9F8l34EjiXDes12wFJna6p1JosxW0U/gsjFLcO8HdkVVtacAbNsScTWTiQ== 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: Mark Brown writes: > When a new thread is created by a thread with GCS enabled the GCS needs > to be specified along with the regular stack. clone3() has been > extended to support this case, allowing userspace to explicitly specify > the size and location of the GCS. The specified GCS must have a valid > GCS token at the top of the stack, as though userspace were pivoting to > the new GCS. This will be consumed on use. At present we do not > atomically consume the token, this will be addressed in a future > revision. > > Unfortunately plain clone() is not extensible and existing clone3() > users will not specify a stack so all existing code would be broken if > we mandated specifying the stack explicitly. For compatibility with > these cases and also x86 (which did not initially implement clone3() > support for shadow stacks) if no GCS is specified we will allocate one > thread so when a thread is created which has GCS enabled allocate one ~~~~~~ This "thread" seems extraneous in the sentence. Remove it? > for it. We follow the extensively discussed x86 implementation and > allocate min(RLIMIT_STACK, 4G). Since the GCS only stores the call Isn't it min(RLIMIT_STACK/2, 2G), as seen in gcs_size()? If true, this size should also be fixed in Documentation/arch/arm64/gcs.rst. > stack and not any variables this should be more than sufficient for most > applications. > > GCSs allocated via this mechanism then it will be freed when the thread > exits, those explicitly configured by the user will not. I'm not sure I parsed this sentence correctly. Is it missing an "If" at the beginning? > +unsigned long gcs_alloc_thread_stack(struct task_struct *tsk, > + const struct kernel_clone_args *args) > +{ > + unsigned long addr, size, gcspr_el0; > + > + /* If the user specified a GCS use it. */ > + if (args->shadow_stack_size) { > + if (!system_supports_gcs()) > + return (unsigned long)ERR_PTR(-EINVAL); > + > + addr = args->shadow_stack; > + size = args->shadow_stack_size; > + > + /* > + * There should be a token, there might be an end of > + * stack marker. > + */ > + gcspr_el0 = addr + size - (2 * sizeof(u64)); > + if (!gcs_consume_token(tsk, gcspr_el0)) { Should this code validate the end of stack marker? Or doesn't it matter whether the marker is correct or not? > + gcspr_el0 += sizeof(u64); > + if (!gcs_consume_token(tsk, gcspr_el0)) > + return (unsigned long)ERR_PTR(-EINVAL); > + } > + > + /* Userspace is responsible for unmapping */ > + tsk->thread.gcspr_el0 = gcspr_el0 + sizeof(u64); > + } else { -- Thiago