Received: by 2002:a05:7412:8521:b0:e2:908c:2ebd with SMTP id t33csp2375603rdf; Mon, 6 Nov 2023 12:12:36 -0800 (PST) X-Google-Smtp-Source: AGHT+IH6HaXprRSEURug/OYdOrIu3RI9WvZ3fe0pWrJRdSY/MgdZ2d4aIQZ3kKHn4JBoVAADz+ke X-Received: by 2002:a05:6e02:1a8d:b0:358:574:4c84 with SMTP id k13-20020a056e021a8d00b0035805744c84mr832413ilv.21.1699301556342; Mon, 06 Nov 2023 12:12:36 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699301556; cv=none; d=google.com; s=arc-20160816; b=ip8s8HF9QqOfxBZ6H4nxOreqwQ79GE4ahgEnFD9mWMO+ellsHcBhI5IR/k7Jg6IUri KB56awCyu8DoTLJ2SsftDDM2BThLz0Oqu/Dr8+QRb1UzxNu+tagYmC+GD0wqY4amgKmy s+f19yb1VWyt75J7Hoh8oRI6dVzTZ4UA9rW9H17gOU8EjfbVzeToiDgBowKlmWtrGgAp x7ZvhkWuTUzm5DltRbmln//6YUXERevuWrRcuUFzkteoczFKDYPmt6VF6NpB1D1AXGFG 7DpohR6woPYEkvKqTms7+byXL7nNxsceJTE/Pi54vJsPCnX+1DxXSjF4wdrchqQiyWrr Z9EA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Z8UoFAswFgd+L4wk44THWP2F8PtTdf8hA2eur1Xmylc=; fh=n5KN85tQTomq0Sa/nFFC9xbnc77mxkBzF8HoolO/QOw=; b=x/ES3rHAykNlhqjZDQptTnU8zHZeKoXXlV9jX+id/bNOQqspmKWoJjwY2uJ80Iule+ OVRXs5m5QfeShkLp5w6rPB/umJc2QzhZDQt58qTmrmt7khPh9HvkmoVF7xH2NdCB7Uwt aH0WPoRA306VgEDnwFNu9Gwe+TwtBkOGGM3+rjrQASyrxypoSobOrqXBq2aLYHqSfPOV ZOGWx4Lg/X5u7i+QVDftdbmrNQRcN59BEjKg9n+/AeSNbye7eCHTMbZToS8I92TL4+id FTD5uVXe4+ACTsr6s9Z+YHUFR8bAAUMbPn+aJv4Nt59CTZ+A6TyJYBUmTbuh1ublo6bA neUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="nqNu/iJt"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Return-Path: Received: from fry.vger.email (fry.vger.email. [23.128.96.38]) by mx.google.com with ESMTPS id e17-20020a056a001a9100b006c0f03b2466si9015986pfv.53.2023.11.06.12.12.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 12:12:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) client-ip=23.128.96.38; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b="nqNu/iJt"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.38 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.dev Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by fry.vger.email (Postfix) with ESMTP id 71865805CD9E; Mon, 6 Nov 2023 12:12:22 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at fry.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233033AbjKFUL4 (ORCPT + 99 others); Mon, 6 Nov 2023 15:11:56 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233014AbjKFULp (ORCPT ); Mon, 6 Nov 2023 15:11:45 -0500 Received: from out-187.mta1.migadu.com (out-187.mta1.migadu.com [IPv6:2001:41d0:203:375::bb]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 321D310C4 for ; Mon, 6 Nov 2023 12:11:41 -0800 (PST) X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1699301499; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Z8UoFAswFgd+L4wk44THWP2F8PtTdf8hA2eur1Xmylc=; b=nqNu/iJtTBpRGoCOjf1lL74liuMLk3YhpzpUWzj3S+HMg+GQeM+EOVnxft+z4OPpPQbPuS Udqa+ZKx2NChvvQUHxkJu+aUnZoO5Chyi4YdPGofo1DOrNugA3NlPhfyyz2+pR+R6ojuqt 30m2oaGb1ReuPP6HOsDoxxp4rcV7+Ok= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Evgenii Stepanov , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH RFC 07/20] kasan: introduce kasan_mempool_unpoison_pages Date: Mon, 6 Nov 2023 21:10:16 +0100 Message-Id: <573ab13b08f2e13d8add349c3a3900bcb7d79680.1699297309.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on fry.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (fry.vger.email [0.0.0.0]); Mon, 06 Nov 2023 12:12:23 -0800 (PST) From: Andrey Konovalov Introduce and document a new kasan_mempool_unpoison_pages hook to be used by the mempool code instead of kasan_unpoison_pages. This hook is not functionally different from kasan_unpoison_pages, but using it improves the mempool code readability. Signed-off-by: Andrey Konovalov --- include/linux/kasan.h | 25 +++++++++++++++++++++++++ mm/kasan/common.c | 6 ++++++ 2 files changed, 31 insertions(+) diff --git a/include/linux/kasan.h b/include/linux/kasan.h index de2a695ad34d..f8ebde384bd7 100644 --- a/include/linux/kasan.h +++ b/include/linux/kasan.h @@ -225,6 +225,9 @@ bool __kasan_mempool_poison_pages(struct page *page, unsigned int order, * This function is similar to kasan_mempool_poison_object() but operates on * page allocations. * + * Before the poisoned allocation can be reused, it must be unpoisoned via + * kasan_mempool_unpoison_pages(). + * * Return: true if the allocation can be safely reused; false otherwise. */ static __always_inline bool kasan_mempool_poison_pages(struct page *page, @@ -235,6 +238,27 @@ static __always_inline bool kasan_mempool_poison_pages(struct page *page, return true; } +void __kasan_mempool_unpoison_pages(struct page *page, unsigned int order, + unsigned long ip); +/** + * kasan_mempool_unpoison_pages - Unpoison a mempool page allocation. + * @page: Pointer to the page allocation. + * @order: Order of the allocation. + * + * This function is intended for kernel subsystems that cache page allocations + * to reuse them instead of freeing them back to page_alloc (e.g. mempool). + * + * This function unpoisons a page allocation that was previously poisoned by + * kasan_mempool_poison_pages() without zeroing the allocation's memory. For + * the tag-based modes, this function assigns a new tag to the allocation. + */ +static __always_inline void kasan_mempool_unpoison_pages(struct page *page, + unsigned int order) +{ + if (kasan_enabled()) + __kasan_mempool_unpoison_pages(page, order, _RET_IP_); +} + bool __kasan_mempool_poison_object(void *ptr, unsigned long ip); /** * kasan_mempool_poison_object - Check and poison a mempool slab allocation. @@ -353,6 +377,7 @@ static inline bool kasan_mempool_poison_pages(struct page *page, unsigned int or { return true; } +static inline void kasan_mempool_unpoison_pages(struct page *page, unsigned int order) {} static inline bool kasan_mempool_poison_object(void *ptr) { return true; diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 9ccc78b20cf2..6283f0206ef6 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -439,6 +439,12 @@ bool __kasan_mempool_poison_pages(struct page *page, unsigned int order, return true; } +void __kasan_mempool_unpoison_pages(struct page *page, unsigned int order, + unsigned long ip) +{ + __kasan_unpoison_pages(page, order, false); +} + bool __kasan_mempool_poison_object(void *ptr, unsigned long ip) { struct folio *folio; -- 2.25.1