Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3472662imu; Sun, 11 Nov 2018 15:54:30 -0800 (PST) X-Google-Smtp-Source: AJdET5cx3bYbbSVI4OT1jBBE08dn0tAtgrJ9Y6XC1VqqhOukor/vgiddbH4cznzgWubJEf9U9/rl X-Received: by 2002:a62:704a:: with SMTP id l71-v6mr17863243pfc.68.1541980470176; Sun, 11 Nov 2018 15:54:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541980470; cv=none; d=google.com; s=arc-20160816; b=jUGj17w710Sbh442BvZF8y6u7tiNIZDH1XBP1sSHi0zYm3UJackkRejt0KQT24Idv+ 47+ZtLMhcqIgs7zxnmZd8cSM8hiA/RyP0jkho9oQ9/mKXhUTzBGBmXnKRnpwT3N/BCav RNkfkB/gQS4Tymc9cugZ4LlDszCS1GJAayl6aHQG2NEEizZ55AED9d/6Vrl6Qx2UWgCR Q7SuQUAr07Js8QsTFG3uXU6Llq15/eudlyDaYxuUkLY8ZF/3NGzyryEcB3hw6YaPI4/U MCtDohv8az4RNQZ25UOqHib7k8RbxbrgG1Gt1G6FAWTPeXiDD7xPSqdSy0P4KdwG6YGI pDBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=th1rmqCpMYiiklaGsc/pvZstvmyZeNYPsd+TYfPYQic=; b=lkvmIHTs+/sECw0vy5vcO6sOuX1HIdIqe7RwxPlSxeW4F5xY7vY5z7eqPuBXdd2UfI j8Q3v0qGno64vARBphj4NPFegMkraQ+RgOBeFlOg7kwnmUKXKb5m00CMQyYmF8S1zkXk zm+XvRlFGTDcg1Zopdv7kUuqJR0Kio0jhvkbKiM+osLObml9lLY6MXBbwZW7Sh9SAl47 aXfocoH9KH7M8hLfpySbYxQic7zI6NWTayxX7AtFqIz6QjJIG2Mun60yZcH8WOlC+oBx cVxE0CrcT5yeuW6UtHMPLQkshp6im2GwB86BbsMdi2Zf4r2zZMlYc40SJoByBmed330x RaUw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=merlin.20170209 header.b="RmGx6FH/"; 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 59-v6si16844481pla.195.2018.11.11.15.54.15; Sun, 11 Nov 2018 15:54:30 -0800 (PST) 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=fail header.i=@infradead.org header.s=merlin.20170209 header.b="RmGx6FH/"; 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 S1732993AbeKLJnE (ORCPT + 99 others); Mon, 12 Nov 2018 04:43:04 -0500 Received: from merlin.infradead.org ([205.233.59.134]:34688 "EHLO merlin.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1732805AbeKLJnE (ORCPT ); Mon, 12 Nov 2018 04:43:04 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=th1rmqCpMYiiklaGsc/pvZstvmyZeNYPsd+TYfPYQic=; b=RmGx6FH/lAZmpS0VCBrmIi/gVF azPTK5Y+8G84h4tQ+Ecw7SkhS6pK2dlsi0P2AWcxPt95VTcIm0FlmXE/sVoVh697k8zn0RT+9AfBz MXKp+lVBCZiP+P2R6ggDLjvkBM4GzFE6bUf+r+BaUxQ999iVkQcSdvfMSt9WEI4JpbtpNKNg2gBaw 6lQ3lbDjPwUvIKT+nvfgD/Rx2FDlbWx3Eum2fE3jpJZhcZ/3JjlGGUZB7EDHAbhPvcPaw4+wLaL5O S4GbMH/w9/u/RQ1e0diSBKTNrGOwHuW16TyyZ8w4xs4lBvY7AHOLw5s0fGMsouWVLkHGF/fUr2dkH fbERvxhg==; Received: from [64.114.255.97] (helo=worktop) by merlin.infradead.org with esmtpsa (Exim 4.90_1 #2 (Red Hat Linux)) id 1gLzWi-00046q-8u; Sun, 11 Nov 2018 23:52:24 +0000 Received: by worktop (Postfix, from userid 1000) id 5E4216E061A; Mon, 12 Nov 2018 00:52:20 +0100 (CET) Date: Mon, 12 Nov 2018 00:52:20 +0100 From: Peter Zijlstra To: Nadav Amit Cc: Ingo Molnar , LKML , X86 ML , "H. Peter Anvin" , Thomas Gleixner , Borislav Petkov , Dave Hansen , Andy Lutomirski , Kees Cook , Dave Hansen , Masami Hiramatsu Subject: Re: [PATCH v4 06/10] x86/alternative: use temporary mm for text poking Message-ID: <20181111235220.GB3056@worktop> References: <20181110231732.15060-1-namit@vmware.com> <20181110231732.15060-7-namit@vmware.com> <20181111145936.GA3021@worktop> <43C8C690-F079-4513-82CD-46A62DBA5A3B@vmware.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <43C8C690-F079-4513-82CD-46A62DBA5A3B@vmware.com> User-Agent: Mutt/1.5.22.1 (2013-10-16) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sun, Nov 11, 2018 at 08:53:07PM +0000, Nadav Amit wrote: > >> + /* > >> + * The lock is not really needed, but this allows to avoid open-coding. > >> + */ > >> + ptep = get_locked_pte(poking_mm, poking_addr, &ptl); > >> + > >> + /* > >> + * If we failed to allocate a PTE, fail. This should *never* happen, > >> + * since we preallocate the PTE. > >> + */ > >> + if (WARN_ON_ONCE(!ptep)) > >> + goto out; > > > > Since we hard rely on init getting that right; can't we simply get rid > > of this? > > This is a repeated complaint of yours, which I do not feel comfortable with. > One day someone will run some static analysis tool and start finding that > all these checks are missing. > > The question is why do you care about them. Mostly because they should not be happening, ever. And if they happen, there really isn't anything sensible we can do about it. > If it is because they affect the > generated code and make it less efficient, I can fully understand and perhaps > we should have something like PARANOID_WARN_ON_ONCE() which compiles into nothing > unless a certain debug option is set. > > If it is about the way the source code looks - I guess it doesn’t sore my > eyes as hard as some other stuff, and I cannot do much about it (other than > removing it as you asked). And yes on the above two points. It adds both runtime overhead (albeit trivially small) and code complexity. > >> +out: > >> + if (memcmp(addr, opcode, len)) > >> + r = -EFAULT; > > > > How could this ever fail? And how can we reliably recover from that? > > This code has been there before (with slightly uglier code). Before this > patch, a BUG_ON() was used here. However, I noticed that kgdb actually > checks that text_poke() succeeded after calling it and gracefully fail. > However, this was useless, since text_poke() would panic before kgdb gets > the chance to do anything (see patch 7). Yes, I know it was there before, and I did see kgdb do it too. But aside from that out-label case, which we also should never hit, how can we realistically ever fail that memcmp()? If we fail here, something is _seriously_ buggered.