From patchwork Tue Jul 12 23:13:15 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: 12915797 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 590AFCCA47F for ; Tue, 12 Jul 2022 23:13:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 826729400DF; Tue, 12 Jul 2022 19:13:29 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 64FF39400DE; Tue, 12 Jul 2022 19:13:29 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4C851940063; Tue, 12 Jul 2022 19:13:29 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 37BEE9400DD for ; Tue, 12 Jul 2022 19:13:29 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 09B5A342FB for ; Tue, 12 Jul 2022 23:13:29 +0000 (UTC) X-FDA: 79680001338.26.066C48E Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by imf03.hostedemail.com (Postfix) with ESMTP id 5CD3420039 for ; Tue, 12 Jul 2022 23:13:28 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1657667608; x=1689203608; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=/mZZ6XVgf+v/LCjFJuOjf/g/7sNGNi+wlPnmFmhLw7o=; b=gNWjpJR296vOepQjQAu1sB5bkf2UjVl4m66kIiiZpZZKSMs5xWCRBZl2 ZwKNXKmra+2tl/kCUtkwsgSQcV6c5nYmftC30ASmxZEYMI6VrKHP67utr ZKfhr+DCX/ZEGoMjrumsaspitJu105unRYeqqpuvU/JWNbcRNwT0AP4VA L5HKxyqwSfIxFCKiNdbv1eGxqiOtpRK/qzzF/+Z/qSDvB/BMt4ix9cjoY qyV8N6+2+fTC8FCDDc+Me4p9dWI95SBUptMnG8eB8b9N8jgPAN+4JBD63 +5d4j+OFdecZv06bJGfJJvmO3ymDpvSd9IG9OPJjL5CwWreGvfVK/BzEw A==; X-IronPort-AV: E=McAfee;i="6400,9594,10406"; a="268101470" X-IronPort-AV: E=Sophos;i="5.92,266,1650956400"; d="scan'208";a="268101470" Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 12 Jul 2022 16:13:25 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.92,266,1650956400"; d="scan'208";a="628074967" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga001.jf.intel.com with ESMTP; 12 Jul 2022 16:13:21 -0700 Received: by black.fi.intel.com (Postfix, from userid 1000) id A8C88F1; Wed, 13 Jul 2022 02:13:29 +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 , Taras Madan , Dmitry Vyukov , "H . J . Lu" , Andi Kleen , Rick Edgecombe , linux-mm@kvack.org, linux-kernel@vger.kernel.org, "Kirill A. Shutemov" Subject: [PATCHv5 00/13] Linear Address Masking enabling Date: Wed, 13 Jul 2022 02:13:15 +0300 Message-Id: <20220712231328.5294-1-kirill.shutemov@linux.intel.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1657667608; a=rsa-sha256; cv=none; b=GMKgS6wlgBhUWeUSDFsGK5LPEwYsZOwak+k7/9sxu/14zhVtb73CBr7k02gE3vCGvdaT5m QTwOSpj2wQj4HNnYznEt2Z+Vja1kr18dY/n1x+6IMRgg6tyHfHvjDheZ/zln1ThSJZ1Icv gASdXqE6msF46QRn4ONVl31uNwoADdA= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=gNWjpJR2; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf03.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.126) 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=1657667608; 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=FIBY2kgEjVfq6S5DBoSfcq0/gQLEEluNS5Ui/f0pnUQ=; b=8Y4EpbLeQtC+5UgGNGyxcI6v6nKep/KgCShzA5mXRJBTj1eQIpYuv1p8xXa4ySZfWAev1K uPhFV3DLEIYRiYj/xqceCrCdjGmNBwYrsRichwWiurZ1hG6eqdJOGUe4olLh+JNmRUp27K 5ThVcxp7gEnA6rktRl7ldWXHtjdCPqc= X-Stat-Signature: oes89wxbh3g4fo3fj6mxcho13i6gg5qj X-Rspamd-Queue-Id: 5CD3420039 Authentication-Results: imf03.hostedemail.com; dkim=pass header.d=intel.com header.s=Intel header.b=gNWjpJR2; dmarc=pass (policy=none) header.from=intel.com; spf=none (imf03.hostedemail.com: domain of kirill.shutemov@linux.intel.com has no SPF policy when checking 134.134.136.126) smtp.mailfrom=kirill.shutemov@linux.intel.com X-Rspam-User: X-Rspamd-Server: rspam10 X-HE-Tag: 1657667608-846111 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. v5: - Do not use switch_mm() in enable_lam_func() - Use mb()/READ_ONCE() pair on LAM enabling; - Add self-test by Weihong Zhang; - Add comments; 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 10. https://cdrdv2.intel.com/v1/dl/getContent/671368 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 Weihong Zhang (5): selftests/x86/lam: Add malloc test cases for linear-address masking selftests/x86/lam: Add mmap and SYSCALL test cases for linear-address masking selftests/x86/lam: Add io_uring test cases for linear-address masking selftests/x86/lam: Add inherit test cases for linear-address masking selftests/x86/lam: Add tests cases for 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 | 6 + arch/x86/include/asm/mmu_context.h | 58 ++ arch/x86/include/asm/processor-flags.h | 2 +- arch/x86/include/asm/tlbflush.h | 36 + 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 | 83 +- arch/x86/kernel/sys_x86_64.c | 5 +- arch/x86/mm/hugetlbpage.c | 6 +- arch/x86/mm/mmap.c | 10 +- arch/x86/mm/tlb.c | 42 +- .../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 +- tools/testing/selftests/x86/Makefile | 2 +- tools/testing/selftests/x86/lam.c | 913 ++++++++++++++++++ virt/kvm/kvm_main.c | 2 +- 53 files changed, 1315 insertions(+), 127 deletions(-) create mode 100644 arch/x86/kernel/proc.c create mode 100644 tools/testing/selftests/x86/lam.c