Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp390446ybt; Wed, 24 Jun 2020 01:41:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/xC+LX52DqBXxDz5Txt/axgR1/2sVQdrjLpWGZ0lout+zWBCQISIWG7c96+eH8zbZuElH X-Received: by 2002:a05:6402:1bde:: with SMTP id ch30mr26413376edb.163.1592988086286; Wed, 24 Jun 2020 01:41:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592988086; cv=none; d=google.com; s=arc-20160816; b=qUytasZpKpuk55F3Trs1XaMHUHSnA2oP3n22k3NA0Yydn7zlLaIlox9A5iKfD6Ee9y S5oGQXz5QzTxvlzq8AZ9DT8FiX66XnaNDYNHq7SWpKJxoZQD6/YXmd7HdS8TxoqQ1p8H ATKZTviWqsoEhPk64FtGM5HlKq3X1vEQjrLs7oiNLvcK25l+kICXIqStuu92CmCXC0rP xI9seHPtY43Vgj1hUQO9bo0/vqY0eaQkSd7iRbT9XFDSo+3Inc+0bW9zU3PTTDEFj6uk 3tgv37H8oRLPLN22KTbwNNgotbDjfkok6+SJfhgUSMHbRb3eiMggJYUQWKn6uEu94lIA tKng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature; bh=6L0sSvuJwPBVGN9Ohq5sd3L0jaFGTHLmQeT1JCfgJfY=; b=q3alTP21TlA1xBkBVichMphp0iKoCN/v4NaM+wgXXVI6M0le2kJPiyrA/9WhKJAjmt CIv/YKec7Ge4BD/ll46/As9Wk44wt8WpuM3bCr0S0KuDEnr5xuhzLzr4bQyMg3HSJ0Hp 4jPO9IcB9pebfXA5sbrijs1g9913zcZrAUD7nJYAHX5e+BOl9YGzbbQVp35M01CVPTZe CE9dCtPvIGzPikCPe57EQUxgWoXbXznxgg5rzOWJ9ReQOOntP955lHxY33FkRD7ZG2cD TD/cfIL4ILG6J4mqs2jryI3eHgVirowJw+OnsRDOgZKNh4g89U7WW/oU22tb97dmDLyN 9/dg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b="VfdUW/uz"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id k23si13191036ejk.35.2020.06.24.01.41.03; Wed, 24 Jun 2020 01:41:26 -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; dkim=pass header.i=@gmail.com header.s=20161025 header.b="VfdUW/uz"; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2390430AbgFXIds (ORCPT + 99 others); Wed, 24 Jun 2020 04:33:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52086 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387606AbgFXId0 (ORCPT ); Wed, 24 Jun 2020 04:33:26 -0400 Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 444E5C061573 for ; Wed, 24 Jun 2020 01:33:26 -0700 (PDT) Received: by mail-pl1-x642.google.com with SMTP id bh7so772095plb.11 for ; Wed, 24 Jun 2020 01:33:26 -0700 (PDT) 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=6L0sSvuJwPBVGN9Ohq5sd3L0jaFGTHLmQeT1JCfgJfY=; b=VfdUW/uzzvEmR/U+vmvbk643UTJcokTJAKQfqN5Kut6DFr8gbaCfTe64IU8Yi4zNP2 66LdHf+2Y/TzC/HWot/VVYnFEv7FvY5KFXPU+zUlSAViJb/pgvvZdwq/bTvDv35Lj8qP dUDTRQtw5RLqnPbskCOEpWj0Z7jpO5h7C0Kbwfkb8V0ONRg32Pi0vRqh+ZicTpACB/Q5 hhq5GkSA41HCg2bw9UCbkPrwzZ+D2ErkGOwoeUMv+ZgwtcVAOJ6hYrb/HM6mdjTFdfGr 3Zup1MHOWff/+WaErP94/+5gh2YJy0VnA0riiQGn/FRmkJn1gUgF5uqC021Aq6aTYq3R 2uDw== 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=6L0sSvuJwPBVGN9Ohq5sd3L0jaFGTHLmQeT1JCfgJfY=; b=lwNg5q8rLBmbcM39u5spD/mJ94I5a0C7voSAE2n1vtyMjuxw05P2Tf07aHxVMjTHKP c1yJAg/CWLZd3CrpjtjvO5skccj/mk8ik6pmXSZc1aR1E9qZDJwhdQ62I7/NLq6RSHy8 zN7hrKxnIhPkdhkHwvd4+Bj74YX6u7B58/sqqUSGqflhGU7NhifbQQqpE1XfVHTd6jg1 N4aVKrABAviVFnJ8cqhHL+MzFRv+r2p/RP3jrC3VaP6LvZWB7n0KdHV0Aw5vKflYyBkG S1u9ZYJUM3m8LJv+ZJqXP0Yi2mraxxe5yzuOnrDCXxUDX2MNp22HqvxIh6C4FjOVfcXF wGiQ== X-Gm-Message-State: AOAM530OcvVEGVpU+ojEgw15wVCEzC1IytlWRMYtZOZSveFg5oZMl3mS +WTf65lFGwLqDOKK4oXig+k= X-Received: by 2002:a17:90a:c797:: with SMTP id gn23mr26694003pjb.165.1592987605689; Wed, 24 Jun 2020 01:33:25 -0700 (PDT) Received: from laptop.hsd1.wa.comcast.net ([2601:600:9b7f:872e:a655:30fb:7373:c762]) by smtp.gmail.com with ESMTPSA id g17sm4558614pju.11.2020.06.24.01.33.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2020 01:33:24 -0700 (PDT) From: Andrei Vagin To: Catalin Marinas , Will Deacon , Mark Rutland Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Vincenzo Frascino , Thomas Gleixner , Dmitry Safonov , Christian Brauner , Andrei Vagin Subject: [PATCH 2/6] arm64/vdso: Zap vvar pages when switching to a time namespace Date: Wed, 24 Jun 2020 01:33:17 -0700 Message-Id: <20200624083321.144975-3-avagin@gmail.com> X-Mailer: git-send-email 2.17.2 In-Reply-To: <20200624083321.144975-1-avagin@gmail.com> References: <20200624083321.144975-1-avagin@gmail.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The order of vvar pages depends on whether a task belongs to the root time namespace or not. In the root time namespace, a task doesn't have a per-namespace page. In a non-root namespace, the VVAR page which contains the system-wide VDSO data is replaced with a namespace specific page that contains clock offsets. Whenever a task changes its namespace, the VVAR page tables are cleared and then they will be re-faulted with a corresponding layout. A task can switch its time namespace only if its ->mm isn't shared with another task. Reviewed-by: Vincenzo Frascino Reviewed-by: Dmitry Safonov Signed-off-by: Andrei Vagin --- arch/arm64/kernel/vdso.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index 7c4620451fa5..bdf492a17dff 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c @@ -124,6 +124,37 @@ static int __vdso_init(enum vdso_abi abi) return 0; } +#ifdef CONFIG_TIME_NS +/* + * The vvar mapping contains data for a specific time namespace, so when a task + * changes namespace we must unmap its vvar data for the old namespace. + * Subsequent faults will map in data for the new namespace. + * + * For more details see timens_setup_vdso_data(). + */ +int vdso_join_timens(struct task_struct *task, struct time_namespace *ns) +{ + struct mm_struct *mm = task->mm; + struct vm_area_struct *vma; + + mmap_read_lock(mm); + + 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_info[VDSO_ABI_AA64].dm)) + zap_page_range(vma, vma->vm_start, size); +#ifdef CONFIG_COMPAT_VDSO + if (vma_is_special_mapping(vma, vdso_info[VDSO_ABI_AA32].dm)) + zap_page_range(vma, vma->vm_start, size); +#endif + } + + mmap_read_unlock(mm); + return 0; +} +#endif + static vm_fault_t vvar_fault(const struct vm_special_mapping *sm, struct vm_area_struct *vma, struct vm_fault *vmf) { -- 2.24.1