Received: by 10.192.165.148 with SMTP id m20csp4607313imm; Mon, 30 Apr 2018 23:47:26 -0700 (PDT) X-Google-Smtp-Source: AB8JxZoED2xotP0GOYmdBabeAi2kTdx0LMMuixRKKma4WSoPO+2SFAYo4B1NE8fwWteh7bQ16iXX X-Received: by 2002:a63:3688:: with SMTP id d130-v6mr12164365pga.228.1525157246494; Mon, 30 Apr 2018 23:47:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1525157246; cv=none; d=google.com; s=arc-20160816; b=YlVa52d5ERhsd6s8dFt89Wxe9A1+L8V2mHmcr16HsP1v5bqbsjPBpz0qXkYjCj/MHw 7baCpQDSgS3BXtqRNbVol2GulhQzP5uC7gWmnJz3Q10WfentPWMPkfcFnKckOFrobsbh 3FgiCsyMC/Yw1ihlgbGVLopG2/ZciVTaSzpD9GSyaEFEG9X5qYwzzj56BmX5ib7Ee5wN B69cs4HMf3CL3uv6I9Hkn0SbFcDbhLepTF5vtWnlU+kddv/fbUICy6cFpRTh3qrcE3vq Z8iKCSjYGwe6pgKTrBKU5f5vSEKeUjLnz75GG+E8rgLlcYXnyr4p5F5FlRa2gnzximlW eg5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject:dmarc-filter :dkim-signature:dkim-signature:arc-authentication-results; bh=M8R5eZq8e6184GIWOHkKbC+WpklQoXIbcXgOhlQQNy4=; b=f427PL4XmPmApigGbE6c3zfOQJMnhiYyMTjiYjBStuuHRcQmmv9LHB59+jKz08dww3 IjHLVI5JP457eQJ20ouMujxsqSWSTXxj7bPvDufmUVHvOqEwzugfzFju5H/emVTenYcX BZ3n7IfzNJ+d1+vZROsg98dRxcB6cFBL8qYht34aP0bM/AVT1ZLcKGi8WZYbuSkdOP18 i+fOo3AmHW+yqvStyc6upcadyK0MId1SihcUR9Ax7DV/GmigukJzW9P8rM5bZYeLDLbm GweYxDzSzWoQNqkuk9mlQA87pVXArtsGsZiICTxWngPTXrWOXReKaJhwrN5NfAjcQsLH g5eA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=ZuU03xBN; dkim=pass header.i=@codeaurora.org header.s=default header.b=HihQx/2o; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f39-v6si9048321plb.572.2018.04.30.23.47.10; Mon, 30 Apr 2018 23:47:26 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@codeaurora.org header.s=default header.b=ZuU03xBN; dkim=pass header.i=@codeaurora.org header.s=default header.b=HihQx/2o; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751651AbeEAGrC (ORCPT + 99 others); Tue, 1 May 2018 02:47:02 -0400 Received: from smtp.codeaurora.org ([198.145.29.96]:35114 "EHLO smtp.codeaurora.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751011AbeEAGrB (ORCPT ); Tue, 1 May 2018 02:47:01 -0400 Received: by smtp.codeaurora.org (Postfix, from userid 1000) id ADB7060A00; Tue, 1 May 2018 06:47:00 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525157220; bh=n3n8JCIPqsgZ73/eIPwIhi4CUNNNq3CeM8KgAocf2i8=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=ZuU03xBNyesTbopAoSj6WQQtysSe6gZOWdQd7sSOIqQjeKY8ggKxeraAozb7nKLHv v1HgQ9En7Sj3OQB9jkIvGcU9Ji1kH1af5/F/qFKYxwQFmp8IS++EFMElKbr6rtGUS6 XuxA/8cD6LGfRSfnvo9ztO5z0sqyHW7wDo86pmoM= X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on pdx-caf-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.8 required=2.0 tests=ALL_TRUSTED,BAYES_00, DKIM_SIGNED,T_DKIM_INVALID autolearn=no autolearn_force=no version=3.4.0 Received: from [10.204.79.109] (blr-c-bdr-fw-01_globalnat_allzones-outside.qualcomm.com [103.229.19.19]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: cpandya@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 41FC8602CB; Tue, 1 May 2018 06:46:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=codeaurora.org; s=default; t=1525157219; bh=n3n8JCIPqsgZ73/eIPwIhi4CUNNNq3CeM8KgAocf2i8=; h=Subject:To:Cc:References:From:Date:In-Reply-To:From; b=HihQx/2ovRnumfGL08I+yqy98TMxUXgVwrbHLFxDmAJ2cEY5lT+4QkH99TO0S5tR+ lIync152mZ+RqibV/u3jQhCG1/iikrwIrqD7FbZV6gz4IFJY7tCEYS0v2fghAIsGtq a2MKpyGpKRPWA6KsgwwPc6EKNX+EZXjju/4Z1yec= DMARC-Filter: OpenDMARC Filter v1.3.2 smtp.codeaurora.org 41FC8602CB Authentication-Results: pdx-caf-mail.web.codeaurora.org; dmarc=none (p=none dis=none) header.from=codeaurora.org Authentication-Results: pdx-caf-mail.web.codeaurora.org; spf=none smtp.mailfrom=cpandya@codeaurora.org Subject: Re: [PATCH v2] mm: vmalloc: Clean up vunmap to avoid pgtable ops twice To: Andrew Morton Cc: vbabka@suse.cz, labbott@redhat.com, catalin.marinas@arm.com, hannes@cmpxchg.org, f.fainelli@gmail.com, xieyisheng1@huawei.com, ard.biesheuvel@linaro.org, richard.weiyang@gmail.com, byungchul.park@lge.com, linux-mm@kvack.org, linux-kernel@vger.kernel.org References: <1523876342-10545-1-git-send-email-cpandya@codeaurora.org> <20180430155207.35a3dd94c31503c7a6268a8f@linux-foundation.org> From: Chintan Pandya Message-ID: <9808b76e-a4e7-95d6-35bf-f64ae4628f0a@codeaurora.org> Date: Tue, 1 May 2018 12:16:53 +0530 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.7.0 MIME-Version: 1.0 In-Reply-To: <20180430155207.35a3dd94c31503c7a6268a8f@linux-foundation.org> Content-Type: text/plain; charset=utf-8; format=flowed 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 5/1/2018 4:22 AM, Andrew Morton wrote: > On Mon, 16 Apr 2018 16:29:02 +0530 Chintan Pandya wrote: > >> vunmap does page table clear operations twice in the >> case when DEBUG_PAGEALLOC_ENABLE_DEFAULT is enabled. >> >> So, clean up the code as that is unintended. >> >> As a perf gain, we save few us. Below ftrace data was >> obtained while doing 1 MB of vmalloc/vfree on ARM64 >> based SoC *without* this patch applied. After this >> patch, we can save ~3 us (on 1 extra vunmap_page_range). >> >> CPU DURATION FUNCTION CALLS >> | | | | | | | >> 6) | __vunmap() { >> 6) | vmap_debug_free_range() { >> 6) 3.281 us | vunmap_page_range(); >> 6) + 45.468 us | } >> 6) 2.760 us | vunmap_page_range(); >> 6) ! 505.105 us | } > > It's been a long time since I looked at the vmap code :( > >> --- a/mm/vmalloc.c >> +++ b/mm/vmalloc.c >> @@ -603,26 +603,6 @@ static void unmap_vmap_area(struct vmap_area *va) >> vunmap_page_range(va->va_start, va->va_end); >> } >> >> -static void vmap_debug_free_range(unsigned long start, unsigned long end) >> -{ >> - /* >> - * Unmap page tables and force a TLB flush immediately if pagealloc >> - * debugging is enabled. This catches use after free bugs similarly to >> - * those in linear kernel virtual address space after a page has been >> - * freed. >> - * >> - * All the lazy freeing logic is still retained, in order to minimise >> - * intrusiveness of this debugging feature. >> - * >> - * This is going to be *slow* (linear kernel virtual address debugging >> - * doesn't do a broadcast TLB flush so it is a lot faster). >> - */ >> - if (debug_pagealloc_enabled()) { >> - vunmap_page_range(start, end); >> - flush_tlb_kernel_range(start, end); >> - } >> -} >> - >> /* >> * lazy_max_pages is the maximum amount of virtual address space we gather up >> * before attempting to purge with a TLB flush. >> @@ -756,6 +736,9 @@ static void free_unmap_vmap_area(struct vmap_area *va) >> { >> flush_cache_vunmap(va->va_start, va->va_end); >> unmap_vmap_area(va); >> + if (debug_pagealloc_enabled()) >> + flush_tlb_kernel_range(va->va_start, va->va_end); >> + >> free_vmap_area_noflush(va); >> } >> >> @@ -1142,7 +1125,6 @@ void vm_unmap_ram(const void *mem, unsigned int count) >> BUG_ON(!PAGE_ALIGNED(addr)); >> >> debug_check_no_locks_freed(mem, size); >> - vmap_debug_free_range(addr, addr+size); > > This appears to be a functional change: if (count <= VMAP_MAX_ALLOC) > and we're in debug mode then the > vunmap_page_range/flush_tlb_kernel_range will no longer be performed. > Why is this ok? > Yes, you are right. In vb_free(), we do vunmap_page_range() but not flush_tlb_kernel_range(). I will add this stub for debug benefits and share v3. diff --git a/mm/vmalloc.c b/mm/vmalloc.c index 6729400..781ce02 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -1036,6 +1036,10 @@ static void vb_free(const void *addr, unsigned long size) vunmap_page_range((unsigned long)addr, (unsigned long)addr + size); + if (debug_pagealloc_enabled()) + flush_tlb_kernel_range((unsigned long)addr, + (unsigned long)addr + size); + spin_lock(&vb->lock); /* Expand dirty range */ >> if (likely(count <= VMAP_MAX_ALLOC)) { >> vb_free(mem, size); >> @@ -1499,7 +1481,6 @@ struct vm_struct *remove_vm_area(const void *addr) >> va->flags |= VM_LAZY_FREE; >> spin_unlock(&vmap_area_lock); >> >> - vmap_debug_free_range(va->va_start, va->va_end); >> kasan_free_shadow(vm); >> free_unmap_vmap_area(va); >> > Chintan -- Qualcomm India Private Limited, on behalf of Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project