From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7FD91C4332F for ; Mon, 21 Nov 2022 05:40:21 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id F276C6B0072; Mon, 21 Nov 2022 00:40:20 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id ED99A6B0073; Mon, 21 Nov 2022 00:40:20 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id DA0616B0074; Mon, 21 Nov 2022 00:40:20 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id CD5426B0072 for ; Mon, 21 Nov 2022 00:40:20 -0500 (EST) Received: from smtpin16.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id A1222140ABE for ; Mon, 21 Nov 2022 05:40:20 +0000 (UTC) X-FDA: 80156349000.16.6CC9952 Received: from mail-yw1-f171.google.com (mail-yw1-f171.google.com [209.85.128.171]) by imf04.hostedemail.com (Postfix) with ESMTP id 48DF140006 for ; Mon, 21 Nov 2022 05:40:20 +0000 (UTC) Received: by mail-yw1-f171.google.com with SMTP id 00721157ae682-3876f88d320so103704847b3.6 for ; Sun, 20 Nov 2022 21:40:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=/0dujvI66k8dvZ4+iOLkypH8JCTwbnK/z2RJps0YrtI=; b=jF3s06QCgsUZvM0RKnSIOmJkFDWsfW6PXcLzLjsdLf5h8gEExAVkTSo/r9NT1TnIb1 iGgvN9AsWBhx5aRtAPMKvr62uClpcvtJlR+Uc9K5pRxxPMz6Jnz8MSKil5/PJIAcsCen fSC0nt7yYiux7MTSQ6SWLs0VLLBodShk6jP+6yRTJdTUZgWQyyMBefhH+q4Ii3Omb2mF IcEeo1XZKwuXARpHGNIQXwi9s8YuMiJ7dqDU7/UJu8KF0gW2LmDkrL9MXu4gJw494jns N9URoloidc17fSAi3W2+iDtPYYMNyavxrXrTXNznLFkdFMKYM9PAFwoPB1BMK/6o3Ajq A5qQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=/0dujvI66k8dvZ4+iOLkypH8JCTwbnK/z2RJps0YrtI=; b=TxBwhqxlCo63maGuw1UXHRM+6k7fnCVOOSdD7gce2mFANwsin0bL+yY2rMa1ky17c+ 8XIcfMVxOHHvwWpEvDeTcIlYSgsqienE7SHFOLOTXZ0D+rZzoTKNbewSGS/xo20Y1aLd GpvAZmmHCxKEk8/3tZ3jXsWVDkb6+DMD6nqBBujXvCb0eAKNAvQI4TkuLNdZNBV36A0L qJblK8+BeDJ8jRbdtkqpKfm/EYFGc5K96QhTVBCepRUbnWzdQuffnRB4LngUAU8PkIAD QF8ERwSbg2V5WsYpjYdstz1HHaG0+kGLEFfA1ReE7WPH+q4V50bnkMXhYR3L83aTY5Us UHaA== X-Gm-Message-State: ANoB5pl607USEup9I/tr6x4MoQEO+c1UaofV98RFB6rgoiExa2sc6R2r zq+vxr1pMUbcOccGM9e6g21wxjPQvsGKb4/C+eQHyQ== X-Google-Smtp-Source: AA0mqf6SEF8jWr1jCFfYCO4FjdTdGRv1CC+XqKHC0wNxmj3V2Yl886eUatLzdUwLno5hATdgxjl0YbwTMeWRBg9MJOs= X-Received: by 2002:a81:142:0:b0:396:56a9:512b with SMTP id 63-20020a810142000000b0039656a9512bmr11564228ywb.459.1669009219299; Sun, 20 Nov 2022 21:40:19 -0800 (PST) MIME-Version: 1.0 References: <4208866d-338f-4781-7ff9-023f016c5b07@intel.com> In-Reply-To: <4208866d-338f-4781-7ff9-023f016c5b07@intel.com> From: Naresh Kamboju Date: Mon, 21 Nov 2022 11:10:07 +0530 Message-ID: Subject: Re: WARNING: CPU: 0 PID: 0 at arch/x86/include/asm/kfence.h:46 kfence_protect To: Dave Hansen Cc: Marco Elver , Peter Zijlstra , kasan-dev , X86 ML , open list , linux-mm , regressions@lists.linux.dev, lkft-triage@lists.linaro.org, Andrew Morton , Alexander Potapenko Content-Type: text/plain; charset="UTF-8" ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669009220; a=rsa-sha256; cv=none; b=vd4dVSV0GAdimnYsfYni3DGYzrgrDqKRkJiOL/g6w8mtzqYLOcoQqATDcKDd+heOOTfLOx bukj12obIozTd9Ze2KkmbzLwsu3oPbQ1caTGDNJ2FnwNEezgLf45HddR6YBLMkrscfbUbd S4qTYQWAKdPhgtjujxVsOb6LpBKH/SM= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=jF3s06QC; spf=pass (imf04.hostedemail.com: domain of naresh.kamboju@linaro.org designates 209.85.128.171 as permitted sender) smtp.mailfrom=naresh.kamboju@linaro.org; dmarc=pass (policy=none) header.from=linaro.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669009220; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=/0dujvI66k8dvZ4+iOLkypH8JCTwbnK/z2RJps0YrtI=; b=s0kBaYGSk8cxmJ6a26/Mg9TyRFx9xXrURdQxhlg1TWUsIh8tHhvll/oRNMrd9xnaWS+a+p Xe7vIS7h7eGdCWEGJPFppqq3LExlwqIoOW0n/QD7mwoUZmxT2FrBe6OiqjdMBUSd6KFnkS l7ewF57FuFRKm4RQ2hdzwpMuZDRzngQ= Authentication-Results: imf04.hostedemail.com; dkim=pass header.d=linaro.org header.s=google header.b=jF3s06QC; spf=pass (imf04.hostedemail.com: domain of naresh.kamboju@linaro.org designates 209.85.128.171 as permitted sender) smtp.mailfrom=naresh.kamboju@linaro.org; dmarc=pass (policy=none) header.from=linaro.org X-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 48DF140006 X-Rspam-User: X-Stat-Signature: uuodqts6wqdykkgqw7o8yqchcw8mteyf X-HE-Tag: 1669009220-788172 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 Thu, 17 Nov 2022 at 20:04, Dave Hansen wrote: > > On 11/17/22 05:58, Marco Elver wrote: > > [ 0.663761] WARNING: CPU: 0 PID: 0 at arch/x86/include/asm/kfence.h:46 kfence_protect+0x7b/0x120 > > [ 0.664033] WARNING: CPU: 0 PID: 0 at mm/kfence/core.c:234 kfence_protect+0x7d/0x120 > > [ 0.664465] kfence: kfence_init failed > > Any chance you could add some debugging and figure out what actually > made kfence call over? Was it the pte or the level? > > if (WARN_ON(!pte || level != PG_LEVEL_4K)) > return false; > > I can see how the thing you bisected to might lead to a page table not > being split, which could mess with the 'level' check. > > Also, is there a reason this code is mucking with the page tables > directly? It seems, uh, rather wonky. This, for instance: > > > if (protect) > > set_pte(pte, __pte(pte_val(*pte) & ~_PAGE_PRESENT)); > > else > > set_pte(pte, __pte(pte_val(*pte) | _PAGE_PRESENT)); > > > > /* > > * 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(); > > Seems rather broken. I assume the preempt_disable() is there to get rid > of some warnings. But, there is nothing I can see to *keep* the CPU > that did the free from being different from the one where the TLB flush > is performed until the preempt_disable(). That makes the > flush_tlb_one_kernel() mostly useless. > > Is there a reason this code isn't using the existing page table > manipulation functions and tries to code its own? What prevents it from > using something like the attached patch? I have applied this patch and found build warnings / errors. In file included from mm/kfence/core.c:34: arch/x86/include/asm/kfence.h: In function 'kfence_protect_page': arch/x86/include/asm/kfence.h:45:17: error: implicit declaration of function 'set_memory_p'; did you mean 'set_memory_np'? [-Werror=implicit-function-declaration] 45 | set_memory_p(addr, addr + PAGE_SIZE); | ^~~~~~~~~~~~ | set_memory_np cc1: all warnings being treated as errors make[4]: *** [scripts/Makefile.build:250: mm/kfence/core.o] Error 1 In file included from mm/kfence/report.c:20: arch/x86/include/asm/kfence.h: In function 'kfence_protect_page': arch/x86/include/asm/kfence.h:45:17: error: implicit declaration of function 'set_memory_p'; did you mean 'set_memory_np'? [-Werror=implicit-function-declaration] 45 | set_memory_p(addr, addr + PAGE_SIZE); | ^~~~~~~~~~~~ | set_memory_np cc1: all warnings being treated as errors make[4]: *** [scripts/Makefile.build:250: mm/kfence/report.o] Error 1 In file included from mm/kfence/kfence_test.c:26: arch/x86/include/asm/kfence.h: In function 'kfence_protect_page': arch/x86/include/asm/kfence.h:45:17: error: implicit declaration of function 'set_memory_p'; did you mean 'set_memory_np'? [-Werror=implicit-function-declaration] 45 | set_memory_p(addr, addr + PAGE_SIZE); | ^~~~~~~~~~~~ | set_memory_np cc1: all warnings being treated as errors make[4]: *** [scripts/Makefile.build:250: mm/kfence/kfence_test.o] Error 1 ref: https://builds.tuxbuild.com/2HqMWcweeInju7rqVgGdNge7gby/ - Naresh