From patchwork Tue Mar 30 06:57:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marco Elver X-Patchwork-Id: 12171777 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-26.3 required=3.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, URIBL_BLOCKED,USER_AGENT_GIT,USER_IN_DEF_DKIM_WL autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 59E07C433DB for ; Tue, 30 Mar 2021 06:57:52 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id DCD8A600EF for ; Tue, 30 Mar 2021 06:57:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DCD8A600EF Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 585B56B007E; Tue, 30 Mar 2021 02:57:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 55C3D6B0082; Tue, 30 Mar 2021 02:57:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 423AA6B0083; Tue, 30 Mar 2021 02:57:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0159.hostedemail.com [216.40.44.159]) by kanga.kvack.org (Postfix) with ESMTP id 25E626B007E for ; Tue, 30 Mar 2021 02:57:51 -0400 (EDT) Received: from smtpin18.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id E68E76D8B for ; Tue, 30 Mar 2021 06:57:50 +0000 (UTC) X-FDA: 77975635500.18.1410C28 Received: from mail-qv1-f73.google.com (mail-qv1-f73.google.com [209.85.219.73]) by imf09.hostedemail.com (Postfix) with ESMTP id AA4676000104 for ; Tue, 30 Mar 2021 06:57:48 +0000 (UTC) Received: by mail-qv1-f73.google.com with SMTP id fb10so11420373qvb.20 for ; Mon, 29 Mar 2021 23:57:50 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:message-id:mime-version:subject:from:to:cc; bh=hMimholtJavSZ5k5RmskDIdPrM99sfcyiNVXiZ0C39Q=; b=OH5d8xlZXFJybWRhJjBkXcR78y6Dg99Fi6Wu9wJe5SF7XuE2276SxkOPb4i0864u7I v1QOvvNSyVuPWNjaUbDzCNwhIj4w9cZWDbBcqD6PwayVLKhhI3moyW6cOIBtXItiRTDN e9mtpAXVixiFF0oBoeyjL+dLI3is78pOxEec8dpytg/re1V5PWPOlgOTqyVQjCmxi66x imkUfN9EK+bKYuPQiCfzm9PpjcWnAKe9rMBS/PE18lvblT/WZA0CeXA3Lpd609dUOsZE xTu1+OiQ8favi0WgZDFc1mkmN023k92e3sDkUivRuX5GLNu7cU682cYXndI/TnLV6z3P k4AA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=hMimholtJavSZ5k5RmskDIdPrM99sfcyiNVXiZ0C39Q=; b=kEsaIHhQjGJxJBRZxz35ute1i1t7yyFx3VvM0nQucaJd0vBcdyiTaZWsHfp6q7sI0d +dwKOrFJd8psT7GmHAL4FOBiu2Xjh+iO1qYxD5LzrtC7Fwinl+Ll/5S3MGLzT1DoFhCs Rh75hWp2/EFIruXMA8B2FCGxiYwLK8vO+PS0Rum1e1zse1OEfsziAJNQk53K6L8IKkLF 3+XXXngAVyRj4q3VU0oRHjEFPZO2szSE+moLO8BMcvMOidabXE+RlvRTurHKap3jWHNP 4T81ZZNPP41SLCkM2QpS+eoOMqL/abLAdqIvr4yf4g51blr2qLZyEPVcS1AZky920w9W FIYQ== X-Gm-Message-State: AOAM530XqAkfP9qcpuwRETx2M+zvm3tQhEwzI8L5syrj1YsQsruh/tQ7 cOMsFuufUOGA3+5ueNZkxlL6SyZDWA== X-Google-Smtp-Source: ABdhPJySzznEs5KXkYY7Mz4YuAJ7eH9id0jzsjJxiOEWguFIkHDpPKF4OEtGNTB/SuPZVGMFtySziqSk3w== X-Received: from elver.muc.corp.google.com ([2a00:79e0:15:13:40b1:c44f:3404:ad6a]) (user=elver job=sendgmr) by 2002:a0c:e148:: with SMTP id c8mr20761637qvl.18.1617087469699; Mon, 29 Mar 2021 23:57:49 -0700 (PDT) Date: Tue, 30 Mar 2021 08:57:37 +0200 Message-Id: <20210330065737.652669-1-elver@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.31.0.291.g576ba9dcdaf-goog Subject: [PATCH mm] kfence, x86: fix preemptible warning on KPTI-enabled systems From: Marco Elver To: elver@google.com, akpm@linux-foundation.org Cc: glider@google.com, dvyukov@google.com, andreyknvl@google.com, jannh@google.com, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kasan-dev@googlegroups.com, x86@kernel.org, Tomi Sarvela X-Rspamd-Server: rspam01 X-Rspamd-Queue-Id: AA4676000104 X-Stat-Signature: ipg9u59sai5uxk653ufb9zy6rq9rbf9z Received-SPF: none (flex--elver.bounces.google.com>: No applicable sender policy available) receiver=imf09; identity=mailfrom; envelope-from="<37ctiYAUKCBo4BL4H6EE6B4.2ECB8DKN-CCAL02A.EH6@flex--elver.bounces.google.com>"; helo=mail-qv1-f73.google.com; client-ip=209.85.219.73 X-HE-DKIM-Result: pass/pass X-HE-Tag: 1617087468-780233 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On systems with KPTI enabled, we can currently observe the following warning: BUG: using smp_processor_id() in preemptible caller is invalidate_user_asid+0x13/0x50 CPU: 6 PID: 1075 Comm: dmesg Not tainted 5.12.0-rc4-gda4a2b1a5479-kfence_1+ #1 Hardware name: Hewlett-Packard HP Pro 3500 Series/2ABF, BIOS 8.11 10/24/2012 Call Trace: dump_stack+0x7f/0xad check_preemption_disabled+0xc8/0xd0 invalidate_user_asid+0x13/0x50 flush_tlb_one_kernel+0x5/0x20 kfence_protect+0x56/0x80 ... While it normally makes sense to require preemption to be off, so that the expected CPU's TLB is flushed and not another, in our case it really is best-effort (see comments in kfence_protect_page()). Avoid the warning by disabling preemption around flush_tlb_one_kernel(). Link: https://lore.kernel.org/lkml/YGIDBAboELGgMgXy@elver.google.com/ Reported-by: Tomi Sarvela Signed-off-by: Marco Elver Acked-by: Alexander Potapenko --- arch/x86/include/asm/kfence.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/arch/x86/include/asm/kfence.h b/arch/x86/include/asm/kfence.h index 97bbb4a9083a..05b48b33baf0 100644 --- a/arch/x86/include/asm/kfence.h +++ b/arch/x86/include/asm/kfence.h @@ -56,8 +56,13 @@ static inline bool kfence_protect_page(unsigned long addr, bool protect) else set_pte(pte, __pte(pte_val(*pte) | _PAGE_PRESENT)); - /* Flush this CPU's TLB. */ + /* + * Flush this CPU's TLB, assuming whoever did the allocation/free is + * likely to continue running on this CPU. + */ + preempt_disable(); flush_tlb_one_kernel(addr); + preempt_enable(); return true; }