Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3899666pxf; Mon, 29 Mar 2021 14:57:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzvQok8OpS7vgUQkKnb2Ouux/4nQbZcdQD7fUWXGBluqzkIG7bqvto+OUFrnOGSzchQY5J+ X-Received: by 2002:a17:906:a413:: with SMTP id l19mr30738543ejz.421.1617055030465; Mon, 29 Mar 2021 14:57:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617055030; cv=none; d=google.com; s=arc-20160816; b=uCDRVsxy3BkfnFDHm0lGKH8wr3nmB8aFaAMyr6yl9tdx4Ftpxs+hrt9MlnaBdoXrxp 9A61zXq/8gEjA+twZputcD5Myql/5nSsUZy1eR8Da8CzJmlUeGaUOIAZlKhJigFBQf5l NvWS1C+prPYeELD3QYI2vHKr4WSgIPFbJq7/mkDJcbqH88YhnPZtPxgFa3HMuoxo2EIc AL6nTz/bEtUxkghsdEIw/aaDCUgOztvrI55sxe+K6Y0TXpD7g7xnXCFJH73FexiasvaK fUohwGc3DwAEDJXFJx8EyoEWidYCtiiFBNohq7OD9QP3zseCzSdjF3XdZpQIe28Ni8jJ ecSA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=lXwK9TDHJMeRrnXTHqrcsnlfyiEUU93Inkgor2Calrw=; b=KevmNcRv7kFHw5QnTSbDLmlfFnyGaclQ8p1lJI7iDVkcU2YuF901F1R4AUapEH/m+O fkxNYU7VQcTLrxwfJPBO2OmR4jg7vKF8BrnbHQ21nkc2Qntl6DwKeLMHBUIquo7ZTdNO QtJFbIitETlghQ4Y6nb5CBED34Fenu1w9I23mhoneVf0vwH9WmmEDIatsJ8ScRO4rU/g t2tjMo90/0HMn5gXJiKa1wtfTZJ/yYmazJEjKOqgq26CD+aPVAFRF+2r5LaA47fPFyTG j3NpKRMqhi4aXZaEzLRCTakVOxkaTV/Q5xAFJH6lZ9th089AFxfyem3L6ExTAbu7xAmj MRMw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=S5OHFkj9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id b14si13652205ede.310.2021.03.29.14.56.47; Mon, 29 Mar 2021 14:57:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=S5OHFkj9; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230364AbhC2Vz0 (ORCPT + 99 others); Mon, 29 Mar 2021 17:55:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230331AbhC2VzN (ORCPT ); Mon, 29 Mar 2021 17:55:13 -0400 Received: from mail-ot1-x333.google.com (mail-ot1-x333.google.com [IPv6:2607:f8b0:4864:20::333]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3EE78C061574 for ; Mon, 29 Mar 2021 14:55:12 -0700 (PDT) Received: by mail-ot1-x333.google.com with SMTP id k14-20020a9d7dce0000b02901b866632f29so13750432otn.1 for ; Mon, 29 Mar 2021 14:55:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=lXwK9TDHJMeRrnXTHqrcsnlfyiEUU93Inkgor2Calrw=; b=S5OHFkj9gRuAuPp2xsjRC8NT8r1TxdLdZkfO9vYEhUseN2QgfNrYt+fA+qtQjZ/QdX lQdkF0CmDqUtekeQiZEMzet8gzOxX5WycJDdqf1NoHputq6tJrJ7CPtRVUuG8q1QXBNb vvUH1YGeN9FEfWbn4InAdkMDcEy0YxTsraLbiK981q8GTZ54s7YgD5fg6xmxIXEpyCO9 drxiGnsygnGdv6NgQiqyGSjPZ3G5iF5f7yXHekbKEzSbrQ8zw9QFbBQMEEdicZg/jO2l QBTgBwaEn+1Xe85+kPEXNhoNn804IichrEVu89AYwjQPp0mZdYEDq9hdiUYNyNcFJQpO zJ9w== 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:content-transfer-encoding; bh=lXwK9TDHJMeRrnXTHqrcsnlfyiEUU93Inkgor2Calrw=; b=PemDmaLnlRVsg/fPf//3xgV1/O++kZ+dEs3kc7nxxNNP6+HEMOwcOLUXtbXBDmVBEK lk1LShXNu14gU2/Sqxpc2XZ4QB69MYGT5utMh+5qSo21WJqON/TGOtMcgfu13OFAx2Cg sEV3X1ybyP/0WOKOYPxCLE50Fi1L9ZqhLrNIVAcAP2EtuP1eR/NHhOUrKNRa0cDSWGL4 JahnEQqAISk6R7DcniSDvMc2VO84GHJLhk86/J7prGCT+AzdyKb7jlXwuXCHkri36Gg5 ip+wjfbtIunoCrsk21I6H/8ILZFDoAuXOXE722KevmX5Y5gB7vDR+QZNfmMz8VQbm6xS YJ1A== X-Gm-Message-State: AOAM532CyVta07sP8d4fen9Gdv9J5ZWEDXGGQ8fCrdvkwaVQWQx6o70B zg/A77Px3tepCObbjY8y7YsqXAg3ZQuPOQB29+lbBA== X-Received: by 2002:a05:6830:148c:: with SMTP id s12mr25234396otq.251.1617054911480; Mon, 29 Mar 2021 14:55:11 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Marco Elver Date: Mon, 29 Mar 2021 23:54:59 +0200 Message-ID: Subject: Re: I915 CI-run with kfence enabled, issues found To: Andy Lutomirski Cc: Dave Hansen , "Sarvela, Tomi P" , kasan-dev , Dave Hansen , Andy Lutomirski , Peter Zijlstra , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "the arch/x86 maintainers" , "H. Peter Anvin" , LKML Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, 29 Mar 2021 at 23:47, Andy Lutomirski wrote: > > > > On Mar 29, 2021, at 2:34 PM, Marco Elver wrote: > > > > =EF=BB=BFOn Mon, 29 Mar 2021 at 23:03, Dave Hansen wrote: > >>> On 3/29/21 10:45 AM, Marco Elver wrote: > >>>> On Mon, 29 Mar 2021 at 19:32, Dave Hansen wr= ote: > >>> Doing it to all CPUs is too expensive, and we can tolerate this being > >>> approximate (nothing bad will happen, KFENCE might just miss a bug an= d > >>> that's ok). > >> ... > >>>> BTW, the preempt checks in flush_tlb_one_kernel() are dependent on K= PTI > >>>> being enabled. That's probably why you don't see this everywhere. = We > >>>> should probably have unconditional preempt checks in there. > >>> > >>> In which case I'll add a preempt_disable/enable() pair to > >>> kfence_protect_page() in arch/x86/include/asm/kfence.h. > >> > >> That sounds sane to me. I'd just plead that the special situation (no= t > >> needing deterministic TLB flushes) is obvious. We don't want any folk= s > >> copying this code. > >> > >> BTW, I know you want to avoid the cost of IPIs, but have you considere= d > >> any other low-cost ways to get quicker TLB flushes? For instance, you > >> could loop over all CPUs and set cpu_tlbstate.invalidate_other=3D1. T= hat > >> would induce a context switch at the next context switch without needi= ng > >> an IPI. > > > > This is interesting. And it seems like it would work well for our > > usecase. Ideally we should only flush entries related to the page we > > changed. But it seems invalidate_other would flush the entire TLB. > > > > With PTI, flush_tlb_one_kernel() already does that for the current > > CPU, but now we'd flush entire TLBs for all CPUs and even if PTI is > > off. > > > > Do you have an intuition for how much this would affect large > > multi-socket systems? I currently can't quite say, and would err on > > the side of caution. > > Flushing the kernel TLB for all addresses > Is rather pricy. ISTR 600 cycles on Skylake, not to mention the cost of l= osing the TLB. How common is this? AFAIK, invalidate_other resets the asid, so it's not explicit and perhaps cheaper? In any case, if we were to do this, it'd be based on the sample interval of KFENCE, which can be as low as 1ms. But this is a production debugging feature, so the target machines are not test machines. For those production deployments we'd be looking at every ~500ms. But I know of other deployments that use <100ms. Doesn't sound like much, but as you say, I also worry a bit about losing the TLB across >100 CPUs even if it's every 500ms. Thanks, -- Marco