From patchwork Tue Dec 19 22:28:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: andrey.konovalov@linux.dev X-Patchwork-Id: 13499301 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 3C996C46CCD for ; Tue, 19 Dec 2023 22:30:23 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9CE608D000B; Tue, 19 Dec 2023 17:30:22 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 8E0D68D0009; Tue, 19 Dec 2023 17:30:22 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 781128D000B; Tue, 19 Dec 2023 17:30:22 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 5F2D28D0009 for ; Tue, 19 Dec 2023 17:30:22 -0500 (EST) Received: from smtpin29.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay02.hostedemail.com (Postfix) with ESMTP id 2516012095D for ; Tue, 19 Dec 2023 22:30:22 +0000 (UTC) X-FDA: 81585012684.29.A803063 Received: from out-170.mta0.migadu.com (out-170.mta0.migadu.com [91.218.175.170]) by imf20.hostedemail.com (Postfix) with ESMTP id 661F31C002F for ; Tue, 19 Dec 2023 22:30:20 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=aMTrQUR0; spf=pass (imf20.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.170 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1703025020; 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=xReOl/oREsxJLQ8k6aIhVhARLuZMnM3hsCknlxTDelk=; b=w/v/DmigBUwrwUUScAXwczfCKn5efJ+dju0CSqWGwr3QD9p0J/xeB1mZ60jgOigbsxlN4I DqlOb09xLWZP/I/Jp+TOT2GYOvFtmXRJq7Z0vnU+jstF25im8MLaW3qYEoVI+79H5AIc4J c2smyOBccAiqIVYA+xNO0UcBBmv8uCE= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1703025020; a=rsa-sha256; cv=none; b=Okop2RaXskWYX2Flp+mj9LjHBC8gCMbqMYIMAaOSGKFDWj92w0noD+H+V3B9VhQkpyQh4M 8TK+BgZqKyBfeDKLFKMabb8RVJpNBNezslejxaul3cDJHKx7FU1AevaWdkctujN3Lgijec 1NCgLbTNq69WiB/QJFWT6qto4VBqUd8= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=aMTrQUR0; spf=pass (imf20.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.170 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev 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=1703025019; 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=xReOl/oREsxJLQ8k6aIhVhARLuZMnM3hsCknlxTDelk=; b=aMTrQUR0xLK7BplxYFtE4/Xbs25JDCetJWE5YR0p8XlsH+LA6uU4fkxqdQROa6y+LmxS6E H6/bMd8AJ43AJZtjVMsIrilr90PtruFOb4TzM1ChHIK5W2TnGpASFi8QvV447DisyRfhwH u+nqgpjQtRh+bJSPL6UUsX9RcwPAdbI= From: andrey.konovalov@linux.dev To: Marco Elver , Alexander Potapenko Cc: Andrey Konovalov , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Evgenii Stepanov , Breno Leitao , Alexander Lobakin , Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH mm 08/21] kasan: clean up __kasan_mempool_poison_object Date: Tue, 19 Dec 2023 23:28:52 +0100 Message-Id: <4f6fc8840512286c1a96e16e86901082c671677d.1703024586.git.andreyknvl@google.com> In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Rspamd-Queue-Id: 661F31C002F X-Rspam-User: X-Stat-Signature: mq1b8h9uz1qqz9rywcisazwj4ufiipn6 X-Rspamd-Server: rspam03 X-HE-Tag: 1703025020-986907 X-HE-Meta: U2FsdGVkX1+Y9YSFyUK5bo1UevsgYRWLtJHrByZCHI5f2y5eDKzMLkYW+AbcdtUJscuHR/dX/DnS2HBqT7nUvqDgBus6chXaG3UVEg5VrJ6Xs1H0ug75X5ru8O8WTYw6QvN+xTgALlYf9WIE62BqAV8JTpHgWIvEm6NouP5S4Ve13DmFq5rKc9c0t3MQ/DdDYPku08Msq1YZ49ykttFBPiAn6CdzgjfyW5hRu/o/ONGT7o3iQitB+2ck3HDxcz0gmrKOZ7nnsgXi98qYE8baUV/tMhCi2IpVOPCEQuUPqPaBfTOf0q5va0pXCatMJW7BgdohZ3sLOnuMIUzE6PiCk8rqSixRFhZO8P1Lh9LvUAzV7AY/fCMrwOLwFCMOuIbzPeKHTrH29D9xmhcpGho4LyaG3J9aZNjEtiDiR5vu4KnMpJqcTAokLiiJ7GR2iPUV6B5owCXUteDDlBojMkNSrdEDQ89SbO9t9lNb++6gmjo9hPCLcKg62VEDPpp4ov1q4tCK9njOoe74EEYj466IpE8aQ6+1LNrkLrQH5wlzJcLWIZ6nR7467eYbq32KaxC6nUg+0AgtIbesnySygTgAMt1LOozhvhQbHMtZM7ff16TziwGUpeZqB9VW0SPIsuRpksZtHIAVVIXSaB7VwQqNo5K9Vlas30vvOctneAMYNBqp8HyFPQ/1PDGVqIQ2vs/wdA0ykVvO1g3tjum2Cxh23/bTHCT5jcmmf7I5A018Rr6o4PAZcaM0q8h2Kt+7q9VFLPpj3xBlvX+mVyLxxogfiXgWyOMu892/kD8Ha/zsCoILr/Cly+M5TYAC0eBjsLLvSCNhJw0bPjAQgOqJXoqOdQTrwoVIvee/3ClazBsgs0Yp9GQHEi0AGLZpSchUJmrhCkhywmsPI1LateFZ2v35/7XQcJaINYJTWUt831O7mxouR6lCwjtSvhpAj437f5j83qeKE1sE4yNEnqKvBkU +lEJfHtu 9Fl/p4l5MbOBB6e9UB6XoMUjcODl59UIUhSM7hhOB32ZbuvSzHSKYIVzwtPRa6rxqSCmiYnXST8BoI9d0pjI23r8PP/2GyrDP9tBMjxBKfwSKrvU1DjfGPhZ3wwzlQ5VFVlyZdFU57FzBxsuL1i0qlZSOcPoouaV65C4HbJ/H4H1T13e/pXLrfpbupBF4L5jN2Sza+xHdx/Qaom56aj2U8noPsLwxMVuSJ6aJ 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: List-Subscribe: List-Unsubscribe: From: Andrey Konovalov Reorganize the code and reword the comment in __kasan_mempool_poison_object to improve the code readability. Signed-off-by: Andrey Konovalov --- mm/kasan/common.c | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/mm/kasan/common.c b/mm/kasan/common.c index 7ebc001d0fcd..3f4a1ed69e03 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -457,27 +457,22 @@ void __kasan_mempool_unpoison_pages(struct page *page, unsigned int order, bool __kasan_mempool_poison_object(void *ptr, unsigned long ip) { - struct folio *folio; - - folio = virt_to_folio(ptr); + struct folio *folio = virt_to_folio(ptr); + struct slab *slab; /* - * Even though this function is only called for kmem_cache_alloc and - * kmalloc backed mempool allocations, those allocations can still be - * !PageSlab() when the size provided to kmalloc is larger than - * KMALLOC_MAX_SIZE, and kmalloc falls back onto page_alloc. + * This function can be called for large kmalloc allocation that get + * their memory from page_alloc. Thus, the folio might not be a slab. */ if (unlikely(!folio_test_slab(folio))) { if (check_page_allocation(ptr, ip)) return false; kasan_poison(ptr, folio_size(folio), KASAN_PAGE_FREE, false); return true; - } else { - struct slab *slab = folio_slab(folio); - - return !____kasan_slab_free(slab->slab_cache, ptr, ip, - false, false); } + + slab = folio_slab(folio); + return !____kasan_slab_free(slab->slab_cache, ptr, ip, false, false); } void __kasan_mempool_unpoison_object(void *ptr, size_t size, unsigned long ip)