From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7666BC2BA2B for ; Thu, 9 Apr 2020 12:03:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 545FE20753 for ; Thu, 9 Apr 2020 12:03:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726622AbgDIMDn (ORCPT ); Thu, 9 Apr 2020 08:03:43 -0400 Received: from foss.arm.com ([217.140.110.172]:49336 "EHLO foss.arm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725987AbgDIMDn (ORCPT ); Thu, 9 Apr 2020 08:03:43 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 087B630E; Thu, 9 Apr 2020 05:03:43 -0700 (PDT) Received: from [192.168.1.172] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BF9063F73D; Thu, 9 Apr 2020 05:03:41 -0700 (PDT) Subject: Re: [PATCH v2 4/6] arm64/vdso: Handle faults on timens page To: Andrei Vagin Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Thomas Gleixner , Dmitry Safonov References: <20200225073731.465270-1-avagin@gmail.com> <20200225073731.465270-5-avagin@gmail.com> From: Vincenzo Frascino Message-ID: <658a52bb-400e-46d2-bfe8-1718c5c5f613@arm.com> Date: Thu, 9 Apr 2020 13:04:26 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20200225073731.465270-5-avagin@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2/25/20 7:37 AM, Andrei Vagin wrote: > 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 Reviewed-by: Vincenzo Frascino > --- > 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 b3e7ce24e59b..fb32c6f76078 100644 > --- a/arch/arm64/kernel/vdso.c > +++ b/arch/arm64/kernel/vdso.c > @@ -18,6 +18,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -175,15 +176,63 @@ 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; > +#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 arch_vdso_type arch_index, > -- Regards, Vincenzo From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.2 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SIGNED_OFF_BY,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2976FC2BB86 for ; Thu, 9 Apr 2020 12:03:48 +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 F255921473 for ; Thu, 9 Apr 2020 12:03:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="A1TzRI9q" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F255921473 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date: Message-ID:From:References:To:Subject:Reply-To:Content-ID:Content-Description :Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=umqBzdf4L3YeY4IdMovlu8hiGWjS/JmlxJPWf6a3fWU=; b=A1TzRI9qtfjOOE K16ay3Zuz0a+d8xMIGRJ44yDiraFEVBjTg50YIqpVC0+zLRYwJiaGtrHa7ouiK4uBkeL6jDw8lsnR Uvb2wjJxME006rEpmcUluqp/79G1/TgVyLDYJC/48rdHAZq2b45LZe29bdKqAt8F21ThpC+gTnM4b WUNsQMekPsZ27ce0sSVyVWzqJ77Iarm+yp/aZO/C5JI1Oh0IKN+9bN4Gw18hnmuxYr5QelzUdcEoj uOLRcmRIY9EUp6k+AIlXz0THwoSLU6YoyVmiTVxyYnlIzcY+PUL3wd47Jq/GqTS6OKLWkZ1gU+k0F AtXutqVsrISnCigWo6ug==; 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 1jMVuN-0006cl-0G; Thu, 09 Apr 2020 12:03:47 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jMVuJ-0006cI-I8 for linux-arm-kernel@lists.infradead.org; Thu, 09 Apr 2020 12:03:45 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 087B630E; Thu, 9 Apr 2020 05:03:43 -0700 (PDT) Received: from [192.168.1.172] (unknown [172.31.20.19]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id BF9063F73D; Thu, 9 Apr 2020 05:03:41 -0700 (PDT) Subject: Re: [PATCH v2 4/6] arm64/vdso: Handle faults on timens page To: Andrei Vagin References: <20200225073731.465270-1-avagin@gmail.com> <20200225073731.465270-5-avagin@gmail.com> From: Vincenzo Frascino Message-ID: <658a52bb-400e-46d2-bfe8-1718c5c5f613@arm.com> Date: Thu, 9 Apr 2020 13:04:26 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 In-Reply-To: <20200225073731.465270-5-avagin@gmail.com> Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200409_050343_687542_9B39CB4B X-CRM114-Status: GOOD ( 20.73 ) 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 , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Dmitry Safonov Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 2/25/20 7:37 AM, Andrei Vagin wrote: > 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 Reviewed-by: Vincenzo Frascino > --- > 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 b3e7ce24e59b..fb32c6f76078 100644 > --- a/arch/arm64/kernel/vdso.c > +++ b/arch/arm64/kernel/vdso.c > @@ -18,6 +18,7 @@ > #include > #include > #include > +#include > #include > #include > #include > @@ -175,15 +176,63 @@ 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; > +#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 arch_vdso_type arch_index, > -- Regards, Vincenzo _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel