Received: by 2002:a25:ad19:0:0:0:0:0 with SMTP id y25csp4926515ybi; Sat, 6 Jul 2019 17:11:39 -0700 (PDT) X-Google-Smtp-Source: APXvYqzTBDFz8fwn1U8u9cQW16/qzVTLar5GBTWvMtp+m/y7sYHfDIZnI2IJSvzmPjIiZi0SC6Z+ X-Received: by 2002:a17:902:a612:: with SMTP id u18mr13500467plq.181.1562458299490; Sat, 06 Jul 2019 17:11:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1562458299; cv=none; d=google.com; s=arc-20160816; b=ZyNGHviVu6UU6FvKXp+vy2zLC4W3STsLB1UeSYDLe4E9zR/MvRWjk6bH7LaiQrWBd3 XDp9l5B5w2gzwq/mnAABmDVEpQN4m7O2GSjpSYHl+gh+0+KvfBADJxJhxjIk2d6H9fKl GXMipXDkb7bawfdl6d+WC0UvtaaOf7BsUSZd+hjbp+R6EF46WU1cBweXVLcjrf0SEYcH SwqYlzr1jaWJ2GyyGDlqvRAKcFWgpcvIajqXIOyqiVh07zHWrwdm1U78HFjiuCrygdxz tv/gEtJLx49gYA25PNkJHyE2DGcIHEcDEmizDsrExnfZLhakyiOS57DiPZffm81u4hSP yAWg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=scpPsW6mAUXoVLt8Kn4PeKq811oedw5fzrQlbMjJCpY=; b=dIpFlEe//TOuRgW6Y2ukeFOvXqBPNxd7ao2DE7ruhk+l9RDzBc8R766VbX80b8bulJ NTeXzw+zruqN1uACaXNMQQRoWHq3NYUMJs6BSJnxj3jSX8r1Rvs+Er8YsmHz0FpJFbLH DwNnFJQNMjbu2vSE/xv0jZiG9a8cxP6/ASW2ivjBR2tDc2MlTbmfgmQjssL1RXQvLnrD pbOOlIj/ysjA3G44xYdyZgwFSPEJP5FfF0Po44jFgwTn2A+ambzOQ0WY5brTIYUOiNbF iSA+t6Fl7GZw0f88rBIY01ER6v0uMixjzOZQBQzWDaB31cPxvb5AAN5POqFtHjTkhEEQ Fi9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux-foundation.org header.s=google header.b=G+oUd4wf; 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 r190si14447362pfr.102.2019.07.06.17.11.12; Sat, 06 Jul 2019 17:11:39 -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=@linux-foundation.org header.s=google header.b=G+oUd4wf; 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 S1726974AbfGGAIn (ORCPT + 99 others); Sat, 6 Jul 2019 20:08:43 -0400 Received: from mail-lj1-f194.google.com ([209.85.208.194]:43475 "EHLO mail-lj1-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726757AbfGGAIn (ORCPT ); Sat, 6 Jul 2019 20:08:43 -0400 Received: by mail-lj1-f194.google.com with SMTP id 16so12443762ljv.10 for ; Sat, 06 Jul 2019 17:08:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=scpPsW6mAUXoVLt8Kn4PeKq811oedw5fzrQlbMjJCpY=; b=G+oUd4wfJSoGtgNHa4aniQAymFR8ZTODrrpYDDWKvvAT1YrndCYcei6L3flSRZXgBd QUpo82vvG+iH5qmiH84iaRIHdc5FjR3ElleF4iXAMgN0mw4XLgeTReq+O0ocMMRwfHKX Ogar77eefZnUateWBw1DYgSIQsn/YXxYZzz9M= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=scpPsW6mAUXoVLt8Kn4PeKq811oedw5fzrQlbMjJCpY=; b=edaEdhRHDc8QdixJxB39h5tXpI/9xJw9zpqRCCzyPbFz/7Vlsk+bmmSB9rBzsJK0Pz Lv09mkLgQweXhSl4LbBX8a7xas4xZ9N5N5eocVxwkp+/NrCQR0TAvkhF1YyqNEDFSwxt cCGwLAONGXDAB+j+ANw7eWZ8WjVfQFNHMZZCdO4VGTKak1Nr6iIaUVK3FiPZkHqJi3bi P9e3PDurV5GBt6bRP8hXIW19AnWcs3kistfJKlcDsjRRWbq/ZBQtLi7s4HJSMiIfb+qx 0uAxP+IJJcnOryWAmVLehmsfGn9/Z9HzC2TrDjaBEuWSPIQ/V9dQxxJs1DO5Gklh9ofB uzqA== X-Gm-Message-State: APjAAAV3MC3P8yZnvUpixyMdempQctzYJKNHqAwvDolvLcXCSt+fV0BY Ag05gjnh8z/9Yu1ALVP76Qp1bkFsZNI= X-Received: by 2002:a2e:480a:: with SMTP id v10mr5795615lja.94.1562458120513; Sat, 06 Jul 2019 17:08:40 -0700 (PDT) Received: from mail-lf1-f48.google.com (mail-lf1-f48.google.com. [209.85.167.48]) by smtp.gmail.com with ESMTPSA id a70sm2655096ljf.57.2019.07.06.17.08.37 for (version=TLS1_3 cipher=AEAD-AES128-GCM-SHA256 bits=128/128); Sat, 06 Jul 2019 17:08:37 -0700 (PDT) Received: by mail-lf1-f48.google.com with SMTP id p197so8522493lfa.2 for ; Sat, 06 Jul 2019 17:08:37 -0700 (PDT) X-Received: by 2002:ac2:59c9:: with SMTP id x9mr5027021lfn.52.1562458116980; Sat, 06 Jul 2019 17:08:36 -0700 (PDT) MIME-Version: 1.0 References: <20190704195555.580363209@infradead.org> <20190704200050.534802824@infradead.org> <20190705134916.GU3402@hirez.programming.kicks-ass.net> <20190706182728.435a89ed@gandalf.local.home> In-Reply-To: From: Linus Torvalds Date: Sat, 6 Jul 2019 17:08:20 -0700 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v2 5/7] x86/mm, tracing: Fix CR2 corruption To: Steven Rostedt Cc: Peter Zijlstra , Thomas Gleixner , Borislav Petkov , Ingo Molnar , Andrew Lutomirski , Peter Anvin , Dave Hansen , Juergen Gross , Linux List Kernel Mailing , He Zhe , Joel Fernandes , devel@etsukata.com Content-Type: multipart/mixed; boundary="0000000000000a3535058d0c21d7" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org --0000000000000a3535058d0c21d7 Content-Type: text/plain; charset="UTF-8" On Sat, Jul 6, 2019 at 3:41 PM Linus Torvalds wrote: > > On Sat, Jul 6, 2019 at 3:27 PM Steven Rostedt wrote: > > > > We also have to deal with reading vmalloc'd data as that can fault too. > > Ahh, that may be a better reason for PeterZ's patches and reading cr2 > very early from asm code than the stack trace case. Hmm. Another alternative might be to simply just make our vmalloc page fault handling more robust. Right now, if we take a vmalloc page fault in an inconvenient spot, it is fatal because it corrupts the cr2 in the outer context. However, it doesn't *need* to be fatal. Who cares if the outer context cr2 gets corrupted? We probably *shouldn't* care - it's an odd and unusual case, and the outer context could just handle the wrong vmalloc-address cr2 fine (it's going to be a no-op, since the inner page fault will have handled it already), return, and then re-fault. The only reason it's fatal right now is that we care much too deeply about (a) the error code (b) the pt_regs state when we handle vmalloc faults. So one option is that we simply handle the vmalloc faults _without_ caring about the error code and the pt_regs state, because even if the error code or the pt_regs implies that the fault comes from user space, the cr2 value might be due to a vmalloc fault from the inner kernel page fault that corrupted cr2. Right now vmalloc faults are already special and need to be handled without holding any locks etc. We'd just make them even more special, and say that we might have a vmalloc area fault from any context. IOW, somethinig like the attached patch would make nesting vmalloc faults harmless. Sure, we'll do the "vmalloc fault" twice, and return and re-do the original page fault, but this is a very unusual case, so from a performance angle we don't really care. But I guess the "read cr2 early" is fine too.. Linus --0000000000000a3535058d0c21d7 Content-Type: text/x-patch; charset="US-ASCII"; name="patch.diff" Content-Disposition: attachment; filename="patch.diff" Content-Transfer-Encoding: base64 Content-ID: X-Attachment-Id: f_jxs77kj10 IGFyY2gveDg2L21tL2ZhdWx0LmMgfCAzMiArKysrKysrKystLS0tLS0tLS0tLS0tLS0tLS0tLS0t LQogMSBmaWxlIGNoYW5nZWQsIDkgaW5zZXJ0aW9ucygrKSwgMjMgZGVsZXRpb25zKC0pCgpkaWZm IC0tZ2l0IGEvYXJjaC94ODYvbW0vZmF1bHQuYyBiL2FyY2gveDg2L21tL2ZhdWx0LmMKaW5kZXgg NDZkZjRjNmFhZTQ2Li4zYTAzNTA0YmM2MjQgMTAwNjQ0Ci0tLSBhL2FyY2gveDg2L21tL2ZhdWx0 LmMKKysrIGIvYXJjaC94ODYvbW0vZmF1bHQuYwpAQCAtMTI0NSw2ICsxMjQ1LDE1IEBAIHN0YXRp YyB2b2lkCiBkb19rZXJuX2FkZHJfZmF1bHQoc3RydWN0IHB0X3JlZ3MgKnJlZ3MsIHVuc2lnbmVk IGxvbmcgaHdfZXJyb3JfY29kZSwKIAkJICAgdW5zaWduZWQgbG9uZyBhZGRyZXNzKQogeworCS8q CisJICogVGhlIGtlcm5lbCB2bWFsbG9jIGFyZWEgY2FuIGZhdWx0IGluIGF0IGFueSB0aW1lLCBh bmQKKwkgKiB3ZSBzaG91bGQgbm90IGNoZWNrIHRoZSBodyBlcnJvciBjb2RlLCBzaW5jZSB0aGUg Y3IyIHZhbHVlCisJICogY291bGQgYmUgYSBzdGFsZSBvbmUgZnJvbSBhIG5lc3RlZCB2bWFsbG9j IGZhdWx0LCBidXQgdGhlCisJICogZXJyb3IgY29kZSBnb3QgcHVzaGVkIGJ5IGhhcmR3YXJlLgor CSAqLworCWlmICh2bWFsbG9jX2ZhdWx0KGFkZHJl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