From patchwork Wed Jun 22 16:22:22 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: 12891137 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 9EB18C433EF for ; Wed, 22 Jun 2022 16:23:08 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id DB9C08E00C6; Wed, 22 Jun 2022 12:23:07 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id D69F08E00C5; Wed, 22 Jun 2022 12:23:07 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id C0ADD8E00C6; Wed, 22 Jun 2022 12:23:07 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id AC2818E00AB for ; Wed, 22 Jun 2022 12:23:07 -0400 (EDT) Received: from smtpin18.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 8053120CC0 for ; Wed, 22 Jun 2022 16:23:07 +0000 (UTC) X-FDA: 79606391214.18.92D57DA Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by imf22.hostedemail.com (Postfix) with ESMTP id E3EC6C00BE for ; Wed, 22 Jun 2022 16:23:01 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1655914982; x=1687450982; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=fAxSfMkPQOft5QNGEOKWIg4HNu6sOXze7SH9g6M0vDc=; b=LFBmfYWFM9WYJm6khfPbGEd7ThyznGLXcIJmSxsDVZXJNi4dGKTiYA7u X72XIb83QYiMkwpopawWpVMxDZIjPrK+SMvMwFwFhRwCWUf6A4Vbio5pM CptS1h0gO3ROexErJIxUDZz2ROSr+sq4gnyEZW1GHzgLB2ogT7AwvLHHh id2HjkqVUI+XG2+4fWe0YU7p2vACKU+d2jT3Ys+iwO6dUnUeVz65/CD4U qmfbxCyCfHeg6FPFKIhcuXorv1ecCZUzu10l3uBTZpyczXNRFbw9aE6w+ 6U6YUKj5Gjzq3/Pi0dq1Kl0UuP880m1du9NxaVq9zjSviNZpgrOAMu7dQ Q==; X-IronPort-AV: E=McAfee;i="6400,9594,10386"; a="280512212" X-IronPort-AV: E=Sophos;i="5.92,212,1650956400"; d="scan'208";a="280512212" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 22 Jun 2022 09:22:41 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,212,1650956400"; d="scan'208";a="620974438" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga001.jf.intel.com with ESMTP; 22 Jun 2022 09:22:38 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id 1FCFB109; Wed, 22 Jun 2022 19:22:43 +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: [PATCHv4 0/8] Linear Address Masking enabling Date: Wed, 22 Jun 2022 19:22:22 +0300 Message-Id: <20220622162230.83474-1-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 ARC-Authentication-Results: i=1; imf22.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=LFBmfYWF; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf22.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.115) smtp.mailfrom=kirill.shutemov@linux.intel.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1655914987; 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=u6Kakt1rjvEmh3/HJaVPixjARtcI4V8qylBRDShtirk=; b=4wxqQcK7g8+BHq6R39daiVo/cUiuADHX35i3Owaae0zcVi3NHr7rf8VIyBMDarj3h5ERnf zFWTL/Nsca6X/eW28MYP9tQOONa6OU3GJvbWQRVINZ6XLKXbGV7jf4N86EKPf7gXTA70GS S35eHzeyDCUkjT4iw52gv5NmPoLoI6A= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1655914987; a=rsa-sha256; cv=none; b=VCa74+RDIEQAm5NCey36SAPKwTb75SoyCshWPz28I1CjsfpqJdkY8An8OP8WIrTXgdd4dE VudFbXE75Kv+GD2Wx9Ff2isyHRWIQylJZhWTqUvrAELPuOffUi6vAG9ahbQzPWtPjJA+zS RfwvtOUJXTvYRe6Iq+iWALR1DzXQqUI= X-Rspamd-Server: rspam11 X-Rspamd-Queue-Id: E3EC6C00BE X-Rspam-User: Authentication-Results: imf22.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=LFBmfYWF; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf22.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 192.55.52.115) smtp.mailfrom=kirill.shutemov@linux.intel.com X-Stat-Signature: 1kcs1xfpfwz8ogqfa8hjyqp6imcura1s X-HE-Tag: 1655914981-252356 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: Linear Address Masking[1] (LAM) modifies the checking that is applied to 64-bit linear addresses, allowing software to use of the untranslated address bits for metadata. The patchset brings support for LAM for userspace addresses. LAM_U48 enabling is controversial since it competes for bits with 5-level paging. Its enabling isolated into an optional last patch that can be applied at maintainer's discretion. Please review and consider applying. v4: - Fix untagged_addr() for LAM_U48; - Remove no-threads restriction on LAM enabling; - Fix mm_struct access from /proc/$PID/arch_status - Fix LAM handling in initialize_tlbstate_and_flush() - Pack tlb_state better; - Comments and commit messages; v3: - Rebased onto v5.19-rc1 - Per-process enabling; - API overhaul (again); - Avoid branches and costly computations in the fast path; - LAM_U48 is in optional patch. v2: - Rebased onto v5.18-rc1 - New arch_prctl(2)-based API - Expose status of LAM (or other thread features) in /proc/$PID/arch_status [1] ISE, Chapter 14. https://software.intel.com/content/dam/develop/external/us/en/documents-tps/architecture-instruction-set-extensions-programming-reference.pdf Kirill A. Shutemov (8): x86/mm: Fix CR3_ADDR_MASK x86: CPUID and CR3/CR4 flags for Linear Address Masking mm: Pass down mm_struct to untagged_addr() x86/mm: Handle LAM on context switch x86/uaccess: Provide untagged_addr() and remove tags before address check x86/mm: Provide ARCH_GET_UNTAG_MASK and ARCH_ENABLE_TAGGED_ADDR x86: Expose untagging mask in /proc/$PID/arch_status x86/mm: Extend LAM to support to LAM_U48 arch/arm64/include/asm/memory.h | 4 +- arch/arm64/include/asm/signal.h | 2 +- arch/arm64/include/asm/uaccess.h | 4 +- arch/arm64/kernel/hw_breakpoint.c | 2 +- arch/arm64/kernel/traps.c | 4 +- arch/arm64/mm/fault.c | 10 +-- arch/sparc/include/asm/pgtable_64.h | 2 +- arch/sparc/include/asm/uaccess_64.h | 2 + arch/x86/include/asm/cpufeatures.h | 1 + arch/x86/include/asm/elf.h | 3 +- arch/x86/include/asm/mmu.h | 2 + arch/x86/include/asm/mmu_context.h | 58 ++++++++++++++ arch/x86/include/asm/processor-flags.h | 2 +- arch/x86/include/asm/tlbflush.h | 4 + arch/x86/include/asm/uaccess.h | 42 +++++++++- arch/x86/include/uapi/asm/prctl.h | 3 + arch/x86/include/uapi/asm/processor-flags.h | 6 ++ arch/x86/kernel/Makefile | 2 + arch/x86/kernel/fpu/xstate.c | 47 ----------- arch/x86/kernel/proc.c | 60 ++++++++++++++ arch/x86/kernel/process.c | 3 + arch/x86/kernel/process_64.c | 78 ++++++++++++++++++- arch/x86/kernel/sys_x86_64.c | 5 +- arch/x86/mm/hugetlbpage.c | 6 +- arch/x86/mm/mmap.c | 9 ++- arch/x86/mm/tlb.c | 68 ++++++++++++---- .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c | 2 +- drivers/gpu/drm/amd/amdgpu/amdgpu_gem.c | 2 +- drivers/gpu/drm/radeon/radeon_gem.c | 2 +- drivers/infiniband/hw/mlx4/mr.c | 2 +- drivers/media/common/videobuf2/frame_vector.c | 2 +- drivers/media/v4l2-core/videobuf-dma-contig.c | 2 +- .../staging/media/atomisp/pci/hmm/hmm_bo.c | 2 +- drivers/tee/tee_shm.c | 2 +- drivers/vfio/vfio_iommu_type1.c | 2 +- fs/proc/task_mmu.c | 2 +- include/linux/mm.h | 11 --- include/linux/uaccess.h | 15 ++++ lib/strncpy_from_user.c | 2 +- lib/strnlen_user.c | 2 +- mm/gup.c | 6 +- mm/madvise.c | 2 +- mm/mempolicy.c | 6 +- mm/migrate.c | 2 +- mm/mincore.c | 2 +- mm/mlock.c | 4 +- mm/mmap.c | 2 +- mm/mprotect.c | 2 +- mm/mremap.c | 2 +- mm/msync.c | 2 +- virt/kvm/kvm_main.c | 2 +- 51 files changed, 385 insertions(+), 126 deletions(-) create mode 100644 arch/x86/kernel/proc.c