From patchwork Tue Feb 28 06:32:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 13154441 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 68669C64ED6 for ; Tue, 28 Feb 2023 06:32:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id EFA156B0072; Tue, 28 Feb 2023 01:32:54 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E86936B0073; Tue, 28 Feb 2023 01:32:54 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D4B106B0075; Tue, 28 Feb 2023 01:32:54 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id C5D586B0072 for ; Tue, 28 Feb 2023 01:32:54 -0500 (EST) Received: from smtpin04.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 9B23F1610E3 for ; Tue, 28 Feb 2023 06:32:54 +0000 (UTC) X-FDA: 80515732668.04.F50D876 Received: from mail-yw1-f202.google.com (mail-yw1-f202.google.com [209.85.128.202]) by imf14.hostedemail.com (Postfix) with ESMTP id DA055100012 for ; Tue, 28 Feb 2023 06:32:51 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=exeEIY5f; spf=pass (imf14.hostedemail.com: domain of 3EqD9YwMKCG8cPPTbbTYR.PbZYVahk-ZZXiNPX.beT@flex--pcc.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3EqD9YwMKCG8cPPTbbTYR.PbZYVahk-ZZXiNPX.beT@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677565971; 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=eey2bWIXShb0HJ2rZd6676jnb6hRL1sBGHfdZHZ/mnM=; b=wvjkzVZNjD23+PYC4lPbHb8EWcHxd0qwqj3Ki5t+HUO0/qsTnurG0LnEV6tdwUaPjkDqHR hO43eijybJHgL/WOP0HCtwfs6+Bo5KmRULvZ0nGSEuFN/K/13p7X/oLFTVlF0sr2lWp71B PCM56hAEm3AwYIQK05Tj11yNEILFug4= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=exeEIY5f; spf=pass (imf14.hostedemail.com: domain of 3EqD9YwMKCG8cPPTbbTYR.PbZYVahk-ZZXiNPX.beT@flex--pcc.bounces.google.com designates 209.85.128.202 as permitted sender) smtp.mailfrom=3EqD9YwMKCG8cPPTbbTYR.PbZYVahk-ZZXiNPX.beT@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677565971; a=rsa-sha256; cv=none; b=Dk1xt4Z9LTqy8t/Jq+Xm29EXVJlcaipKn7Uv3q9EjALMuKVTAjkkExIu18kFRtWLbCMcbm 05lHfx85BgO/xF61tljnSqU9d/eFXDfaKLs1TfyYc9OSy5JsFslF6TKEmtAWMyv3giTFkF 00Jj5yGhkYUzBzuwTmbsJ218m1jqRSs= Received: by mail-yw1-f202.google.com with SMTP id 00721157ae682-536c02ed619so192192477b3.8 for ; Mon, 27 Feb 2023 22:32:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677565971; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=eey2bWIXShb0HJ2rZd6676jnb6hRL1sBGHfdZHZ/mnM=; b=exeEIY5fWGlcZGVP7LYpH20VWXe5Zd74N5MibMoNaGhfte0/m04wncsgkZ42c81G9u xjwSkbxN7lhKJw3/ZFJ330YJlKsDgfyX/pKH51okzeWO026l5lbQ+rBHN+YqTVoP8rHl Wk7FGb5O2F4gadUDHuF7XtjdA7lEYjFJOyhol0bSWbjAuVG6LwYUtM6TVxhR4UWI2vvE ygXcb6MhUbYAD0IPZ9mgdxdOC0NWpPGNq+N6hidb1kFjVoRDXSpvbF8s7I9f73F9DW/T HeIP7KXQ+Ci/dbBH8Y3O4rh6lswmAGQ71d2MsJoj8ViqLp7nuN3tp2j/0oBV85TCiKG8 xFzA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677565971; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=eey2bWIXShb0HJ2rZd6676jnb6hRL1sBGHfdZHZ/mnM=; b=cKKQMlxZBOGvXBJSYyGDTJnhNmLLzYOaVOAtdtPsQNECOtch3cCc6HpDKwyNn2vfnH EVE3u0HFErPT5MRU8WHIaih138G0n8vdPp9/t+1gFUA0tjrTVTrHVnXtYiZmzBopdoSh e2h/E0ScbCZrj5II7hwMckuU8CbJ22cohBtKw9Cu7f6wRrcvQVtUs3dZLj/fjCdpsQzj XaMk5aSEj3hQkIDl1uo5GXylrRDkHobb+thuFhdkWaoi7X0w4tzvgOEW7XJ6EQ4zLShV HP3vqR4+qmqPFMPsFsMkJN1n3gbCOW6j1ULnV7qc9I/AIkZwSq9aBvayhOqMR58Zs7MC egmg== X-Gm-Message-State: AO0yUKV+E5KbkzrQ3plbZC8yficO8NF5b9ixlvrREg4WVs6w7Euv2UIP bnZZzUcUDR5wq2p8Wkz+Dx6RwyU= X-Google-Smtp-Source: AK7set+57JSpmmONJa+F5jArhG3H6DN81OBajRlOxhpKK//us3HrP9vQLt/cDaarFzuIYJrI34YHm6Q= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2d3:205:cb8e:e6d0:b612:8d4c]) (user=pcc job=sendgmr) by 2002:a05:6902:1388:b0:855:fdcb:4467 with SMTP id x8-20020a056902138800b00855fdcb4467mr1957716ybu.0.1677565970984; Mon, 27 Feb 2023 22:32:50 -0800 (PST) Date: Mon, 27 Feb 2023 22:32:39 -0800 In-Reply-To: <20230228063240.3613139-1-pcc@google.com> Message-Id: <20230228063240.3613139-2-pcc@google.com> Mime-Version: 1.0 References: <20230228063240.3613139-1-pcc@google.com> X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog Subject: [PATCH v2 1/2] Revert "kasan: drop skip_kasan_poison variable in free_pages_prepare" From: Peter Collingbourne To: catalin.marinas@arm.com, andreyknvl@gmail.com Cc: Peter Collingbourne , linux-mm@kvack.org, kasan-dev@googlegroups.com, ryabinin.a.a@gmail.com, linux-arm-kernel@lists.infradead.org, vincenzo.frascino@arm.com, will@kernel.org, eugenis@google.com, stable@vger.kernel.org X-Stat-Signature: o9k8qh8mbba1nz7t31hzt3i3d5jds4x6 X-Rspam-User: X-Rspamd-Queue-Id: DA055100012 X-Rspamd-Server: rspam06 X-HE-Tag: 1677565971-227328 X-HE-Meta: U2FsdGVkX185Fdxo7uygUqpmEv7HUip1H51CKfnKBV9hjzrFb8bQeH7dEHhf5+TOq/Vnj7cR7wDP3hdEYbDNwQDJPVA+Ui3EX1l5AF6STNVQu/INYhQDbGWbQI+7tEQhmUDV1hEoTlQnHWYG5SiClEcNj2qG9IF8gtqV/m8KqHgQB/nm3LT7cJFANTXeaZ3S1puqEh99+l5U6HX54Ox0YsLbqCYGHGSWg1STItIMX2AcqFRS4sha11Ho2QGsmR6xgB5ul+cHRCr4tYIvzE1zWwjlTF1aKj+0VIuz76qtLVqoF2/JUwJBzY+HNlYiZF4+ZqC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2+r69/d+2+wowvB3suKnSyPPfacE9GdFmYii8svPa40bRSvfuWM6lpTDQfT+JAp6C47pe34jTGS+MA5sDYVB8Zm/PZ1kj+MuVZ3o2uhvJGlfjRYkQi1QhfWzac+fm/gq8TqB4CMgEXwQtk+hClIbFd+TZSfMSWvWSpO5K+iT2+KfoCqDr8hciY/lUz65PudE5N5oFHqSZDd1jA8UTkN+kBnZlsrFO2w001w04MIC9oeNCwYnwUpWTi+FjLzmKf/2ifrFe2nGsZSwdoQvZi03FX88WUJGSRSzt1oeBm6cK1AxE/aHRTtqauGFEuXI+fsI+nXQCEC6Z0+vafMefIqspAeRpJu2HjJ/a6EhDWZ4KqJe0p5HyLdjo4OeUFT8qEaSwZLYtQMCLda4cRwatXg75JSZGGvB8/REaU8nLSUfiVnCoxeq2XG8ZP/uqb41yz9L1IWic= 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: This reverts commit 487a32ec24be819e747af8c2ab0d5c515508086a. The should_skip_kasan_poison() function reads the PG_skip_kasan_poison flag from page->flags. However, this line of code in free_pages_prepare(): page->flags &= ~PAGE_FLAGS_CHECK_AT_PREP; clears most of page->flags, including PG_skip_kasan_poison, before calling should_skip_kasan_poison(), which meant that it would never return true as a result of the page flag being set. Therefore, fix the code to call should_skip_kasan_poison() before clearing the flags, as we were doing before the reverted patch. Signed-off-by: Peter Collingbourne Fixes: 487a32ec24be ("kasan: drop skip_kasan_poison variable in free_pages_prepare") Cc: # 6.1 Link: https://linux-review.googlesource.com/id/Ic4f13affeebd20548758438bb9ed9ca40e312b79 Reviewed-by: Andrey Konovalov --- mm/page_alloc.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/page_alloc.c b/mm/page_alloc.c index ac1fc986af44..7136c36c5d01 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -1398,6 +1398,7 @@ static __always_inline bool free_pages_prepare(struct page *page, unsigned int order, bool check_free, fpi_t fpi_flags) { int bad = 0; + bool skip_kasan_poison = should_skip_kasan_poison(page, fpi_flags); bool init = want_init_on_free(); VM_BUG_ON_PAGE(PageTail(page), page); @@ -1470,7 +1471,7 @@ static __always_inline bool free_pages_prepare(struct page *page, * With hardware tag-based KASAN, memory tags must be set before the * page becomes unavailable via debug_pagealloc or arch_free_page. */ - if (!should_skip_kasan_poison(page, fpi_flags)) { + if (!skip_kasan_poison) { kasan_poison_pages(page, order, init); /* Memory is already initialized if KASAN did it internally. */ From patchwork Tue Feb 28 06:32:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Collingbourne X-Patchwork-Id: 13154442 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 333AAC6FA8E for ; Tue, 28 Feb 2023 06:32:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A66D66B0073; Tue, 28 Feb 2023 01:32:56 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 9F18B6B0075; Tue, 28 Feb 2023 01:32:56 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 86AD96B0078; Tue, 28 Feb 2023 01:32:56 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 780F86B0073 for ; Tue, 28 Feb 2023 01:32:56 -0500 (EST) Received: from smtpin28.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 54448C11FC for ; Tue, 28 Feb 2023 06:32:56 +0000 (UTC) X-FDA: 80515732752.28.0C91A1E Received: from mail-yw1-f201.google.com (mail-yw1-f201.google.com [209.85.128.201]) by imf10.hostedemail.com (Postfix) with ESMTP id 8860AC000B for ; Tue, 28 Feb 2023 06:32:53 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=UQZocSva; spf=pass (imf10.hostedemail.com: domain of 3FKD9YwMKCHEeRRVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--pcc.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3FKD9YwMKCHEeRRVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1677565973; a=rsa-sha256; cv=none; b=4fw7WfvBwtDa+FhluEfRActqhpSncsUI8Zs0ScstzAYXZKnVectWpQY0f3pipo2EnagnMJ fIBhjifMbqvcLa/SXAVA9eAqgc5jLVCMduCUOvkzko20qV9/wpOaL9dADAXOgfTjxXLV+d P39HvHcNBXrG0ndzkW86E2AQfbQAnvs= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=google.com header.s=20210112 header.b=UQZocSva; spf=pass (imf10.hostedemail.com: domain of 3FKD9YwMKCHEeRRVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--pcc.bounces.google.com designates 209.85.128.201 as permitted sender) smtp.mailfrom=3FKD9YwMKCHEeRRVddVaT.RdbaXcjm-bbZkPRZ.dgV@flex--pcc.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1677565973; 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=lS6JtWUQ52Qb7wGcCxHBiNyAoHwwQgmvUkclpS5/AjA=; b=NxSCjrqbhHSmgyAz4bP3jLtsMhLJQXCZzbumirmcjvwOLEIMTgDWje2vYCUSPVNe9WXd8J usefIPUu1jmIxxz3bBXnFHvMU8/OeYOQhcQBXUY1CjFutTcmakaThH7k7MARzoTWr4GumO +W3ncXCTIf20gL1MaBsBAr2/s5pw1rI= Received: by mail-yw1-f201.google.com with SMTP id 00721157ae682-536bbaa701aso189805417b3.3 for ; Mon, 27 Feb 2023 22:32:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; t=1677565972; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=lS6JtWUQ52Qb7wGcCxHBiNyAoHwwQgmvUkclpS5/AjA=; b=UQZocSvaR5DeuSbwpQ8ySGmLcbJYKh6q3uwTjfoNqDSipY/sl0CL9MHII1tgyIzssh KhUBT25SuZG/BIXpgtoudqGOxLmOahwhhjIz8DCe613CBl52g+9KNPPSBuWSHrqCOJVs MmZToCMbbakMMwdUgOyQJ2slfVC9XWVzA9yGvEKpPt9y9no4reWp0q8gCt9+on/ZCFlk JO3/CRwNn6hS1naYOD7MdN2R7OFiHhqmSS4FFgDtOvzrdoYx3amH199bzajT3QdwE4Uq 2FPtLsWokhBjNAFlL3+rAV4VF4gbZIUgKrxpjuWNXL9e5LkLiGcWZiDl1E/jan2lB9Sk ESJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1677565972; h=cc:to:from:subject:references:mime-version:message-id:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lS6JtWUQ52Qb7wGcCxHBiNyAoHwwQgmvUkclpS5/AjA=; b=sLUzo15bFTwu4Xx1oMYySWiE1fGJziY5JXQnYEB70xWw4UQEtDCc1TxxxFYk2BWS+X brGvXPb21nxxssnPiEu4cqVuy5p+NvBnSFWmjlsT8KADbjpWZAM7wZFP7Ro1xOIJXRd8 nt4uv05RgkrAgj8R136tuRhr8JHYj85ai3XZCQ3GXgKXcKVMpHeHKAR0e/5XL2y8v+xX K+s6r21WMy0fdx9DpiVHnisDBvoMOYDjKvCng+hiD4szvEpOOYpaFK5cB01J4R1+Ul9y Fl0GJIQVjpH5zdVuJP9WQuIK1cwLWIb4qd+P6aj6bRX/0Qdmibo0zagJWWLAL168adSM dXrw== X-Gm-Message-State: AO0yUKVIzwY5l9Er8v4tWUWICPLP7XOp+1AeA8a4+RKSRUs4/RfP9o6D AoGQ3/ENP2ZqSz0JgKIYONH6JmA= X-Google-Smtp-Source: AK7set8o760Y9jVZgo03F/saIycnTA4toXupWTCE1MRVx0UyigTc73sU6iS60IaYlLahu+Mt/Vf/M4I= X-Received: from pcc-desktop.svl.corp.google.com ([2620:15c:2d3:205:cb8e:e6d0:b612:8d4c]) (user=pcc job=sendgmr) by 2002:a81:ad0d:0:b0:536:38b4:f50 with SMTP id l13-20020a81ad0d000000b0053638b40f50mr952514ywh.1.1677565972773; Mon, 27 Feb 2023 22:32:52 -0800 (PST) Date: Mon, 27 Feb 2023 22:32:40 -0800 In-Reply-To: <20230228063240.3613139-1-pcc@google.com> Message-Id: <20230228063240.3613139-3-pcc@google.com> Mime-Version: 1.0 References: <20230228063240.3613139-1-pcc@google.com> X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog Subject: [PATCH v2 2/2] kasan: remove PG_skip_kasan_poison flag From: Peter Collingbourne To: catalin.marinas@arm.com, andreyknvl@gmail.com Cc: Peter Collingbourne , linux-mm@kvack.org, kasan-dev@googlegroups.com, ryabinin.a.a@gmail.com, linux-arm-kernel@lists.infradead.org, vincenzo.frascino@arm.com, will@kernel.org, eugenis@google.com X-Rspam-User: X-Rspamd-Queue-Id: 8860AC000B X-Rspamd-Server: rspam01 X-Stat-Signature: muouhjh7dk8pnn5kj7bjgxjidfcjotmw X-HE-Tag: 1677565973-892117 X-HE-Meta: U2FsdGVkX18JGBsNjLLuhKs/II+pFuJF7UBUvVSTaFfVzDRidTtuvY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d+gXUNBsB68ZWKqirN0XuJjO6Kdx+oRI8ylHYlxVAxPAsMv+ug+srmICunzN/8ntdHopONt8ZKVQuvY+qA2bMlFO/TMvX1jZNWwP5tPtDZY1WiF233LCrNZOD/7U+WuHyc+HtFhLRErElS+Rmmc7WGMen3hN+CCd/WT18aDCO2/Kq0tqdkbyHzFxzBWm0PQihpUQj3fFfxZ6Z3U70+iHyKERyxbX2+kQLzkD4rMMHZBVc8xbODJH4iEmEFHEsBmYGHR+jKUTcdXVK+0Wvs2KkixdYaBW2aEcWqKJwZXXfPS+Slkna1HRgjfLEkhrTP+sPJTp5V9Z9/ynYKcROMJT/ochHGciohDrcIl96/+M1u0YVatgIr2fcTR7KXhwDLmPawVYeH5IXh5dGK6LL9AwVK2C+5y6dxi2UOj7+WcNfaP9r63JfV62BbPs23BpIQvnJvNMBKzIG+3iX8SRIAoLFugD3VuT3YOsyW/B+6q4RPQ60pXv2IhdG9eRp4hWwU/eqZ+3YPyRo9jrKk1F1x5plKSmVE+wkpKQ8PJE3qY71Zgi0zWlD5hmaIM/Ye1mZl/bB46IaiG8izgwjJTw8aGWzI0xkxT3aWP798PWeUMdRywPE4NpUngMhDyO/lmk4qmy4lo9EkycmwjPCeEw== 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: Code inspection reveals that PG_skip_kasan_poison is redundant with kasantag, because the former is intended to be set iff the latter is the match-all tag. It can also be observed that it's basically pointless to poison pages which have kasantag=0, because any pages with this tag would have been pointed to by pointers with match-all tags, so poisoning the pages would have little to no effect in terms of bug detection. Therefore, change the condition in should_skip_kasan_poison() to check kasantag instead, and remove PG_skip_kasan_poison and associated flags. Signed-off-by: Peter Collingbourne Link: https://linux-review.googlesource.com/id/I57f825f2eaeaf7e8389d6cf4597c8a5821359838 --- v2: - also remove GFP_SKIP_KASAN_POISON and FPI_SKIP_KASAN_POISON - rename GFP_SKIP_KASAN_UNPOISON to GFP_SKIP_KASAN - update comments - simplify control flow by removing reset_tags include/linux/gfp_types.h | 28 +++++------- include/linux/page-flags.h | 9 ---- include/trace/events/mmflags.h | 12 +----- mm/kasan/hw_tags.c | 2 +- mm/page_alloc.c | 79 +++++++++++++--------------------- mm/vmalloc.c | 2 +- 6 files changed, 44 insertions(+), 88 deletions(-) diff --git a/include/linux/gfp_types.h b/include/linux/gfp_types.h index 5088637fe5c2..9bd45cdd19ac 100644 --- a/include/linux/gfp_types.h +++ b/include/linux/gfp_types.h @@ -47,16 +47,14 @@ typedef unsigned int __bitwise gfp_t; #define ___GFP_ACCOUNT 0x400000u #define ___GFP_ZEROTAGS 0x800000u #ifdef CONFIG_KASAN_HW_TAGS -#define ___GFP_SKIP_ZERO 0x1000000u -#define ___GFP_SKIP_KASAN_UNPOISON 0x2000000u -#define ___GFP_SKIP_KASAN_POISON 0x4000000u +#define ___GFP_SKIP_ZERO 0x1000000u +#define ___GFP_SKIP_KASAN 0x2000000u #else -#define ___GFP_SKIP_ZERO 0 -#define ___GFP_SKIP_KASAN_UNPOISON 0 -#define ___GFP_SKIP_KASAN_POISON 0 +#define ___GFP_SKIP_ZERO 0 +#define ___GFP_SKIP_KASAN 0 #endif #ifdef CONFIG_LOCKDEP -#define ___GFP_NOLOCKDEP 0x8000000u +#define ___GFP_NOLOCKDEP 0x4000000u #else #define ___GFP_NOLOCKDEP 0 #endif @@ -234,25 +232,22 @@ typedef unsigned int __bitwise gfp_t; * memory tags at the same time as zeroing memory has minimal additional * performace impact. * - * %__GFP_SKIP_KASAN_UNPOISON makes KASAN skip unpoisoning on page allocation. - * Only effective in HW_TAGS mode. - * - * %__GFP_SKIP_KASAN_POISON makes KASAN skip poisoning on page deallocation. - * Typically, used for userspace pages. Only effective in HW_TAGS mode. + * %__GFP_SKIP_KASAN makes KASAN skip unpoisoning on page allocation and + * poisoning on page deallocation. Typically used for userspace and vmalloc + * pages. Only effective in HW_TAGS mode. */ #define __GFP_NOWARN ((__force gfp_t)___GFP_NOWARN) #define __GFP_COMP ((__force gfp_t)___GFP_COMP) #define __GFP_ZERO ((__force gfp_t)___GFP_ZERO) #define __GFP_ZEROTAGS ((__force gfp_t)___GFP_ZEROTAGS) #define __GFP_SKIP_ZERO ((__force gfp_t)___GFP_SKIP_ZERO) -#define __GFP_SKIP_KASAN_UNPOISON ((__force gfp_t)___GFP_SKIP_KASAN_UNPOISON) -#define __GFP_SKIP_KASAN_POISON ((__force gfp_t)___GFP_SKIP_KASAN_POISON) +#define __GFP_SKIP_KASAN ((__force gfp_t)___GFP_SKIP_KASAN) /* Disable lockdep for GFP context tracking */ #define __GFP_NOLOCKDEP ((__force gfp_t)___GFP_NOLOCKDEP) /* Room for N __GFP_FOO bits */ -#define __GFP_BITS_SHIFT (27 + IS_ENABLED(CONFIG_LOCKDEP)) +#define __GFP_BITS_SHIFT (26 + IS_ENABLED(CONFIG_LOCKDEP)) #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1)) /** @@ -335,8 +330,7 @@ typedef unsigned int __bitwise gfp_t; #define GFP_DMA __GFP_DMA #define GFP_DMA32 __GFP_DMA32 #define GFP_HIGHUSER (GFP_USER | __GFP_HIGHMEM) -#define GFP_HIGHUSER_MOVABLE (GFP_HIGHUSER | __GFP_MOVABLE | \ - __GFP_SKIP_KASAN_POISON | __GFP_SKIP_KASAN_UNPOISON) +#define GFP_HIGHUSER_MOVABLE (GFP_HIGHUSER | __GFP_MOVABLE | __GFP_SKIP_KASAN) #define GFP_TRANSHUGE_LIGHT ((GFP_HIGHUSER_MOVABLE | __GFP_COMP | \ __GFP_NOMEMALLOC | __GFP_NOWARN) & ~__GFP_RECLAIM) #define GFP_TRANSHUGE (GFP_TRANSHUGE_LIGHT | __GFP_DIRECT_RECLAIM) diff --git a/include/linux/page-flags.h b/include/linux/page-flags.h index a7e3a3405520..74f81a52e7e1 100644 --- a/include/linux/page-flags.h +++ b/include/linux/page-flags.h @@ -135,9 +135,6 @@ enum pageflags { #ifdef CONFIG_ARCH_USES_PG_ARCH_X PG_arch_2, PG_arch_3, -#endif -#ifdef CONFIG_KASAN_HW_TAGS - PG_skip_kasan_poison, #endif __NR_PAGEFLAGS, @@ -594,12 +591,6 @@ TESTCLEARFLAG(Young, young, PF_ANY) PAGEFLAG(Idle, idle, PF_ANY) #endif -#ifdef CONFIG_KASAN_HW_TAGS -PAGEFLAG(SkipKASanPoison, skip_kasan_poison, PF_HEAD) -#else -PAGEFLAG_FALSE(SkipKASanPoison, skip_kasan_poison) -#endif - /* * PageReported() is used to track reported free pages within the Buddy * allocator. We can use the non-atomic version of the test and set diff --git a/include/trace/events/mmflags.h b/include/trace/events/mmflags.h index 9db52bc4ce19..232bc8efc98e 100644 --- a/include/trace/events/mmflags.h +++ b/include/trace/events/mmflags.h @@ -55,8 +55,7 @@ #ifdef CONFIG_KASAN_HW_TAGS #define __def_gfpflag_names_kasan , \ gfpflag_string(__GFP_SKIP_ZERO), \ - gfpflag_string(__GFP_SKIP_KASAN_POISON), \ - gfpflag_string(__GFP_SKIP_KASAN_UNPOISON) + gfpflag_string(__GFP_SKIP_KASAN) #else #define __def_gfpflag_names_kasan #endif @@ -96,12 +95,6 @@ #define IF_HAVE_PG_ARCH_X(flag,string) #endif -#ifdef CONFIG_KASAN_HW_TAGS -#define IF_HAVE_PG_SKIP_KASAN_POISON(flag,string) ,{1UL << flag, string} -#else -#define IF_HAVE_PG_SKIP_KASAN_POISON(flag,string) -#endif - #define __def_pageflag_names \ {1UL << PG_locked, "locked" }, \ {1UL << PG_waiters, "waiters" }, \ @@ -130,8 +123,7 @@ IF_HAVE_PG_HWPOISON(PG_hwpoison, "hwpoison" ) \ IF_HAVE_PG_IDLE(PG_young, "young" ) \ IF_HAVE_PG_IDLE(PG_idle, "idle" ) \ IF_HAVE_PG_ARCH_X(PG_arch_2, "arch_2" ) \ -IF_HAVE_PG_ARCH_X(PG_arch_3, "arch_3" ) \ -IF_HAVE_PG_SKIP_KASAN_POISON(PG_skip_kasan_poison, "skip_kasan_poison") +IF_HAVE_PG_ARCH_X(PG_arch_3, "arch_3" ) #define show_page_flags(flags) \ (flags) ? __print_flags(flags, "|", \ diff --git a/mm/kasan/hw_tags.c b/mm/kasan/hw_tags.c index d1bcb0205327..bb4f56e5bdec 100644 --- a/mm/kasan/hw_tags.c +++ b/mm/kasan/hw_tags.c @@ -318,7 +318,7 @@ void *__kasan_unpoison_vmalloc(const void *start, unsigned long size, * Thus, for VM_ALLOC mappings, hardware tag-based KASAN only tags * the first virtual mapping, which is created by vmalloc(). * Tagging the page_alloc memory backing that vmalloc() allocation is - * skipped, see ___GFP_SKIP_KASAN_UNPOISON. + * skipped, see ___GFP_SKIP_KASAN. * * For non-VM_ALLOC allocations, page_alloc memory is tagged as usual. */ diff --git a/mm/page_alloc.c b/mm/page_alloc.c index 7136c36c5d01..960e0edd413d 100644 --- a/mm/page_alloc.c +++ b/mm/page_alloc.c @@ -112,17 +112,6 @@ typedef int __bitwise fpi_t; */ #define FPI_TO_TAIL ((__force fpi_t)BIT(1)) -/* - * Don't poison memory with KASAN (only for the tag-based modes). - * During boot, all non-reserved memblock memory is exposed to page_alloc. - * Poisoning all that memory lengthens boot time, especially on systems with - * large amount of RAM. This flag is used to skip that poisoning. - * This is only done for the tag-based KASAN modes, as those are able to - * detect memory corruptions with the memory tags assigned by default. - * All memory allocated normally after boot gets poisoned as usual. - */ -#define FPI_SKIP_KASAN_POISON ((__force fpi_t)BIT(2)) - /* prevent >1 _updater_ of zone percpu pageset ->high and ->batch fields */ static DEFINE_MUTEX(pcp_batch_high_lock); #define MIN_PERCPU_PAGELIST_HIGH_FRACTION (8) @@ -1355,13 +1344,19 @@ static int free_tail_pages_check(struct page *head_page, struct page *page) /* * Skip KASAN memory poisoning when either: * - * 1. Deferred memory initialization has not yet completed, - * see the explanation below. - * 2. Skipping poisoning is requested via FPI_SKIP_KASAN_POISON, - * see the comment next to it. - * 3. Skipping poisoning is requested via __GFP_SKIP_KASAN_POISON, + * 1. For generic KASAN: deferred memory initialization has not yet completed. + * Tag-based KASAN modes skip pages freed via deferred memory initialization + * using page tags instead (see below). + * 2. For tag-based KASAN: the page has a match-all KASAN tag, indicating + * that error detection is disabled for accesses via the page address. + * + * Pages will have match-all tags in the following circumstances: + * + * 1. Skipping poisoning is requested via __GFP_SKIP_KASAN, * see the comment next to it. - * 4. The allocation is excluded from being checked due to sampling, + * 2. Pages are being initialized for the first time, including during deferred + * memory init; see the call to page_kasan_tag_reset in __init_single_page. + * 3. The allocation is excluded from being checked due to sampling, * see the call to kasan_unpoison_pages. * * Poisoning pages during deferred memory init will greatly lengthen the @@ -1377,10 +1372,10 @@ static int free_tail_pages_check(struct page *head_page, struct page *page) */ static inline bool should_skip_kasan_poison(struct page *page, fpi_t fpi_flags) { - return deferred_pages_enabled() || - (!IS_ENABLED(CONFIG_KASAN_GENERIC) && - (fpi_flags & FPI_SKIP_KASAN_POISON)) || - PageSkipKASanPoison(page); + if (IS_ENABLED(CONFIG_KASAN_GENERIC)) + return deferred_pages_enabled(); + + return page_kasan_tag(page) == 0xff; } static void kernel_init_pages(struct page *page, int numpages) @@ -1754,7 +1749,7 @@ void __free_pages_core(struct page *page, unsigned int order) * Bypass PCP and place fresh pages right to the tail, primarily * relevant for memory onlining. */ - __free_pages_ok(page, order, FPI_TO_TAIL | FPI_SKIP_KASAN_POISON); + __free_pages_ok(page, order, FPI_TO_TAIL); } #ifdef CONFIG_NUMA @@ -2456,9 +2451,9 @@ static inline bool should_skip_kasan_unpoison(gfp_t flags) /* * With hardware tag-based KASAN enabled, skip if this has been - * requested via __GFP_SKIP_KASAN_UNPOISON. + * requested via __GFP_SKIP_KASAN. */ - return flags & __GFP_SKIP_KASAN_UNPOISON; + return flags & __GFP_SKIP_KASAN; } static inline bool should_skip_init(gfp_t flags) @@ -2477,7 +2472,6 @@ inline void post_alloc_hook(struct page *page, unsigned int order, bool init = !want_init_on_free() && want_init_on_alloc(gfp_flags) && !should_skip_init(gfp_flags); bool zero_tags = init && (gfp_flags & __GFP_ZEROTAGS); - bool reset_tags = true; int i; set_page_private(page, 0); @@ -2511,37 +2505,22 @@ inline void post_alloc_hook(struct page *page, unsigned int order, /* Take note that memory was initialized by the loop above. */ init = false; } - if (!should_skip_kasan_unpoison(gfp_flags)) { - /* Try unpoisoning (or setting tags) and initializing memory. */ - if (kasan_unpoison_pages(page, order, init)) { - /* Take note that memory was initialized by KASAN. */ - if (kasan_has_integrated_init()) - init = false; - /* Take note that memory tags were set by KASAN. */ - reset_tags = false; - } else { - /* - * KASAN decided to exclude this allocation from being - * (un)poisoned due to sampling. Make KASAN skip - * poisoning when the allocation is freed. - */ - SetPageSkipKASanPoison(page); - } - } - /* - * If memory tags have not been set by KASAN, reset the page tags to - * ensure page_address() dereferencing does not fault. - */ - if (reset_tags) { + if (!should_skip_kasan_unpoison(gfp_flags) && + kasan_unpoison_pages(page, order, init)) { + /* Take note that memory was initialized by KASAN. */ + if (kasan_has_integrated_init()) + init = false; + } else { + /* + * If memory tags have not been set by KASAN, reset the page + * tags to ensure page_address() dereferencing does not fault. + */ for (i = 0; i != 1 << order; ++i) page_kasan_tag_reset(page + i); } /* If memory is still not initialized, initialize it now. */ if (init) kernel_init_pages(page, 1 << order); - /* Propagate __GFP_SKIP_KASAN_POISON to page flags. */ - if (kasan_hw_tags_enabled() && (gfp_flags & __GFP_SKIP_KASAN_POISON)) - SetPageSkipKASanPoison(page); set_page_owner(page, order, gfp_flags); page_table_check_alloc(page, order); diff --git a/mm/vmalloc.c b/mm/vmalloc.c index ef910bf349e1..b0c84847e9b6 100644 --- a/mm/vmalloc.c +++ b/mm/vmalloc.c @@ -3170,7 +3170,7 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align, * pages backing VM_ALLOC mapping. Memory is instead * poisoned and zeroed by kasan_unpoison_vmalloc(). */ - gfp_mask |= __GFP_SKIP_KASAN_UNPOISON | __GFP_SKIP_ZERO; + gfp_mask |= __GFP_SKIP_KASAN | __GFP_SKIP_ZERO; } /* Take note that the mapping is PAGE_KERNEL. */