Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp198641pxb; Wed, 18 Aug 2021 19:59:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz+in2cnD9FvoIoGhTX/gm0WLw0qw8ZvNmOTGBpszn7UJKxG65be1ptSCmi0WwQKZ7LuOcA X-Received: by 2002:a05:6602:14a:: with SMTP id v10mr9685143iot.36.1629341981030; Wed, 18 Aug 2021 19:59:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629341981; cv=none; d=google.com; s=arc-20160816; b=ZBYcQTd8Frxb+cvGgTaRvsGwy7PXPjs2plOGgdjPkNoNHOy/OKeQutZUdcmYwWCpJS fdd1u8V5MaUlX/nQQe6HX/J/pKXP6aYSNbsxsc5kFFhg3bVjRdw9cqeWT22pz2IT1bS+ 1EvTBbvA8dGbWkVuqzrmw2O0irZvFkwI2lXy3CMqzUPOfkzXA38zTKVoeY7e7geELbHC zt4SlX0uW6nKYxNzSpGVaIYf91IsOCGJXWlP8OGL9hRA8BOkdSvBJMhN77XANxaEur7x fZ6WWtWzrUN7l+DpX4LaAX8hc6mz3D1ZuLGlpZCbLnf9zOS5c3AOoaPS9URASU2a5Bnz FWWw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:in-reply-to:message-id :date:subject:cc:to:from; bh=+m/V752RejUX8eA/pjp9OkFAkuEk9uWd+6fFu16OI54=; b=FZbmD23NY8QH7HWtvJ7XRVf/eMNWroXIsHVnBNMp7Qd172tpTDnEF5gGUgpgIUA1L4 S97UmRkyzy1OcVZ4/eXeIQ0OiTTOD2hB5dWm6iTQTIAQNMdYbfPnhjYriuEIcHJWxBOH qlmGimNFtVc6aisckl4dFomthvELqlkFK3Tr0qxkUJmLGzEmzgINpuOXJJOt2SfhseFW mdNNS62VfpIvk8dP+nQleG1idRDAVsqsqf3tXrwJ4xHxMWNB/QQzClXYz5h6V3wXj1bs erf95EKsiaTAAcgNgBAocU+a6/tKp3E/38Mk8dzm9JHK0z8RhMRt+CcYDug2o0/mCrbP QiIw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id q20si1691625ilj.61.2021.08.18.19.59.29; Wed, 18 Aug 2021 19:59:41 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235911AbhHSC6i (ORCPT + 99 others); Wed, 18 Aug 2021 22:58:38 -0400 Received: from szxga03-in.huawei.com ([45.249.212.189]:14274 "EHLO szxga03-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235878AbhHSC6g (ORCPT ); Wed, 18 Aug 2021 22:58:36 -0400 Received: from dggemv703-chm.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4GqqFV5XZLz87kF; Thu, 19 Aug 2021 10:57:50 +0800 (CST) Received: from dggpemm000001.china.huawei.com (7.185.36.245) by dggemv703-chm.china.huawei.com (10.3.19.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 19 Aug 2021 10:57:48 +0800 Received: from localhost.localdomain (10.175.112.125) by dggpemm000001.china.huawei.com (7.185.36.245) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Thu, 19 Aug 2021 10:57:47 +0800 From: Tong Tiangen To: Paul Walmsley , Palmer Dabbelt , Palmer Dabbelt , Albert Ou CC: , , "Tong Tiangen" Subject: [PATCH -next 1/2] riscv/vdso: Move vdso data page up front Date: Thu, 19 Aug 2021 03:06:49 +0000 Message-ID: <20210819030650.716478-2-tongtiangen@huawei.com> X-Mailer: git-send-email 2.18.0.huawei.25 In-Reply-To: <20210819030650.716478-1-tongtiangen@huawei.com> References: <20210819030650.716478-1-tongtiangen@huawei.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems704-chm.china.huawei.com (10.3.19.181) To dggpemm000001.china.huawei.com (7.185.36.245) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org As commit 601255ae3c98 ("arm64: vdso: move data page before code pages"), the same issue exists on riscv, testcase is shown below, make sure that vdso.so is bigger than page size, struct timespec tp; clock_gettime(5, &tp); printf("tv_sec: %ld, tv_nsec: %ld\n", tp.tv_sec, tp.tv_nsec); without this patch, test result : tv_sec: 0, tv_nsec: 0 with this patch, test result : tv_sec: 1629271537, tv_nsec: 748000000 Move the vdso data page in front of the VDSO area to fix the issue. In this patch, I moved the declaration of sys_riscv_flush_icache from asm/vdso.h to asm/syscall.h, the reason is asm/vdso.h is included in vdso.lds.S, If the declaration is placed here, This will introduce syntax error. Fixes: ad5d1122b82fb ("riscv: use vDSO common flow to reduce the latency of the time-related functions") Signed-off-by: Tong Tiangen --- arch/riscv/include/asm/syscall.h | 2 ++ arch/riscv/include/asm/vdso.h | 4 +-- arch/riscv/kernel/vdso.c | 47 ++++++++++++++++++------------- arch/riscv/kernel/vdso/vdso.lds.S | 3 +- 4 files changed, 33 insertions(+), 23 deletions(-) diff --git a/arch/riscv/include/asm/syscall.h b/arch/riscv/include/asm/syscall.h index b933b1583c9f..50704bd5ca3e 100644 --- a/arch/riscv/include/asm/syscall.h +++ b/arch/riscv/include/asm/syscall.h @@ -82,4 +82,6 @@ static inline int syscall_get_arch(struct task_struct *task) #endif } +asmlinkage long sys_riscv_flush_icache(uintptr_t, uintptr_t, uintptr_t); + #endif /* _ASM_RISCV_SYSCALL_H */ diff --git a/arch/riscv/include/asm/vdso.h b/arch/riscv/include/asm/vdso.h index 1453a2f563bc..564741266580 100644 --- a/arch/riscv/include/asm/vdso.h +++ b/arch/riscv/include/asm/vdso.h @@ -10,6 +10,8 @@ #include +#define __VVAR_PAGES 1 + #ifndef CONFIG_GENERIC_TIME_VSYSCALL struct vdso_data { }; @@ -29,6 +31,4 @@ struct vdso_data { (void __user *)((unsigned long)(base) + __vdso_##name); \ }) -asmlinkage long sys_riscv_flush_icache(uintptr_t, uintptr_t, uintptr_t); - #endif /* _ASM_RISCV_VDSO_H */ diff --git a/arch/riscv/kernel/vdso.c b/arch/riscv/kernel/vdso.c index 25a3b8849599..5fecd5529eff 100644 --- a/arch/riscv/kernel/vdso.c +++ b/arch/riscv/kernel/vdso.c @@ -14,12 +14,18 @@ #include #ifdef CONFIG_GENERIC_TIME_VSYSCALL #include -#else -#include #endif +#include extern char vdso_start[], vdso_end[]; +enum vvar_pages { + VVAR_DATA_PAGE_OFFSET, + VVAR_NR_PAGES, +}; + +#define VVAR_SIZE (VVAR_NR_PAGES << PAGE_SHIFT) + static unsigned int vdso_pages __ro_after_init; static struct page **vdso_pagelist __ro_after_init; @@ -38,7 +44,7 @@ static int __init vdso_init(void) vdso_pages = (vdso_end - vdso_start) >> PAGE_SHIFT; vdso_pagelist = - kcalloc(vdso_pages + 1, sizeof(struct page *), GFP_KERNEL); + kcalloc(vdso_pages + VVAR_NR_PAGES, sizeof(struct page *), GFP_KERNEL); if (unlikely(vdso_pagelist == NULL)) { pr_err("vdso: pagelist allocation failed\n"); return -ENOMEM; @@ -63,7 +69,9 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, unsigned long vdso_base, vdso_len; int ret; - vdso_len = (vdso_pages + 1) << PAGE_SHIFT; + BUILD_BUG_ON(VVAR_NR_PAGES != __VVAR_PAGES); + + vdso_len = (vdso_pages + VVAR_NR_PAGES) << PAGE_SHIFT; mmap_write_lock(mm); vdso_base = get_unmapped_area(NULL, 0, vdso_len, 0, 0); @@ -72,29 +80,28 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, goto end; } - /* - * Put vDSO base into mm struct. We need to do this before calling - * install_special_mapping or the perf counter mmap tracking code - * will fail to recognise it as a vDSO (since arch_vma_name fails). - */ - mm->context.vdso = (void *)vdso_base; + mm->context.vdso = NULL; + ret = install_special_mapping(mm, vdso_base, VVAR_SIZE, + (VM_READ | VM_MAYREAD), &vdso_pagelist[vdso_pages]); + if (unlikely(ret)) + goto end; ret = - install_special_mapping(mm, vdso_base, vdso_pages << PAGE_SHIFT, + install_special_mapping(mm, vdso_base + VVAR_SIZE, + vdso_pages << PAGE_SHIFT, (VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC), vdso_pagelist); - if (unlikely(ret)) { - mm->context.vdso = NULL; + if (unlikely(ret)) goto end; - } - vdso_base += (vdso_pages << PAGE_SHIFT); - ret = install_special_mapping(mm, vdso_base, PAGE_SIZE, - (VM_READ | VM_MAYREAD), &vdso_pagelist[vdso_pages]); + /* + * Put vDSO base into mm struct. We need to do this before calling + * install_special_mapping or the perf counter mmap tracking code + * will fail to recognise it as a vDSO (since arch_vma_name fails). + */ + mm->context.vdso = (void *)vdso_base + VVAR_SIZE; - if (unlikely(ret)) - mm->context.vdso = NULL; end: mmap_write_unlock(mm); return ret; @@ -105,7 +112,7 @@ const char *arch_vma_name(struct vm_area_struct *vma) if (vma->vm_mm && (vma->vm_start == (long)vma->vm_mm->context.vdso)) return "[vdso]"; if (vma->vm_mm && (vma->vm_start == - (long)vma->vm_mm->context.vdso + PAGE_SIZE)) + (long)vma->vm_mm->context.vdso - VVAR_SIZE)) return "[vdso_data]"; return NULL; } diff --git a/arch/riscv/kernel/vdso/vdso.lds.S b/arch/riscv/kernel/vdso/vdso.lds.S index e6f558bca71b..e9111f700af0 100644 --- a/arch/riscv/kernel/vdso/vdso.lds.S +++ b/arch/riscv/kernel/vdso/vdso.lds.S @@ -3,12 +3,13 @@ * Copyright (C) 2012 Regents of the University of California */ #include +#include OUTPUT_ARCH(riscv) SECTIONS { - PROVIDE(_vdso_data = . + PAGE_SIZE); + PROVIDE(_vdso_data = . - __VVAR_PAGES * PAGE_SIZE); . = SIZEOF_HEADERS; .hash : { *(.hash) } :text -- 2.18.0.huawei.25