From patchwork Mon Nov 6 20:10:17 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: 162163 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:8f47:0:b0:403:3b70:6f57 with SMTP id j7csp2902061vqu; Mon, 6 Nov 2023 12:11:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IEiPR+h/fPgNLmE3Ck//axkZBvQ9EfMYKYCGY2Nh3tdakTs0yYHBO0pGRgd9KWwlL4/LL1x X-Received: by 2002:a05:6870:1792:b0:1e9:c28f:45b9 with SMTP id r18-20020a056870179200b001e9c28f45b9mr855780oae.19.1699301517939; Mon, 06 Nov 2023 12:11:57 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1699301517; cv=none; d=google.com; s=arc-20160816; b=hwkWCbY5cu4iJPIU4/xtj/BlEpiZtLOILXtdiSUj4QiSqCv9WMFIeyl2SCE9uCrFTP lrOVGasQmDvD8yvs4AguWNoWXsmfN6HsQ9gwLruQ39qrDerv+AVqNcqvMEJ7VKIB5kRV bFjnIIN6dqJxOfY2RnFIfu7WucePzf1Iv7EWA2gncT4CREi1049rwpITyY+yaZRMMso2 LASVvZa0XGf/PAqbPLKCW+AdO1VYRM3FM6vLkr191BcqmNwXghezWamRI4fhF+Gmbw1I fWhIAaa0BSMU8HCT7IGeLIn1wDCmNpOO+doEwMHzkhy02D1abu4uvjxft6qGl8dzrt5X 2b8A== 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=XVuFmnWl7Ai+GOwJv1yuDcJd9SrRUciNhjDptmGZnZI=; fh=n5KN85tQTomq0Sa/nFFC9xbnc77mxkBzF8HoolO/QOw=; b=iZ9/QislLjNyzd5PQwaeW7FgK7VOxWJVF9V9/CNPbjSL2FoUCGruk4xq0nNfu+97dM 3/ROWrrhm0Pc7vkr7IrgyvadfbpUDBPHXYUedwOC0BGjxFx+hx4OalRyP4v+eYT5vNU1 Gx1fUM+XMXiPYxUgjbtTo+Rn29oPJZMagDdPp3zF/0FLyXvc6/vIgjqy7qVBpEKxay61 rY5mdzXwSezpeavVbMfRkjdwUjQdszuxBO0i/sQuJ4dn+JVlOdqhDTnxHYDzLuvhx5IU gakwn88DGjuACwnPS0YqFvz4PZNbaQNCao3y8uqalqiq97Oo78POp0jo4TmyYMMaqTvu ASGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=vvDAFFN6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (snail.vger.email. [2620:137:e000::3:7]) by mx.google.com with ESMTPS id k16-20020a635a50000000b00578fe1bdfcasi387055pgm.860.2023.11.06.12.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Nov 2023 12:11:57 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 as permitted sender) client-ip=2620:137:e000::3:7; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.dev header.s=key1 header.b=vvDAFFN6; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:7 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 snail.vger.email (Postfix) with ESMTP id 1C8258087275; Mon, 6 Nov 2023 12:11:57 -0800 (PST) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233023AbjKFULx (ORCPT + 34 others); Mon, 6 Nov 2023 15:11:53 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41126 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232940AbjKFULp (ORCPT ); Mon, 6 Nov 2023 15:11:45 -0500 Received: from out-184.mta1.migadu.com (out-184.mta1.migadu.com [IPv6:2001:41d0:203:375::b8]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B10210C9 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=XVuFmnWl7Ai+GOwJv1yuDcJd9SrRUciNhjDptmGZnZI=; b=vvDAFFN6FcYKWYAGx5sCoYZo2aE996ZHT27ORsBGzAXwAllc9a/mweQGGLH+tNqC9ukgoo kfT6X1bqAgw8fHV/cuj8owqV2YMiINk9I1HHRRwNCkZiOyFphUoExea/Wc88Wdh/Xw3yFD ieHf70kObAwysIDH+u5fgJoaxYfbcAM= 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 08/20] kasan: clean up __kasan_mempool_poison_object Date: Mon, 6 Nov 2023 21:10:17 +0100 Message-Id: In-Reply-To: References: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net 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 (snail.vger.email [0.0.0.0]); Mon, 06 Nov 2023 12:11:57 -0800 (PST) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781846788000583639 X-GMAIL-MSGID: 1781846788000583639 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 6283f0206ef6..7c28d0a5af2c 100644 --- a/mm/kasan/common.c +++ b/mm/kasan/common.c @@ -447,27 +447,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)