Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp4046998ybl; Mon, 26 Aug 2019 04:47:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqyvqqEbs4+UcnhMKmF43g9Ir/sch04JjYNyUTD6A6OnVVq+iYT1DcbXcaXmkjMrTV/rn/Fy X-Received: by 2002:a17:90a:f0d8:: with SMTP id fa24mr17615839pjb.142.1566820034632; Mon, 26 Aug 2019 04:47:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566820034; cv=none; d=google.com; s=arc-20160816; b=F/IUGauyEPBve0+XmT+pNTt/JPPa/2cVZmkfOo3L6Jz6S5yQcwWbqw7UZUhxuUfydk lqs6QgXct/AZUXnGubrmVAtGYetK1DAfy4bEb/ND+jPWpAboQ6+da5Hkoh/u1OBog7PB MqfS9UkG8QVMfzr6iI4Hy0JX+KjTIudmaW1ESzTwCaGo67GxIy//Ey4QAbQOh+fN5Ax4 BwLFykBX3GI3OCWPp1nPgkCb5aBEJWbopVAsKsNm/FMRNq/+A5UovPYcFmHYvv5l3MJG 4y8ZC49ex2E30LTXv/Q1KVNVMRzl9hUUFe/7AdejhtVBFOf8PI5qTsipqOaM/S1b8yeh ZEfQ== 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:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date; bh=3bYSWG+IrMvccV3JYseYd1UICDKk6Y0G83phnn5AHa4=; b=T/J6zS/CIeFNal3jt9sZCajuukVt9qafeFQlv3nWzSCx33dNNq5ZtHjhZVYv+vbyeU e6dihf6pQG8+awZlECjLzrk9KpCEfHqjxYwz9stlUq0kV6ACWe7zZCBKSiLlVfd30fe6 +aaosgxcjOqqrYhimZBmeXGdH6NMLYM1VVD8IzZ+bN4mCyaWZuTqcnH1+TpZ6udI4Omz oqLRfFt3Mqt22WSpucOXKYLgxB7EBfB9eKIWeeIdBKg6fBBoupus7UQhHtXtdH4AAZoQ +g22SpqwPMWmKd8DsTGjkPW4VZTFhtM3HQn2eND3kNj6+lk10ysQwHtS2LMHhQmQlyEw 5xBQ== ARC-Authentication-Results: i=1; mx.google.com; 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 o14si8989146pgk.45.2019.08.26.04.46.59; Mon, 26 Aug 2019 04:47:14 -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; 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 S1730607AbfHZLdM (ORCPT + 99 others); Mon, 26 Aug 2019 07:33:12 -0400 Received: from mail.kernel.org ([198.145.29.99]:51902 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727017AbfHZLdM (ORCPT ); Mon, 26 Aug 2019 07:33:12 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 42DD9217F5; Mon, 26 Aug 2019 11:33:10 +0000 (UTC) Date: Mon, 26 Aug 2019 07:33:08 -0400 From: Steven Rostedt To: Peter Zijlstra Cc: Song Liu , linux-kernel@vger.kernel.org, linux-mm@kvack.org, kernel-team@fb.com, stable@vger.kernel.org, Thomas Gleixner , Dave Hansen , Andy Lutomirski , Nadav Amit , Daniel Bristot de Oliveira Subject: Re: [PATCH] x86/mm: Do not split_large_page() for set_kernel_text_rw() Message-ID: <20190826073308.6e82589d@gandalf.local.home> In-Reply-To: <20190823093637.GH2369@hirez.programming.kicks-ass.net> References: <20190823052335.572133-1-songliubraving@fb.com> <20190823093637.GH2369@hirez.programming.kicks-ass.net> X-Mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 23 Aug 2019 11:36:37 +0200 Peter Zijlstra wrote: > On Thu, Aug 22, 2019 at 10:23:35PM -0700, Song Liu wrote: > > As 4k pages check was removed from cpa [1], set_kernel_text_rw() leads to > > split_large_page() for all kernel text pages. This means a single kprobe > > will put all kernel text in 4k pages: > > > > root@ ~# grep ffff81000000- /sys/kernel/debug/page_tables/kernel > > 0xffffffff81000000-0xffffffff82400000 20M ro PSE x pmd > > > > root@ ~# echo ONE_KPROBE >> /sys/kernel/debug/tracing/kprobe_events > > root@ ~# echo 1 > /sys/kernel/debug/tracing/events/kprobes/enable > > > > root@ ~# grep ffff81000000- /sys/kernel/debug/page_tables/kernel > > 0xffffffff81000000-0xffffffff82400000 20M ro x pte > > > > To fix this issue, introduce CPA_FLIP_TEXT_RW to bypass "Text RO" check > > in static_protections(). > > > > Two helper functions set_text_rw() and set_text_ro() are added to flip > > _PAGE_RW bit for kernel text. > > > > [1] commit 585948f4f695 ("x86/mm/cpa: Avoid the 4k pages check completely") > > ARGH; so this is because ftrace flips the whole kernel range to RW and > back for giggles? I'm thinking _that_ is a bug, it's a clear W^X > violation. Since ftrace did this way before text_poke existed and way before anybody cared (back in 2007), it's not really a bug. Anyway, I believe Nadav has some patches that converts ftrace to use the shadow page modification trick somewhere. Or we also need the text_poke batch processing (did that get upstream?). Mapping in 40,000 pages one at a time is noticeable from a human stand point. -- Steve