From patchwork Tue Feb 4 17:59:09 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Vagin X-Patchwork-Id: 11365115 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 624491398 for ; Tue, 4 Feb 2020 17:59:41 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3F1A021741 for ; Tue, 4 Feb 2020 17:59:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="oc8AiR1h"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="cZvdvgC6" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3F1A021741 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=AczG0jnRV589ali8rJfwDN6FRDQmirPQ6A5a+GNnKsk=; b=oc8AiR1h6zhM0l+yLzYIvylIZz 3czYJhl5iFCVDBpPFQTPNqi9+ufP7AuPw3Dulslgj65ZtzGhG+yx2RAp3EFP3RnIVi/sNI1ScWTgH O3iIBf8IjdW/ln7X4lce7gcagATWGbL+du+6ApQERPJCO0HpTQZ99muoePuQbUYj1NADG6bRXWlyv x1d4fGND38VnsAaX3jEyqns9cBA0XrWriWYklyZYAw/ZWQATK/eT4UqoBhHdlq6tTPxsBSJKIGze+ ejiUmvT7FWTs6sYeHpplLHy5F2N4qQBJL+ocQhOIwZa/REq6KyE02y/o/E7wZrHl2dSsF3MmJmOaj hAWvieQQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iz2U4-0007hv-C4; Tue, 04 Feb 2020 17:59:36 +0000 Received: from mail-pj1-x1041.google.com ([2607:f8b0:4864:20::1041]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iz2Tt-0007Wf-76 for linux-arm-kernel@lists.infradead.org; Tue, 04 Feb 2020 17:59:26 +0000 Received: by mail-pj1-x1041.google.com with SMTP id ep11so1712787pjb.2 for ; Tue, 04 Feb 2020 09:59:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=nfh22yuIBMeQ3kvIydY8ilzEcSZOCdGdBZ/eBSsIN/Q=; b=cZvdvgC6JY1X2WLdvXp4m3GQ+VLpqwAwdJRWr3OHt+mDbjcYTLQTWTP5LOy0VNI2J9 GsZ6G3+eROIlZRwhBOKiZei6C4Y24+XLK6CnTNAVCElkoqyA2ndnkIHuaKxR5/ropUFE xt/v49ir5Air6MKMQtxu4OQjBsAEyLuuoJ13Kqn2lLoqUsdLN06QPqAg6XtiWVju/5RL RNfC7XniMD6tlt3sN0WYRTWli2s1MXpEmWdYaM6cWc23RpF4AnDSJYjuDGMa7mr17ylN /cQ8tR7Ax4Ee2JmrlRO+Tu4hKx/Pb4zCeLXk+x3gUjQ26RcxPCXJDcDbRpqSqACDBw23 1igQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=nfh22yuIBMeQ3kvIydY8ilzEcSZOCdGdBZ/eBSsIN/Q=; b=r/XvtNMRx6rNB3mCQC8FUhsyEtgXtpQvGAt2P5b+oZcUq625xojw1NXhcGiDblkQoT AlRvR1dLhCaRB9Fc4tI17tTcUtiZDjnHeqhx3bdLdYh1KNJVEh4E8InQte3BJtxuQRyV kOQ0wW9nxdzJySrOtnR38SsImjd2kIEhaSuhSAcBVQbLVg+2xYzLV+cgYP4jlz8PNMRe QyWa8j3kccpRbEnpWwGvut3axkH9l/fWnkNmMya7zB/tSyCDRrMaIHGdOiVXyBgD/oEy nUF6kCuxs6djh4Fckmdybq7Ot1T3X6UE3nKbANW6/hw0fOql0mvMfDxBw/T34L/Yicfs WRkA== X-Gm-Message-State: APjAAAVW/9HoCTu5oA+vC04wzUJi4hASwS9i88ToBefAxZHhGLMyhJI6 4k7Lxfw2GtABZKOWq1xWqvQ= X-Google-Smtp-Source: APXvYqw9azuHvBSMLyzc/8cqmPByqTFaxmhbhNKiyzp8wI/JEy0MYOpijPSV6ICe+k2TNK2BwWVxAQ== X-Received: by 2002:a17:90a:9c1:: with SMTP id 59mr305035pjo.65.1580839164471; Tue, 04 Feb 2020 09:59:24 -0800 (PST) Received: from localhost.localdomain ([2620:0:1008:fd00:25a6:3140:768c:a64d]) by smtp.gmail.com with ESMTPSA id d73sm25414465pfd.109.2020.02.04.09.59.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 09:59:23 -0800 (PST) From: Andrei Vagin To: Vincenzo Frascino Subject: [PATCH 1/5] arm64/vdso: use the fault callback to map vvar pages Date: Tue, 4 Feb 2020 09:59:09 -0800 Message-Id: <20200204175913.74901-2-avagin@gmail.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200204175913.74901-1-avagin@gmail.com> References: <20200204175913.74901-1-avagin@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200204_095925_266253_8ED73314 X-CRM114-Status: GOOD ( 15.18 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [avagin[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Gleixner , Andrei Vagin , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Dmitry Safonov MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This is required to support time namespaces where a time namespace data page is different for each namespace. Signed-off-by: Andrei Vagin --- arch/arm64/kernel/vdso.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index 354b11e27c07..c4b4758eaf0b 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c @@ -114,28 +114,32 @@ static int __vdso_init(enum arch_vdso_type arch_index) PAGE_SHIFT; /* Allocate the vDSO pagelist, plus a page for the data. */ - vdso_pagelist = kcalloc(vdso_lookup[arch_index].vdso_pages + 1, + vdso_pagelist = kcalloc(vdso_lookup[arch_index].vdso_pages, sizeof(struct page *), GFP_KERNEL); if (vdso_pagelist == NULL) return -ENOMEM; - /* Grab the vDSO data page. */ - vdso_pagelist[0] = phys_to_page(__pa_symbol(vdso_data)); - - /* Grab the vDSO code pages. */ pfn = sym_to_pfn(vdso_lookup[arch_index].vdso_code_start); for (i = 0; i < vdso_lookup[arch_index].vdso_pages; i++) - vdso_pagelist[i + 1] = pfn_to_page(pfn + i); + vdso_pagelist[i] = pfn_to_page(pfn + i); - vdso_lookup[arch_index].dm->pages = &vdso_pagelist[0]; - vdso_lookup[arch_index].cm->pages = &vdso_pagelist[1]; + vdso_lookup[arch_index].cm->pages = vdso_pagelist; return 0; } +static vm_fault_t vvar_fault(const struct vm_special_mapping *sm, + struct vm_area_struct *vma, struct vm_fault *vmf) +{ + if (vmf->pgoff == 0) + return vmf_insert_pfn(vma, vmf->address, + sym_to_pfn(vdso_data)); + return VM_FAULT_SIGBUS; +} + static int __setup_additional_pages(enum arch_vdso_type arch_index, struct mm_struct *mm, struct linux_binprm *bprm, @@ -155,7 +159,7 @@ static int __setup_additional_pages(enum arch_vdso_type arch_index, } ret = _install_special_mapping(mm, vdso_base, PAGE_SIZE, - VM_READ|VM_MAYREAD, + VM_READ|VM_MAYREAD|VM_PFNMAP, vdso_lookup[arch_index].dm); if (IS_ERR(ret)) goto up_fail; @@ -206,6 +210,8 @@ static int aarch32_vdso_mremap(const struct vm_special_mapping *sm, #define C_SIGPAGE 1 #define C_PAGES (C_SIGPAGE + 1) #endif /* CONFIG_COMPAT_VDSO */ +static vm_fault_t vvar_fault(const struct vm_special_mapping *sm, + struct vm_area_struct *vma, struct vm_fault *vmf); static struct page *aarch32_vdso_pages[C_PAGES] __ro_after_init; static struct vm_special_mapping aarch32_vdso_spec[C_PAGES] = { { @@ -215,6 +221,7 @@ static struct vm_special_mapping aarch32_vdso_spec[C_PAGES] = { #ifdef CONFIG_COMPAT_VDSO { .name = "[vvar]", + .fault = vvar_fault, }, { .name = "[vdso]", @@ -396,6 +403,7 @@ static int vdso_mremap(const struct vm_special_mapping *sm, static struct vm_special_mapping vdso_spec[A_PAGES] __ro_after_init = { { .name = "[vvar]", + .fault = vvar_fault, }, { .name = "[vdso]", From patchwork Tue Feb 4 17:59:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Vagin X-Patchwork-Id: 11365117 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4A2CB1398 for ; Tue, 4 Feb 2020 17:59:55 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 27C9221741 for ; Tue, 4 Feb 2020 17:59:55 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="XFj9RTCU"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="f2D9vquN" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 27C9221741 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=P/VY1UIQIl9dBzT4y31VkKMNbcAXJPo2rwr6SdVJJA4=; b=XFj9RTCUI23eiPrSL8Kso4yl0/ y0CAl3FKwVyOcj+DfRsBCbtDyZgkLvn6A5pYYgRW5LIFEB9HoPW1XATz9NZQbBO7tnGegAvu4JZeO RCOFZeaRkhKVFiQ0AhsaRvHgWS9/12UA5UL1IzFFUUYgNhyl5SryULMo2ervqbTuQk5Jrxagqg28q 1pmHBYuaAguxGrKmbVdtiqeg/Ew/9Qt1PeVu0yjydFhWtW2pe7ehzlgNRCsq66GLgWPL6tP20XSXj 7Ujc0PpB9crincYXXR1Ong41lvSF8NrTk3NBbx9fQE4cmsdKnPvuLERlfjXE/hHUCNtEstFGXSsRM 4qMJxuEw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iz2UK-0007x6-IN; Tue, 04 Feb 2020 17:59:52 +0000 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iz2Tu-0007X0-NW for linux-arm-kernel@lists.infradead.org; Tue, 04 Feb 2020 17:59:28 +0000 Received: by mail-pl1-x642.google.com with SMTP id d9so7566911plo.11 for ; Tue, 04 Feb 2020 09:59:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=7Yq7DlP+MKcqgZ3wsjfCTguAnbXfIOKWROJvqxl0zoQ=; b=f2D9vquNX5DsXU5g1xuVZpuFt9sTH4kFwsIAWNMIjnxU4QKnljJhk9oBZx4jGkTBER L2lJn5kkTuXGKXMRxq1F7++Ge53ax+ujxh1P/CQHoT6Aa+x4zGIEGrGLIPiu3zV1MqqD IjnegYIZYOF9cHDeb5aYhnyZve7ybwBeT/ofK1QB2aM6Myt/7mATzhWcfhbwZm3rIOki By3TJYdZqvQBqPIxasrGkhNYd1py0kxsUijkqJ7xpQxmX8ygFycQ6L4uKslE7Jdc9pFV YQbTzpCfLKBG+UqTQqsBPCWELHqafw+dikqc9/SOsCJ9KcCXPR8uD9mRUrZxG41OinTK PT0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=7Yq7DlP+MKcqgZ3wsjfCTguAnbXfIOKWROJvqxl0zoQ=; b=AoDr2hdJWQ09lXPcENN0ZseKJE7SMtREp/rxbHc9J5PQ7vscF/xoFC8cuaKvNqidme 58DRxxxHNlGexwlJpFcPCQRxzvXdTkDIpHWrco3SLjjP+LDD6ga9TZ+hR5p/5a4LrXgz c9lBLE+BrCPiNcRV//7Fn+E9z1JcbcT/WWbwZzoZ9+9klrlXeXnz5Xgy2UeVAxPi766H rRgfikcFrLexj2xS+R1J+fe24D55FzELTGh4ONiVD7sIvUp6AcmbX2OEthe3nDSh409j U2qwf/b6LfP3i1T42gMG3CBVh49VEB4nYtqg2KxhDB9agY0Buj65+2Oy5kH8ordUWVGs WyNw== X-Gm-Message-State: APjAAAXsOQUnJ0wSMFbFQ/zYuyy03f5xgsarWDjsWxuNWwawPKAdnIRt zYheZpyCO/1HxekEQadNXt7HryEHwV8= X-Google-Smtp-Source: APXvYqzZ3hxUy2pgjYnm+E5KKwzAk92s+OrDRAm4xSLtLf0eFvS2+/aSnkqwr9PMcUcTGFMIy3Fd9A== X-Received: by 2002:a17:90a:1697:: with SMTP id o23mr363140pja.62.1580839165382; Tue, 04 Feb 2020 09:59:25 -0800 (PST) Received: from localhost.localdomain ([2620:0:1008:fd00:25a6:3140:768c:a64d]) by smtp.gmail.com with ESMTPSA id d73sm25414465pfd.109.2020.02.04.09.59.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 09:59:24 -0800 (PST) From: Andrei Vagin To: Vincenzo Frascino Subject: [PATCH 2/5] arm64/vdso: Zap vvar pages when switching to a time namespace Date: Tue, 4 Feb 2020 09:59:10 -0800 Message-Id: <20200204175913.74901-3-avagin@gmail.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200204175913.74901-1-avagin@gmail.com> References: <20200204175913.74901-1-avagin@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200204_095926_794339_0D332BC2 X-CRM114-Status: GOOD ( 13.21 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:642 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [avagin[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Gleixner , Andrei Vagin , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Dmitry Safonov MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The VVAR page layout depends on whether a task belongs to the root or non-root time namespace. Whenever a task changes its namespace, the VVAR page tables are cleared and then they will be re-faulted with a corresponding layout. Signed-off-by: Andrei Vagin --- arch/arm64/kernel/vdso.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index c4b4758eaf0b..5ef808ddf08c 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c @@ -131,6 +131,38 @@ static int __vdso_init(enum arch_vdso_type arch_index) return 0; } +#ifdef CONFIG_TIME_NS +/* + * The vvar page layout depends on whether a task belongs to the root or + * non-root time namespace. Whenever a task changes its namespace, the VVAR + * page tables are cleared and then they will re-faulted with a + * corresponding layout. + * See also the comment near timens_setup_vdso_data() for details. + */ +int vdso_join_timens(struct task_struct *task, struct time_namespace *ns) +{ + struct mm_struct *mm = task->mm; + struct vm_area_struct *vma; + + if (down_write_killable(&mm->mmap_sem)) + return -EINTR; + + for (vma = mm->mmap; vma; vma = vma->vm_next) { + unsigned long size = vma->vm_end - vma->vm_start; + + if (vma_is_special_mapping(vma, vdso_lookup[ARM64_VDSO].dm)) + zap_page_range(vma, vma->vm_start, size); +#ifdef CONFIG_COMPAT_VDSO + if (vma_is_special_mapping(vma, vdso_lookup[ARM64_VDSO32].dm)) + zap_page_range(vma, vma->vm_start, size); +#endif + } + + up_write(&mm->mmap_sem); + return 0; +} +#endif + static vm_fault_t vvar_fault(const struct vm_special_mapping *sm, struct vm_area_struct *vma, struct vm_fault *vmf) { From patchwork Tue Feb 4 17:59:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Vagin X-Patchwork-Id: 11365119 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 333AF92A for ; Tue, 4 Feb 2020 18:00:15 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0F7CC2084E for ; Tue, 4 Feb 2020 18:00:15 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="LInMt6dc"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="qPyKceqZ" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0F7CC2084E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=lrcyhhBvsDhw85gv6OORJIqGQh4rKsJIeU4aC7HJz34=; b=LInMt6dc/Bs4qN+c86iMWaygTv pIHYZV2l/bTz1OkJTKzha8MO1OMZwt41gtyT2+FKc7amrW4Tjg+nFfUET7hFDUSaa38BvZBjsHHJi 1BzoOgeUosyg1bXSoSgIKt78eoAPGs/v2KkLfk67u8M9aZMsel8+7pSUuabRrwLg7fYXf9VzOIcc6 Q/C6dCmQSD6F5sh34sCfLB1K8Y7P+qArS4DGp98qNcIym9tmz2uAIfR406jVC8jHzL4e3BlVTMlZe 7yH5WSG3ZwkbB88NZBBYrjLJb+gtND+flddDGGMR3j+3bMpzuQfmfv3WrvcQDgbzT6MPregKEsZ7H sMWGFQMA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iz2Ue-0000nF-1r; Tue, 04 Feb 2020 18:00:12 +0000 Received: from mail-pg1-x544.google.com ([2607:f8b0:4864:20::544]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iz2Tv-0007Yg-Oi for linux-arm-kernel@lists.infradead.org; Tue, 04 Feb 2020 17:59:30 +0000 Received: by mail-pg1-x544.google.com with SMTP id l24so10035816pgk.2 for ; Tue, 04 Feb 2020 09:59:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=jzwpyaAi9qfvtDcphiGn84RH5NYgJbTyN+92eOI3fxI=; b=qPyKceqZYfzBGk1eYDxatw3fSM0UvHz5LIwlqPA2eA1hiNDR1pi5SUexK8zNyoT4s7 YNq/b0BwXOmzaaMTcvGZ8lq6LH2SuSWSQuGZ1xoU7XI5cCP8u4EUu2PLxkZwIO6r/xUC i9NFkxFqtW+2zbRZdt9aw5ljceJq5VomxXUt2R0uZqFuR1RoO5lAhfcmhW5WnVOfOjTM cw8lGa1s3m3DvGPfd/I9C5EW8/qj8rkEYkzPsLB70xIyvllFRXztQajnK1wCoCA67Xcn bIN7iDtq2P2EEu0i6JheCkwZQxAiKtluH69JFSLYPMf5GnBKPlhyghXwMNzxN5oE+4pD 95vg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=jzwpyaAi9qfvtDcphiGn84RH5NYgJbTyN+92eOI3fxI=; b=rQSdT9ZY+SieX/Yd5bQRng70reJzVRrqKnO8eFW5dEi5PwVQ1ED7fk+fgSBY/8iLKx eD86Pn8AwoVA09w5izRnHzO0ZfOELRQ2WZ2QoLS5Lqwpto4lD3STYg91n1R0tiLtVO0N +/SweLGPlN+Qged0nzXrFp5PZs3HJauMN2ViaXt03GamnuMt/m4oGVcmXi1yiSPPAYWm p3Ho29vgx55CXj04xlbPSdpM5KovdZ2VQyCNa6C/BprO+hu3RIiXy+lGsrr679AN3QAA Kd1xhijkKi5DyMc4FdPYT1pyadVjxb/jJXDP5aMGYd7Jo1rv9XZ6j4+56cDIoUyaO/SW PmvA== X-Gm-Message-State: APjAAAUThk//LT+NKflaEzI7aUlXKZezCcULb93AzEn1XUwQl2n0bzPu bK2UbgOwR3C/AsPaguMu7Rs= X-Google-Smtp-Source: APXvYqzLRIHbMcFv3zpUfHLC4QFg9lmDdBwhQXR0HUgudWEYxHZ1sND6lAY9NEjCev3yCwB5BWL08w== X-Received: by 2002:a63:4b24:: with SMTP id y36mr32051434pga.176.1580839166926; Tue, 04 Feb 2020 09:59:26 -0800 (PST) Received: from localhost.localdomain ([2620:0:1008:fd00:25a6:3140:768c:a64d]) by smtp.gmail.com with ESMTPSA id d73sm25414465pfd.109.2020.02.04.09.59.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 09:59:25 -0800 (PST) From: Andrei Vagin To: Vincenzo Frascino Subject: [PATCH 3/5] arm64/vdso: Add time napespace page Date: Tue, 4 Feb 2020 09:59:11 -0800 Message-Id: <20200204175913.74901-4-avagin@gmail.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200204175913.74901-1-avagin@gmail.com> References: <20200204175913.74901-1-avagin@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200204_095927_861306_75F11043 X-CRM114-Status: GOOD ( 20.29 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:544 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [avagin[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Gleixner , Andrei Vagin , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Dmitry Safonov MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Allocate the time namespace page among VVAR pages. Provide __arch_get_timens_vdso_data() helper for VDSO code to get the code-relative position of VVARs on that special page. If a task belongs to a time namespace then the VVAR page which contains the system wide VDSO data is replaced with a namespace specific page which has the same layout as the VVAR page. That page has vdso_data->seq set to 1 to enforce the slow path and vdso_data->clock_mode set to VCLOCK_TIMENS to enforce the time namespace handling path. The extra check in the case that vdso_data->seq is odd, e.g. a concurrent update of the VDSO data is in progress, is not really affecting regular tasks which are not part of a time namespace as the task is spin waiting for the update to finish and vdso_data->seq to become even again. If a time namespace task hits that code path, it invokes the corresponding time getter function which retrieves the real VVAR page, reads host time and then adds the offset for the requested clock which is stored in the special VVAR page. Signed-off-by: Andrei Vagin --- arch/arm64/Kconfig | 1 + .../arm64/include/asm/vdso/compat_gettimeofday.h | 11 +++++++++++ arch/arm64/include/asm/vdso/gettimeofday.h | 8 ++++++++ arch/arm64/kernel/vdso.c | 16 +++++++++++++--- arch/arm64/kernel/vdso/vdso.lds.S | 3 ++- arch/arm64/kernel/vdso32/vdso.lds.S | 3 ++- include/vdso/datapage.h | 1 + 7 files changed, 38 insertions(+), 5 deletions(-) diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index e688dfad0b72..a671c2e36e5f 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -109,6 +109,7 @@ config ARM64 select GENERIC_STRNLEN_USER select GENERIC_TIME_VSYSCALL select GENERIC_GETTIMEOFDAY + select GENERIC_VDSO_TIME_NS select HANDLE_DOMAIN_IRQ select HARDIRQS_SW_RESEND select HAVE_PCI diff --git a/arch/arm64/include/asm/vdso/compat_gettimeofday.h b/arch/arm64/include/asm/vdso/compat_gettimeofday.h index 537b1e695365..30a674f598c7 100644 --- a/arch/arm64/include/asm/vdso/compat_gettimeofday.h +++ b/arch/arm64/include/asm/vdso/compat_gettimeofday.h @@ -161,6 +161,17 @@ static __always_inline const struct vdso_data *__arch_get_vdso_data(void) return ret; } +#ifdef CONFIG_TIME_NS +static __always_inline const struct vdso_data *__arch_get_timens_vdso_data(void) +{ + const struct vdso_data *ret; + + asm volatile("mov %0, %1" : "=r"(ret) : "r"(_timens_data)); + + return ret; +} +#endif + #endif /* !__ASSEMBLY__ */ #endif /* __ASM_VDSO_GETTIMEOFDAY_H */ diff --git a/arch/arm64/include/asm/vdso/gettimeofday.h b/arch/arm64/include/asm/vdso/gettimeofday.h index b08f476b72b4..aa38e80dfbc4 100644 --- a/arch/arm64/include/asm/vdso/gettimeofday.h +++ b/arch/arm64/include/asm/vdso/gettimeofday.h @@ -98,6 +98,14 @@ const struct vdso_data *__arch_get_vdso_data(void) return _vdso_data; } +#ifdef CONFIG_TIME_NS +static __always_inline +const struct vdso_data *__arch_get_timens_vdso_data(void) +{ + return _timens_data; +} +#endif + #endif /* !__ASSEMBLY__ */ #endif /* __ASM_VDSO_GETTIMEOFDAY_H */ diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index 5ef808ddf08c..bc93e26ae485 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c @@ -46,6 +46,10 @@ enum arch_vdso_type { #define VDSO_TYPES (ARM64_VDSO + 1) #endif /* CONFIG_COMPAT_VDSO */ +#define VVAR_DATA_PAGE_OFFSET 0 +#define VVAR_TIMENS_PAGE_OFFSET 1 +#define VVAR_NR_PAGES 2 + struct __vdso_abi { const char *name; const char *vdso_code_start; @@ -81,6 +85,12 @@ static union { } vdso_data_store __page_aligned_data; struct vdso_data *vdso_data = vdso_data_store.data; + +struct vdso_data *arch_get_vdso_data(void *vvar_page) +{ + return (struct vdso_data *)(vvar_page); +} + static int __vdso_remap(enum arch_vdso_type arch_index, const struct vm_special_mapping *sm, struct vm_area_struct *new_vma) @@ -182,7 +192,7 @@ static int __setup_additional_pages(enum arch_vdso_type arch_index, vdso_text_len = vdso_lookup[arch_index].vdso_pages << PAGE_SHIFT; /* Be sure to map the data page */ - vdso_mapping_len = vdso_text_len + PAGE_SIZE; + vdso_mapping_len = vdso_text_len + VVAR_NR_PAGES * PAGE_SIZE; vdso_base = get_unmapped_area(NULL, 0, vdso_mapping_len, 0, 0); if (IS_ERR_VALUE(vdso_base)) { @@ -190,13 +200,13 @@ static int __setup_additional_pages(enum arch_vdso_type arch_index, goto up_fail; } - ret = _install_special_mapping(mm, vdso_base, PAGE_SIZE, + ret = _install_special_mapping(mm, vdso_base, VVAR_NR_PAGES * PAGE_SIZE, VM_READ|VM_MAYREAD|VM_PFNMAP, vdso_lookup[arch_index].dm); if (IS_ERR(ret)) goto up_fail; - vdso_base += PAGE_SIZE; + vdso_base += VVAR_NR_PAGES * PAGE_SIZE; mm->context.vdso = (void *)vdso_base; ret = _install_special_mapping(mm, vdso_base, vdso_text_len, VM_READ|VM_EXEC| diff --git a/arch/arm64/kernel/vdso/vdso.lds.S b/arch/arm64/kernel/vdso/vdso.lds.S index 7ad2d3a0cd48..a90b7d14e990 100644 --- a/arch/arm64/kernel/vdso/vdso.lds.S +++ b/arch/arm64/kernel/vdso/vdso.lds.S @@ -17,7 +17,8 @@ OUTPUT_ARCH(aarch64) SECTIONS { - PROVIDE(_vdso_data = . - PAGE_SIZE); + PROVIDE(_vdso_data = . - 2 * PAGE_SIZE); + PROVIDE(_timens_data = _vdso_data + PAGE_SIZE); . = VDSO_LBASE + SIZEOF_HEADERS; .hash : { *(.hash) } :text diff --git a/arch/arm64/kernel/vdso32/vdso.lds.S b/arch/arm64/kernel/vdso32/vdso.lds.S index a3944927eaeb..3e432b536e53 100644 --- a/arch/arm64/kernel/vdso32/vdso.lds.S +++ b/arch/arm64/kernel/vdso32/vdso.lds.S @@ -17,7 +17,8 @@ OUTPUT_ARCH(arm) SECTIONS { - PROVIDE_HIDDEN(_vdso_data = . - PAGE_SIZE); + PROVIDE_HIDDEN(_vdso_data = . - 2 * PAGE_SIZE); + PROVIDE_HIDDEN(_timens_data = _vdso_data + PAGE_SIZE); . = VDSO_LBASE + SIZEOF_HEADERS; .hash : { *(.hash) } :text diff --git a/include/vdso/datapage.h b/include/vdso/datapage.h index c5f347cc5e55..57eec6caca69 100644 --- a/include/vdso/datapage.h +++ b/include/vdso/datapage.h @@ -100,6 +100,7 @@ struct vdso_data { * relocation, and this is what we need. */ extern struct vdso_data _vdso_data[CS_BASES] __attribute__((visibility("hidden"))); +extern struct vdso_data _timens_data[CS_BASES] __attribute__((visibility("hidden"))); #endif /* !__ASSEMBLY__ */ From patchwork Tue Feb 4 17:59:12 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Vagin X-Patchwork-Id: 11365121 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BE8AB1398 for ; Tue, 4 Feb 2020 18:00:32 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3D2EA2084E for ; Tue, 4 Feb 2020 18:00:32 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="XXNGwsDa"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="m/jQpv2J" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3D2EA2084E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=M9iNMZlz6sf174Nb3PPuNTi2mSTP/uwZWvDVS1adKTU=; b=XXNGwsDaCepcw6L6KUNlMWu1+A 83Ldhiny0SEbYqbjR79/9EiJkMhZYJZjFg50feMRh0M5JMm697AkNw7OKPMIz3I1gbb3IBJ8TBhwk tULiZXRY7B3vubV79UT3VpVuM82FGPlX7/yaWTkbvW0B8cZjSNIESln10aODMmCldLcPCxPRz/4rJ dY0hkFejwz0JHVi+yx7Hcl0C1SkcqxPdfca+10wjoMehsRsESWsG3Tows6eOAymPXwSNgDa4NMZGz xxre7/cLS8BnCokBPjoEN/EqHOjP5n2pmIfDvaqMSstmCXg/tTmX/SOQuKYYjttl1smJsxdUA1/XC JsyNYR1Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iz2Uu-0001E9-Vc; Tue, 04 Feb 2020 18:00:28 +0000 Received: from mail-pl1-x644.google.com ([2607:f8b0:4864:20::644]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iz2Tx-0007Zs-KW for linux-arm-kernel@lists.infradead.org; Tue, 04 Feb 2020 17:59:31 +0000 Received: by mail-pl1-x644.google.com with SMTP id y8so7557051pll.13 for ; Tue, 04 Feb 2020 09:59:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=b/tatmAbPqQvnbldAouTM/R8vE/FozyyVbJhnSwJXGA=; b=m/jQpv2JIjMmYb0com4+E9ygLdFliyeNs30azzuB5uZxmGdg2Z6m6ZNxWcUsWuV/58 a/IYICceuBaOBCgC5vHB1M3Jd8ov0ZRQT07oApqu7FdsVSYpwcxaE7bmxkWzs1URLwwk OwaD4YOFmg4eX2KSoNfwnkbvyGlH4m9IfKZ/75I3RkdIbKGQOz8Vkr3RbNDIgyNugFeX 4ubvJkQ2YxE9geC4va10CzZfuDAe5NXvu5zbP1vIrNorrYvodKAKH04QZ5nPkGJ0v0A2 IZiSap0cjNjQ7ZwaeUo3lB1kD7GRcAn9Q7ywK3zOwnE5nNbWCy76F70T1AFe2UZ0qvIt cDrg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=b/tatmAbPqQvnbldAouTM/R8vE/FozyyVbJhnSwJXGA=; b=hsgNyy0oEE91hSr47p91JMExhOq0iHsPoPAPvMLPnEI8pcGgc1SFY75hfUUp8UGG66 b76CFFXc84M4FU2CCKU1YX8pdygJoyRj4QUH4XSKxWVMubbB1sn6d79sD1Y6WrjlNqLd hmFBjW7reN5tSBB/UwXsgfZZ/7L2jO7hTAAdJIZt2NkghG9DkYE0BOZsTjmVwNhYUAWI CnFfUsellOITGwtaJMz60CtyCe/4BlN05TvXMlLHEmMu1CIF2kfXP/pYDkOWShYPHsyL uLj1yIvq7taJdNXR63FdHZjrvJxpU+GiIagVn0Oksz2AERE/fSOugjoppyqwqXIx6M6G lvDg== X-Gm-Message-State: APjAAAW006Nfyng1DoBuLHoqPglWENytBUmCFGfEPgiEJ8qh7M8tCU1R gEeSq3Sc3xqGGf1ZM5hJjxc= X-Google-Smtp-Source: APXvYqz/wsrLImmXNuI6MmUGKvGiwMhcKuUinmHKrZOCjZ8lY4eaVm8L+1GK00GJH3It8luUkRKQ+Q== X-Received: by 2002:a17:90b:4015:: with SMTP id ie21mr334038pjb.1.1580839168199; Tue, 04 Feb 2020 09:59:28 -0800 (PST) Received: from localhost.localdomain ([2620:0:1008:fd00:25a6:3140:768c:a64d]) by smtp.gmail.com with ESMTPSA id d73sm25414465pfd.109.2020.02.04.09.59.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 09:59:27 -0800 (PST) From: Andrei Vagin To: Vincenzo Frascino Subject: [PATCH 4/5] arm64/vdso: Handle faults on timens page Date: Tue, 4 Feb 2020 09:59:12 -0800 Message-Id: <20200204175913.74901-5-avagin@gmail.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200204175913.74901-1-avagin@gmail.com> References: <20200204175913.74901-1-avagin@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200204_095929_706138_C96382B0 X-CRM114-Status: GOOD ( 15.34 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:644 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [avagin[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Gleixner , Andrei Vagin , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Dmitry Safonov MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org If a task belongs to a time namespace then the VVAR page which contains the system wide VDSO data is replaced with a namespace specific page which has the same layout as the VVAR page. Signed-off-by: Andrei Vagin --- arch/arm64/kernel/vdso.c | 55 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 51 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index bc93e26ae485..2e553468b183 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c @@ -23,6 +23,7 @@ #include #include #include +#include #include #include @@ -171,15 +172,61 @@ int vdso_join_timens(struct task_struct *task, struct time_namespace *ns) up_write(&mm->mmap_sem); return 0; } + +static struct page *find_timens_vvar_page(struct vm_area_struct *vma) +{ + if (likely(vma->vm_mm == current->mm)) + return current->nsproxy->time_ns->vvar_page; + + /* + * VM_PFNMAP | VM_IO protect .fault() handler from being called + * through interfaces like /proc/$pid/mem or + * process_vm_{readv,writev}() as long as there's no .access() + * in special_mapping_vmops(). + * For more details check_vma_flags() and __access_remote_vm() + */ + + WARN(1, "vvar_page accessed remotely"); + + return NULL; +} +#else +static inline struct page *find_timens_vvar_page(struct vm_area_struct *vma) +{ + return NULL; +} #endif static vm_fault_t vvar_fault(const struct vm_special_mapping *sm, struct vm_area_struct *vma, struct vm_fault *vmf) { - if (vmf->pgoff == 0) - return vmf_insert_pfn(vma, vmf->address, - sym_to_pfn(vdso_data)); - return VM_FAULT_SIGBUS; + struct page *timens_page = find_timens_vvar_page(vma); + unsigned long pfn; + + switch (vmf->pgoff) { + case VVAR_DATA_PAGE_OFFSET: + if (timens_page) + pfn = page_to_pfn(timens_page); + else + pfn = sym_to_pfn(vdso_data); + break; + case VVAR_TIMENS_PAGE_OFFSET: + /* + * If a task belongs to a time namespace then a namespace + * specific VVAR is mapped with the VVAR_DATA_PAGE_OFFSET and + * the real VVAR page is mapped with the VVAR_TIMENS_PAGE_OFFSET + * offset. + * See also the comment near timens_setup_vdso_data(). + */ + if (!timens_page) + return VM_FAULT_SIGBUS; + pfn = sym_to_pfn(vdso_data); + break; + default: + return VM_FAULT_SIGBUS; + } + + return vmf_insert_pfn(vma, vmf->address, pfn); } static int __setup_additional_pages(enum arch_vdso_type arch_index, From patchwork Tue Feb 4 17:59:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Vagin X-Patchwork-Id: 11365123 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CA82392A for ; Tue, 4 Feb 2020 18:00:44 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 9F6C62084E for ; Tue, 4 Feb 2020 18:00:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="IypsHbku"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="UI3nq/p9" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9F6C62084E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=9dcQugUiB66M5NwPjZubQWwsB4I3AoNFRZKLYf4iuOk=; b=IypsHbkuTmRkarEdzg0H7wBHrA q22uWsrL5oyCjjizRQsvz22FU7ZyVn3Nc7kkAnpcbu/oGrQeJaYr4oVXul+uFGiOFo8IeI0owR5DR za9ieTi1CPjGz24X2FUroOgC4unH7qYpmZnMxKKqHnwWNvCZgitbOSoL2IPWzBgvh5q0Qt/2YewyY BhJmJmngnrnf1ytnrbx7ARuBfGZLFPvAuL+6OfoCOYWQKY39tcdvbQ/XthVd4vJ6pPk1Xz6AvhVm3 szAVEaqqPR6e5lMExuTV6SM9aMkrvTutJBjmJBgz2UOBTFFdY04VV5skloNu+KGpWIYKwJeI+aGC4 BoAdix2g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1iz2V8-0001RN-RM; Tue, 04 Feb 2020 18:00:42 +0000 Received: from mail-pf1-x444.google.com ([2607:f8b0:4864:20::444]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iz2Ty-0007bZ-Sj for linux-arm-kernel@lists.infradead.org; Tue, 04 Feb 2020 17:59:32 +0000 Received: by mail-pf1-x444.google.com with SMTP id k29so9820843pfp.13 for ; Tue, 04 Feb 2020 09:59:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=JyMzGy1x0Bon4+AzM/Sj0HNrbhuXPMQCx6Z9N3h13AI=; b=UI3nq/p9II8ri8gMr7xe4jx5TsTT5VWWhbBR7v+ihCbko9aZN9SZ1sO8nro5JpLhNI EK48Cl3ywcSaRhchOJXm1FYtGAJFWf8rKE1of5WvcC1GPSpYi2MAowQyiHBwkhbFJbfv 6ns+r7NVnz/0MX1TwyA7zFwrIRmqfiAMNOc3R0/VBdH+p1zKGvql9LZ2yZCRjml/vXGj TBsu7RPFMwRMm/WTz3k9ZzWdtVrAJp1YVe/Ha9nPQKj33UPVFNqO7txSOBrzN60lTGQ8 Zr5EpXwvVtutXXkTyQh9O/bprChPTWnAMhKvx671mDx9/Ye0P/brBW39AT4A7iMZLcOU FYjA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=JyMzGy1x0Bon4+AzM/Sj0HNrbhuXPMQCx6Z9N3h13AI=; b=DFafEdUclgSwalXTwH4gUu6KvUuXZ0Hq/thL7iTjWvH6holWVtBjV7606whyZRDr8I r53znUCM5UY3Z1UPpAC9C0A9k5CVMlFLGQLaiLyOY+x5as4OizX82wejlAAGfiEkQwHa 3DVeWKTtLce5oxhqQ/1cR94AjTFgNlU3utj9JZuhcTC486iwiHOpgfPMwEsATb3Gyea1 Eew1sZXq9OJt3yS9qgRSgOLIhPgzpRWVRgszEPICPCsq3kiwKnU1WEaUhb6P8PZyu0U/ iydcn1qAct4TVFukbIE6bCHXG/aN2yrJkIS6lrG+h6BGItnqsUHi0353vv9AxngbLWH8 nHZg== X-Gm-Message-State: APjAAAU9IWfrgUMv7819OVt5jA5mg0hBLaB9O7ri2TNP4tnSwYuGhhWT HyvEcXUE5LkJSrTkViuX+cI= X-Google-Smtp-Source: APXvYqwVVGMbq4U6Mx/8kHYp68Lm5UDq8ejfa6s44BKqQGNs00hDz/L86IOvGdVpIQoM+QmiUsAd+Q== X-Received: by 2002:a62:f243:: with SMTP id y3mr32842181pfl.146.1580839169558; Tue, 04 Feb 2020 09:59:29 -0800 (PST) Received: from localhost.localdomain ([2620:0:1008:fd00:25a6:3140:768c:a64d]) by smtp.gmail.com with ESMTPSA id d73sm25414465pfd.109.2020.02.04.09.59.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Feb 2020 09:59:28 -0800 (PST) From: Andrei Vagin To: Vincenzo Frascino Subject: [PATCH 5/5] arm64/vdso: Restrict splitting VVAR VMA Date: Tue, 4 Feb 2020 09:59:13 -0800 Message-Id: <20200204175913.74901-6-avagin@gmail.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200204175913.74901-1-avagin@gmail.com> References: <20200204175913.74901-1-avagin@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200204_095931_008415_82AF6827 X-CRM114-Status: GOOD ( 12.18 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.3 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:444 listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [avagin[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Thomas Gleixner , Andrei Vagin , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Dmitry Safonov MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org Forbid splitting VVAR VMA resulting in a stricter ABI and reducing the amount of corner-cases to consider while working further on VDSO time namespace support. As the offset from timens to VVAR page is computed compile-time, the pages in VVAR should stay together and not being partically mremap()'ed. Signed-off-by: Andrei Vagin --- arch/arm64/kernel/vdso.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index 2e553468b183..e6ebdc184c1e 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c @@ -229,6 +229,17 @@ static vm_fault_t vvar_fault(const struct vm_special_mapping *sm, return vmf_insert_pfn(vma, vmf->address, pfn); } +static int vvar_mremap(const struct vm_special_mapping *sm, + struct vm_area_struct *new_vma) +{ + unsigned long new_size = new_vma->vm_end - new_vma->vm_start; + + if (new_size != VVAR_NR_PAGES * PAGE_SIZE) + return -EINVAL; + + return 0; +} + static int __setup_additional_pages(enum arch_vdso_type arch_index, struct mm_struct *mm, struct linux_binprm *bprm, @@ -311,6 +322,7 @@ static struct vm_special_mapping aarch32_vdso_spec[C_PAGES] = { { .name = "[vvar]", .fault = vvar_fault, + .mremap = vvar_mremap, }, { .name = "[vdso]", @@ -493,6 +505,7 @@ static struct vm_special_mapping vdso_spec[A_PAGES] __ro_after_init = { { .name = "[vvar]", .fault = vvar_fault, + .mremap = vvar_mremap, }, { .name = "[vdso]",