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=-7.0 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,T_DKIMWL_WL_HIGH,URIBL_BLOCKED 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 78287C04AB6 for ; Tue, 28 May 2019 08:23:26 +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 4D363208C3 for ; Tue, 28 May 2019 08:23:26 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="YavvIrqv" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4D363208C3 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-Type: Content-Transfer-Encoding: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=/MOU3Bhuw/K6cLMIVG77L+Abr1rxK3Kgbf1UIYE3/nY=; b=YavvIrqv7gHZwUMC4Oa/wJd8C rnLlEaSKWZFv/GP0CgfctGyTRaXqzg8JBdoAe9ATnQ3v9gna/PzArF6aDfD7ZDIX/ecfMdGgCbWPL zJ3eV9RtzBnpvJb9/8xaH+B/fEBGSsALIv9STY1vvuM+EZeyj9ASt31X46I7xnoV4kOgCtIsNWq0b YXF26/CTbq+K0rY4t9PgNysVxSSN5ZarKiNN/YnbMQlHpMe8v7ffovj7F1DRP83EuYXOwaG3giOS/ QnRod7aH1On3r06pBA3MiHYIIr3S1U2wvYyhw58/cSfJzMpTneACs6EcDCEG0PHBkXJi0nqbEwiUf TCUiBRYSw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hVXOE-0003GT-Op; Tue, 28 May 2019 08:23:22 +0000 Received: from foss.arm.com ([217.140.101.70]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hVXOB-0003Ei-A8 for linux-arm-kernel@lists.infradead.org; Tue, 28 May 2019 08:23:20 +0000 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.72.51.249]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id E9959341; Tue, 28 May 2019 01:23:18 -0700 (PDT) Received: from [192.168.1.27] (usa-sjc-mx-foss1.foss.arm.com [217.140.101.70]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 7F7303F59C; Tue, 28 May 2019 01:23:16 -0700 (PDT) Subject: Re: [PATCH 3/4] arm64/kprobes: set VM_FLUSH_RESET_PERMS on kprobe instruction pages To: Anshuman Khandual , linux-arm-kernel@lists.infradead.org References: <20190523102256.29168-1-ard.biesheuvel@arm.com> <20190523102256.29168-4-ard.biesheuvel@arm.com> From: Ard Biesheuvel Message-ID: <7c5e1fea-c93e-fc5b-8c77-c9bd9ec41fb3@arm.com> Date: Tue, 28 May 2019 10:23:14 +0200 User-Agent: Mozilla/5.0 (X11; Linux aarch64; rv:60.0) Gecko/20100101 Thunderbird/60.7.0 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190528_012319_354214_27C221C1 X-CRM114-Status: GOOD ( 21.18 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: mark.rutland@arm.com, marc.zyngier@arm.com, Will Deacon , linux-kernel@vger.kernel.org, Peter Zijlstra , Nadav Amit , Masami Hiramatsu , James Morse , Andrew Morton , Rick Edgecombe Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 5/28/19 10:20 AM, Anshuman Khandual wrote: > > > On 05/23/2019 03:52 PM, Ard Biesheuvel wrote: >> In order to avoid transient inconsistencies where freed code pages >> are remapped writable while stale TLB entries still exist on other >> cores, mark the kprobes text pages with the VM_FLUSH_RESET_PERMS >> attribute. This instructs the core vmalloc code not to defer the >> TLB flush when this region is unmapped and returned to the page >> allocator. > > Makes sense. > >> >> Signed-off-by: Ard Biesheuvel >> --- >> arch/arm64/kernel/probes/kprobes.c | 4 +++- >> 1 file changed, 3 insertions(+), 1 deletion(-) >> >> diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/kprobes.c >> index 2509fcb6d404..036cfbf9682a 100644 >> --- a/arch/arm64/kernel/probes/kprobes.c >> +++ b/arch/arm64/kernel/probes/kprobes.c >> @@ -131,8 +131,10 @@ void *alloc_insn_page(void) >> void *page; >> >> page = vmalloc_exec(PAGE_SIZE); >> - if (page) >> + if (page) { >> set_memory_ro((unsigned long)page, 1); >> + set_vm_flush_reset_perms(page); >> + } > > Looks good. It seems there might be more users who would like to set > VM_FLUSH_RESET_PERMS right after their allocation for the same reason. > Hence would not it help to have a variant like vmalloc_exec_reset() or > such which will tag vm_struct->flags with VM_FLUSH_RESET_PERMS right > after it's allocation without requiring the caller to do the same. > If there is a sufficient number of similar users, then of course, it makes sense to factor this out. However, the kprobes code is slightly unusual in the sense that it allocates memory and immediately remaps it read-only, and relies on code patching to populate this allocation. I am not expecting to see this pattern in other places. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel