Received: by 2002:a05:6902:102b:0:0:0:0 with SMTP id x11csp390298ybt; Wed, 24 Jun 2020 01:41:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJza/dGlPhKmw/Wx6DYi1xA8sriEkmZFxztvXvKGzZVc9Oh0Lg8mUzCGHP+6g0peonQUyXHQ X-Received: by 2002:a17:906:5410:: with SMTP id q16mr24718262ejo.103.1592988070759; Wed, 24 Jun 2020 01:41:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1592988070; cv=none; d=google.com; s=arc-20160816; b=ZNjaO42SgYEW68zw7oojP9GcQtSofadqfZypBiJkQtrGVms1PNaHQpWyxQybaFZ3N8 3tnON4adZ1WhmvBsI5F2hBnkoDQDEs8FxU/bDDeEuow70hDAOJHaQNxAHLWl9Uhf+s6Z Byffl4wNRzTZNZ9JsilK5tumkoCrWk0BBuc+bP9F6TF64p/mTxq75wXQ5BqQZnABbuC1 mawLtmnWnTCKnhxoS7tht3TEH7B2vCdlGXjixCwCAW1Tgt5Fv2PQl0hFCOWIPht9uh9l Gv2PmkPSoLF262bOiaN+zeHXcxxwOSxQ4TTZPZSgRHPbJTvfljyP06hqWlwCkk6pyf9w eSyg== 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=/8shzvkLZsRhF8EZiKwRb8IF1NpqovkVn3jBNb1PgYM=; b=SEvSB05EAHQZnANaYa2+2o1Oro2Yot5SrH5/79BO7j52vmL5rPg3it6NoII38/bkkj X9pOCN5t9QZBJcM6Ixe2dhIJkTwtaoo1CiUxzo1i+ZYCmqOM2N+pq+pZVcFjpp+ivg0W FU0Nv6ul3418z4xMcRUU2mOMDzLXvPi/visAVsmu+/eJqEw9xvQuxl2d4nG0zcSeHj96 68UzgtXsr0DKE+uMIqcSjzdPlSdAaEClLHjyTcRncFJKJI3UOOzSYj0k7vBEVPmM2WJI GKC/ebGxgLXzuRoJ2o0cY5n/1ImAaprnHVDAfNuvz++tjUbJx5fpGRzGzkRx3oynrSbd eE4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=LuLWGAHb; 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 s5si11641348ejd.121.2020.06.24.01.40.47; Wed, 24 Jun 2020 01:41:10 -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=LuLWGAHb; 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 S2390378AbgFXIdc (ORCPT + 99 others); Wed, 24 Jun 2020 04:33:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52094 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2390347AbgFXId2 (ORCPT ); Wed, 24 Jun 2020 04:33:28 -0400 Received: from mail-pg1-x544.google.com (mail-pg1-x544.google.com [IPv6:2607:f8b0:4864:20::544]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50560C061755 for ; Wed, 24 Jun 2020 01:33:28 -0700 (PDT) Received: by mail-pg1-x544.google.com with SMTP id z5so1086422pgb.6 for ; Wed, 24 Jun 2020 01:33:28 -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=/8shzvkLZsRhF8EZiKwRb8IF1NpqovkVn3jBNb1PgYM=; b=LuLWGAHbvAtYucC3BWurHeM1ccLgXcqjPYvzH4nrLZhaqZNRwbLU+BAqXwo9nAZakQ OlnmNWE/wAi55BiWJJeFq8T3XTxJ0V1JMtYMEyV4Mhdyq8MOBGWPRdOw8JVg5Zs+vopT GVUnEjOm7YQHarNfqJrqIIishg88JZlRTVyuxyoifLWAdu8Gi3KUSIo2upbLSqkaBcFb v1h4TNUpp1IZh6RG2r9dPj3zrEJIIr+p5yO3UAE5J0bRVcVQbBQ4YtotNxhoIbqRIZy3 bCODgJ360ezsnoQtu8zOABWR2lffiYDpMA8G+CRVGt8xYV+9X+tBQ253tAB8EaYvU6vY PiuQ== 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=/8shzvkLZsRhF8EZiKwRb8IF1NpqovkVn3jBNb1PgYM=; b=jHHMSF/X3u3JuDOyvqUW8f9yDrzkRdxXEIdlUtgWNr2np1V8BHJbr6ElIT8/YAvhvb 677PcNGxR5LJHRty8Mog0/WMoYURkzdIkZkd758iLZPXNgU4VZ+gaFeHZ9LT2rt1+1RY WkViKLendQagy+ClLr1uLycZmIQdJQLk/yJtVudeUPrdc8oP0RNd6EpzDMzzEm0Oy46h +p1zW7r8fuM7CelmWz3ID6XF7aukogvtpkp4DZLE/A9OGHSZ0o5cV9915RKzt48h9wJn 8aY95awadxMZPxi8DnYTO35tjQ3le/OrDi3aBEWmvITB0YgLbzPWqCpNnGmHe4AukPoB SeMg== X-Gm-Message-State: AOAM532Zh677UIZUk3wrh5tt+8DriiqkJfbn6VAWoZn7qvbVzsKFBgR/ FafPyedp+boTAuXSa9yRDI4= X-Received: by 2002:a05:6a00:14d4:: with SMTP id w20mr29268187pfu.279.1592987607681; Wed, 24 Jun 2020 01:33:27 -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.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jun 2020 01:33:27 -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 4/6] arm64/vdso: Handle faults on timens page Date: Wed, 24 Jun 2020 01:33:19 -0700 Message-Id: <20200624083321.144975-5-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 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. Reviewed-by: Vincenzo Frascino Reviewed-by: Dmitry Safonov Signed-off-by: Andrei Vagin --- arch/arm64/kernel/vdso.c | 57 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/arch/arm64/kernel/vdso.c b/arch/arm64/kernel/vdso.c index 18854e6c1373..be9ca8c46cff 100644 --- a/arch/arm64/kernel/vdso.c +++ b/arch/arm64/kernel/vdso.c @@ -18,6 +18,7 @@ #include #include #include +#include #include #include #include @@ -164,15 +165,63 @@ int vdso_join_timens(struct task_struct *task, struct time_namespace *ns) mmap_read_unlock(mm); 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; +#ifdef CONFIG_TIME_NS + 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; +#endif /* CONFIG_TIME_NS */ + default: + return VM_FAULT_SIGBUS; + } + + return vmf_insert_pfn(vma, vmf->address, pfn); } static int __setup_additional_pages(enum vdso_abi abi, -- 2.24.1