From patchwork Fri Jun 10 14:35:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Kirill A. Shutemov" X-Patchwork-Id: 12877663 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 54D68CCA47B for ; Fri, 10 Jun 2022 14:35:43 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 22B5E8D00B8; Fri, 10 Jun 2022 10:35:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 0EDC98D00B3; Fri, 10 Jun 2022 10:35:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EB42F8D00B8; Fri, 10 Jun 2022 10:35:37 -0400 (EDT) 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 D5D7F8D00B3 for ; Fri, 10 Jun 2022 10:35:37 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id B2F8D33791 for ; Fri, 10 Jun 2022 14:35:37 +0000 (UTC) X-FDA: 79562574714.12.A7AE136 Received: from mga04.intel.com (mga04.intel.com [192.55.52.120]) by imf09.hostedemail.com (Postfix) with ESMTP id 635E1140065 for ; Fri, 10 Jun 2022 14:35:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1654871736; x=1686407736; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=r1mjNgxw2ZcRVt/bhSb4f5Mjb8Nk4rnJL0ffOUx3ru4=; b=m1sPs4Lt6sO1c1JjCVO4p5LML6oCkWP90KSxWua1EWUm3YjkgR7QnuEo D0XelTP99lD8+9JmhkauHKj5guDmrPTV4cSf79yV9QWC+Vm8wWjacHFr0 VcpcnmoSbbmatmy0xADE93B3rKgs2OkDv+oHyr15pQKJQuQRs7ej3VEK2 s7iUDgzIUzfVNXM+YvfDDXJ+2PRzxVeGeyilVnbC8pEm5ZdOP3yOWW4x3 lqf4gDIPgz8+8Fz8Bwi3ZWGSB0BEQXaljMBEXh0mlMegXuBdR5VumWB5I 2EDdJ7Bzj4aGhLR9RbaXYrkyRFzNoALiMDP5Sdt8Q9krBlO7PyI0jqvvN Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10374"; a="276425802" X-IronPort-AV: E=Sophos;i="5.91,290,1647327600"; d="scan'208";a="276425802" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga104.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 10 Jun 2022 07:35:35 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.91,290,1647327600"; d="scan'208";a="534102921" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 10 Jun 2022 07:35:31 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 5720D60E; Fri, 10 Jun 2022 17:35:30 +0300 (EEST) From: "Kirill A. Shutemov" To: Dave Hansen , Andy Lutomirski , Peter Zijlstra Cc: x86@kernel.org, Kostya Serebryany , Andrey Ryabinin , Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , "H . J . Lu" , Andi Kleen , Rick Edgecombe , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv3 6/8] x86/mm: Provide ARCH_GET_UNTAG_MASK and ARCH_ENABLE_TAGGED_ADDR Date: Fri, 10 Jun 2022 17:35:25 +0300 Message-Id: <20220610143527.22974-7-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220610143527.22974-1-kirill.shutemov@linux.intel.com> References: <20220610143527.22974-1-kirill.shutemov@linux.intel.com> MIME-Version: 1.0 ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1654871737; 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:in-reply-to:references:references:dkim-signature; bh=hS4QR0utwloZmAtaZiJuai5sQstNG1/BKUykgpI58cA=; b=yeLSOEgBtzfuYr/45QRfsTHJxf+KKwmzwuA10c0QtuZ7cremQAxZAxhm/u7ZgGFOpHeerN 7nWt5U0J6XkzgWYWqvCakXs9i4lcNWfQtOSa9Azm0WWdKpzTz5dt8hDthyyhfjnsHoJqgc hLmWm/1qxOY36snbf42SYWTskvBhbH0= ARC-Authentication-Results: i=1; imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=m1sPs4Lt; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf09.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.120) smtp.mailfrom=kirill.shutemov@linux.intel.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1654871737; a=rsa-sha256; cv=none; b=NxBLp7BOveIDI+zkUVg0D839CW9u7Q92qx/Qb18OXnavugK3cRBBva1Cqkr1nF5h1P6aaU 722f7Xj8S6IeQ98Aym15+kjxXY622nYOGDwtikkeXdIkko2jtcFQYh6zhYMALrarYUeUk7 ihcLSvcXqiykkcXUUE4Mum+UU8IyZsk= X-Stat-Signature: w1j9ey7bx9dhb348thazeyypcrnrhf7t X-Rspamd-Queue-Id: 635E1140065 Authentication-Results: imf09.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=m1sPs4Lt; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf09.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.120) smtp.mailfrom=kirill.shutemov@linux.intel.com X-Rspam-User: X-Rspamd-Server: rspam05 X-HE-Tag: 1654871736-663180 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: Add a couple of arch_prctl() handles: - ARCH_ENABLE_TAGGED_ADDR enabled LAM. The argument is required number of tag bits. It is rounded up to the nearest LAM mode that can provide it. For now only LAM_U57 is supported, with 6 tag bits. - ARCH_GET_UNTAG_MASK returns untag mask. It can indicates where tag bits located in the address. Signed-off-by: Kirill A. Shutemov --- arch/x86/include/uapi/asm/prctl.h | 3 +++ arch/x86/kernel/process_64.c | 32 ++++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/uapi/asm/prctl.h b/arch/x86/include/uapi/asm/prctl.h index 500b96e71f18..38164a05c23c 100644 --- a/arch/x86/include/uapi/asm/prctl.h +++ b/arch/x86/include/uapi/asm/prctl.h @@ -20,4 +20,7 @@ #define ARCH_MAP_VDSO_32 0x2002 #define ARCH_MAP_VDSO_64 0x2003 +#define ARCH_GET_UNTAG_MASK 0x4001 +#define ARCH_ENABLE_TAGGED_ADDR 0x4002 + #endif /* _ASM_X86_PRCTL_H */ diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c index 1962008fe743..93c8eba1a66d 100644 --- a/arch/x86/kernel/process_64.c +++ b/arch/x86/kernel/process_64.c @@ -742,6 +742,32 @@ static long prctl_map_vdso(const struct vdso_image *image, unsigned long addr) } #endif +static int prctl_enable_tagged_addr(unsigned long nr_bits) +{ + struct mm_struct *mm = current->mm; + + /* Already enabled? */ + if (mm->context.lam_cr3_mask) + return -EBUSY; + + /* LAM has to be enabled before spawning threads */ + if (get_nr_threads(current) > 1) + return -EBUSY; + + if (!nr_bits) { + return -EINVAL; + } else if (nr_bits <= 6) { + mm->context.lam_cr3_mask = X86_CR3_LAM_U57; + mm->context.untag_mask = ~GENMASK(62, 57); + } else { + return -EINVAL; + } + + /* Update CR3 to get LAM active */ + switch_mm(current->mm, current->mm, current); + return 0; +} + long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2) { int ret = 0; @@ -829,7 +855,11 @@ long do_arch_prctl_64(struct task_struct *task, int option, unsigned long arg2) case ARCH_MAP_VDSO_64: return prctl_map_vdso(&vdso_image_64, arg2); #endif - + case ARCH_GET_UNTAG_MASK: + return put_user(current->mm->context.untag_mask, + (unsigned long __user *)arg2); + case ARCH_ENABLE_TAGGED_ADDR: + return prctl_enable_tagged_addr(arg2); default: ret = -EINVAL; break;