From patchwork Sat Nov 26 19:12:13 2022 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: 13056559 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 D66A5C4332F for ; Sat, 26 Nov 2022 19:12:18 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 394986B0072; Sat, 26 Nov 2022 14:12:18 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 344626B0073; Sat, 26 Nov 2022 14:12:18 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 233FC6B0074; Sat, 26 Nov 2022 14:12:18 -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 13EAC6B0072 for ; Sat, 26 Nov 2022 14:12:18 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D478DA737F for ; Sat, 26 Nov 2022 19:12:17 +0000 (UTC) X-FDA: 80176539114.22.8FEB7E2 Received: from out-178.mta0.migadu.com (out-178.mta0.migadu.com [91.218.175.178]) by imf10.hostedemail.com (Postfix) with ESMTP id 665D6C0005 for ; Sat, 26 Nov 2022 19:12:17 +0000 (UTC) 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=1669489935; 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=Mld0Zf5BHHuTHmAamXf8kUapqnIfndf6LF73jgEUyOU=; b=JRT26BDvFyqYcCreQlbv+eRunjXarfdLgSQrSIN61868nvVAbKFfzCAPXP1pu6+7vfuQdd WyQDQUFYp/RCMRU6uZHcxzmr1bgQox4v5SK5bCluwdnbKPLCHupa2a077vEk/OaK8sx4/z /EOB1zmujUK1lo/QM2FLlP61uFm+QVU= From: andrey.konovalov@linux.dev To: Marco Elver , "David S . Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: Andrey Konovalov , Alexander Potapenko , Dmitry Vyukov , Andrey Ryabinin , kasan-dev@googlegroups.com, Peter Collingbourne , Evgenii Stepanov , Florian Mayer , Jann Horn , Mark Brand , netdev@vger.kernel.org, Andrew Morton , linux-mm@kvack.org, linux-kernel@vger.kernel.org, Andrey Konovalov Subject: [PATCH v2 2/2] net, kasan: sample tagging of skb allocations with HW_TAGS Date: Sat, 26 Nov 2022 20:12:13 +0100 Message-Id: <7bf26d03fab8d99cdeea165990e9f2cf054b77d6.1669489329.git.andreyknvl@google.com> In-Reply-To: <4c341c5609ed09ad6d52f937eeec28d142ff1f46.1669489329.git.andreyknvl@google.com> References: <4c341c5609ed09ad6d52f937eeec28d142ff1f46.1669489329.git.andreyknvl@google.com> MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=JRT26BDv; spf=pass (imf10.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.178 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1669489937; a=rsa-sha256; cv=none; b=BE97ygqnwEnATBe3VYjibB93gM4Y914pU2PT6+5t/N8189INkDdW0MpHjnetCpypT6bA7W +zCW8kHZxNyBvzHeNShklWA9P6FGs6dnrGz0SSstTYVh6G4/74xnPIQEQhXfhKfPSNQm2K AXrgdPna/u/3XQhveELKyzYXpxkIrsU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1669489937; 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=Mld0Zf5BHHuTHmAamXf8kUapqnIfndf6LF73jgEUyOU=; b=avhIcI7eJ692su/Y1LX7sWV7xTsjnQ8v4/ovmbXmjWgp3EGUf64C7Ume0vvBIuXMvQesH7 uj0VbfwOqFz3kfQ4E/xOiqCEJgbVrBcyRzr8coxR402KIP981jC0T6XDT1v6wf6zDtYYMH J2Qxb1xl5s5Lxm1nNg0CNZt00ib6I4w= Authentication-Results: imf10.hostedemail.com; dkim=pass header.d=linux.dev header.s=key1 header.b=JRT26BDv; spf=pass (imf10.hostedemail.com: domain of andrey.konovalov@linux.dev designates 91.218.175.178 as permitted sender) smtp.mailfrom=andrey.konovalov@linux.dev; dmarc=pass (policy=none) header.from=linux.dev X-Rspam-User: X-Rspamd-Queue-Id: 665D6C0005 X-Rspamd-Server: rspam01 X-Stat-Signature: 4gq68b8bep39jn1bhz67ytn6gxecip7k X-HE-Tag: 1669489937-352894 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: From: Andrey Konovalov As skb page_alloc allocations tend to be big, tagging and checking all such allocations with Hardware Tag-Based KASAN introduces a significant slowdown in testing scenarios that extensively use the network. This is undesirable, as Hardware Tag-Based KASAN is intended to be used in production and thus its performance impact is crucial. Use __GFP_KASAN_SAMPLE flag for skb page_alloc allocations to make KASAN use sampling and tag only some of these allocations. When running a local loopback test on a testing MTE-enabled device in sync mode, enabling Hardware Tag-Based KASAN intoduces a 50% slowdown. Applying this patch and setting kasan.page_alloc.sampling to a value higher than 1 allows to lower the slowdown. The performance improvement saturates around the sampling interval value of 10, which lowers the slowdown to 20%. The slowdown in real scenarios will likely be better. Signed-off-by: Andrey Konovalov --- net/core/skbuff.c | 4 ++-- net/core/sock.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 88fa40571d0c..fdea87deee13 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -6135,8 +6135,8 @@ struct sk_buff *alloc_skb_with_frags(unsigned long header_len, while (order) { if (npages >= 1 << order) { page = alloc_pages((gfp_mask & ~__GFP_DIRECT_RECLAIM) | - __GFP_COMP | - __GFP_NOWARN, + __GFP_COMP | __GFP_NOWARN | + __GFP_KASAN_SAMPLE, order); if (page) goto fill_page; diff --git a/net/core/sock.c b/net/core/sock.c index a3ba0358c77c..f7d20070ad88 100644 --- a/net/core/sock.c +++ b/net/core/sock.c @@ -2842,7 +2842,7 @@ bool skb_page_frag_refill(unsigned int sz, struct page_frag *pfrag, gfp_t gfp) /* Avoid direct reclaim but allow kswapd to wake */ pfrag->page = alloc_pages((gfp & ~__GFP_DIRECT_RECLAIM) | __GFP_COMP | __GFP_NOWARN | - __GFP_NORETRY, + __GFP_NORETRY | __GFP_KASAN_SAMPLE, SKB_FRAG_PAGE_ORDER); if (likely(pfrag->page)) { pfrag->size = PAGE_SIZE << SKB_FRAG_PAGE_ORDER;