Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3625279imu; Sun, 11 Nov 2018 19:47:28 -0800 (PST) X-Google-Smtp-Source: AJdET5c9HN5QdZIa0XrhERuTYxrhXHmACrxxgtGTItt4YdFADEyCKO5CpE51E7R8mtnxdBHYq6NQ X-Received: by 2002:a62:1dd5:: with SMTP id d204-v6mr18204682pfd.157.1541994448368; Sun, 11 Nov 2018 19:47:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541994448; cv=none; d=google.com; s=arc-20160816; b=orkNaeV2/upwgreSbCABEg9VnjcWqLPVBNe04INY+qsKE3fSl0Qbq6ECumBmcvKfZb C9SteES5bFip1F7XQFwQcGp005miAc9xb7kfxC8J7dmRPmhF0BFRLlkHPWlvMVfJnFiE egYBD9hpbkINUIDDp1ihe8EZ1GpsLnqAqbqDQl5cybsR0pY0NaTURYjsZqulyifPCFiu awwTlmRjIa/jIg7ncpyIvnYRo7oY1QdF0EVV0OlFFhrDe63mFE6aUmHq1zvJbUDcG/mz c2N98Cik7CZRwpnlQgg6VAGcw/kHtYV//OCjp/42uGQbpzMKpknVEAK6WzaD3YWcbgZu kdtQ== 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=qCBeWAVPl6/xvWokQkbKevMdjTmKaDmHisaEPKfKjBw=; b=UZhM+hgMeUXxzj6DMrvc+owpwz/Dhp32pEbfT+aPqgfxr8kIcRgIx99Rvz1lQ/y5XW 3kmIir4fLWfIy+lB9M0V0rxNb8oZ/b0krsmLboZRtfTtNAtie01JoEJvk4vciqSsAhEA G0YjltWxk2KB3xtKXsxt5q6k1p2vOupVmW0uL6IxS2T5rR4DmVdrSsVVN1fuEU/xkISP 9Re0QkOHpL97jkLTImAuluIzLf9cVi00KtuCfl08FFIPujDSi2bgCwdJkejIsx6gYlBD bYZLniwRJbVwQFGL3uuWG7PJiQ9gnjqJxNkktuHeuxtNcPxCJz0ktrO0+q5ZPS2RtMxr sbfA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=GaYohkx4; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d12si5665637pga.506.2018.11.11.19.47.12; Sun, 11 Nov 2018 19:47:28 -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=@gmail.com header.s=20161025 header.b=GaYohkx4; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730395AbeKLNiG (ORCPT + 99 others); Mon, 12 Nov 2018 08:38:06 -0500 Received: from mail-wm1-f67.google.com ([209.85.128.67]:53650 "EHLO mail-wm1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726270AbeKLNiG (ORCPT ); Mon, 12 Nov 2018 08:38:06 -0500 Received: by mail-wm1-f67.google.com with SMTP id f10-v6so6998197wme.3 for ; Sun, 11 Nov 2018 19:46:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:content-transfer-encoding:in-reply-to :user-agent; bh=qCBeWAVPl6/xvWokQkbKevMdjTmKaDmHisaEPKfKjBw=; b=GaYohkx49u016XwGD4AYcG+oknPuSSa+XdnTDGkGtuAj7oyIiWBHJXlJAJAqlJ4AUp GnA1E2h9sJbgWZhtSjXujA5u/iJb9LF48kU/t9H3iwflZZEuR/l3pIbZLtcCEt8J1wOc uiRZSeqRxEa71m+X32cTcp6q7i4CNJYNvUgKWEUzS2RxQlr8OV/5Xp1+LN+AVYcOG2rL NhgsRAqexo2MC60t7mQLXl1WOIMcCPqh15MQY08OFd3gzpxlUa4x0VQwirZKNaNmad4i blDyavxayDQT6osVyZVHk7072Ks7WIKtdDSEjhDgKI5/LGZ1eGhdp2uS0XW1mPx4lqCv fpZQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition :content-transfer-encoding:in-reply-to:user-agent; bh=qCBeWAVPl6/xvWokQkbKevMdjTmKaDmHisaEPKfKjBw=; b=PIvy3vA3ViI8rpmOjcVXMCytwjUFxX9jCjUdVwRtaCAkh8KrG7jyDJz2+0VGsG9reZ QmRYnefbjZU+cDYf35l41ctlswimzsFRhoR6/XtgppkE7dT9/40d7uubOjUdvmBjLTeM Tmc/jlOPHvdPgq3I907AhPK2ucRNOrDMygA3d2tPQj76HSBO1hifURbhjXeWyLzPlVtp elB2Vu1L05angU4CQyJpa7KaHaYGWpitF+23ZzSERkOZp4naGyj9BzbuWO+XWZLQudgl 8TFzY67DgEaLSTvBMWkdTHilLq7tF+ExKpPVty3NtHD0WfcrNqZY08yeUJpvXAxb9KDv 7Rhw== X-Gm-Message-State: AGRZ1gLkioDXPNCoeL9DFll0coATw5s9MR4Vule5FS+b7jom1H64VwvJ WaxhilUUiC+goj2k/+iy9NI= X-Received: by 2002:a1c:730b:: with SMTP id d11-v6mr6199542wmb.107.1541994410032; Sun, 11 Nov 2018 19:46:50 -0800 (PST) Received: from gmail.com (2E8B0CD5.catv.pool.telekom.hu. [46.139.12.213]) by smtp.gmail.com with ESMTPSA id l42-v6sm11475238wre.37.2018.11.11.19.46.48 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Sun, 11 Nov 2018 19:46:49 -0800 (PST) Date: Mon, 12 Nov 2018 04:46:46 +0100 From: Ingo Molnar To: Peter Zijlstra Cc: Nadav Amit , 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: <20181112034646.GA88919@gmail.com> References: <20181110231732.15060-1-namit@vmware.com> <20181110231732.15060-7-namit@vmware.com> <20181111145936.GA3021@worktop> <43C8C690-F079-4513-82CD-46A62DBA5A3B@vmware.com> <20181111235220.GB3056@worktop> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20181111235220.GB3056@worktop> User-Agent: Mutt/1.9.4 (2018-02-28) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Peter Zijlstra wrote: > 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. Since get_locked_pte() might in principle return NULL, it's an entirely routine pattern to check the return for NULL. This will save reviewer time in the future. > [...] And if they happen, there really isn't anything sensible we can > do about it. Warning about it is 'something', even if we cash afterwards, isn't 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. It's trivially small cycle level overhead in something that will be burdened by two TLB flushes anyway is is utterly slow. > > >> +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. So wouldn't it be better to just document and verify our assumptions of this non-trivial code by using return values intelligently? I mean, being worried about overhead would be legitimate in the syscall entry code. In code patching code, which is essentially a slow path, we should be much more worried about *robustness*. Thanks, Ingo