From patchwork Wed Jan 15 02:17:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Alexei Starovoitov X-Patchwork-Id: 13939763 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 4B0EFE77188 for ; Wed, 15 Jan 2025 02:18:25 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D80A6280004; Tue, 14 Jan 2025 21:18:24 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id D305F280001; Tue, 14 Jan 2025 21:18:24 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BD113280004; Tue, 14 Jan 2025 21:18:24 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id 9C2FA280001 for ; Tue, 14 Jan 2025 21:18:24 -0500 (EST) Received: from smtpin11.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay10.hostedemail.com (Postfix) with ESMTP id 4D059C0F3D for ; Wed, 15 Jan 2025 02:18:24 +0000 (UTC) X-FDA: 83008076928.11.529334C Received: from mail-pl1-f174.google.com (mail-pl1-f174.google.com [209.85.214.174]) by imf20.hostedemail.com (Postfix) with ESMTP id 6C5851C0013 for ; Wed, 15 Jan 2025 02:18:22 +0000 (UTC) Authentication-Results: imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="B8i/k22B"; spf=pass (imf20.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1736907502; 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=Q8dNygR7UFFvbzRNwqjbILq73kIw4oFHXTY0L0penA8=; b=aC1cvuX1qPfTd6JugVslW+ISKeQStWTbzrjctbA/MxXXHNwkYh5XGH6/9gWMTsBBiGFAq6 p2NMW6GlbJot5ngDuFiI8SeP/tXUxop4HJgIW3bLTzMpGEBXl1gO2eYh2lUo+C9rNU7LSB mVKreMjUktllml9aTFSWesa9KLogPWY= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1736907502; a=rsa-sha256; cv=none; b=uKAKphXWYJUJFT/2CH4cR0I7bCOiIzBNjZ595kajDHSRcV8pnBQMcOsmV2I5jCLG5Cx8cb PMQV+gTjUtt4zW7FEnqtyr4LLNVtxFs061mMSaBW3GqawCZmnhtBn6aPl7lNDgKMFquEwp zsfx/A8WLJ9jF5OKXQk0ixx5/fEg+8c= ARC-Authentication-Results: i=1; imf20.hostedemail.com; dkim=pass header.d=gmail.com header.s=20230601 header.b="B8i/k22B"; spf=pass (imf20.hostedemail.com: domain of alexei.starovoitov@gmail.com designates 209.85.214.174 as permitted sender) smtp.mailfrom=alexei.starovoitov@gmail.com; dmarc=pass (policy=none) header.from=gmail.com Received: by mail-pl1-f174.google.com with SMTP id d9443c01a7336-216634dd574so72639865ad.2 for ; Tue, 14 Jan 2025 18:18:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1736907501; x=1737512301; darn=kvack.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Q8dNygR7UFFvbzRNwqjbILq73kIw4oFHXTY0L0penA8=; b=B8i/k22BOze87K4uHhju5n5/JfxxLk1KisMvCb3QKw9hO5fK8uF/aRM8xd6z0dHeQh XT0tFYW2EghiG+h7bmnB55xTpPnWSyB37WETNTNWKvUE6KIL+ft4gQfJqCUvIAj4EF9t ZVsqKSV9032pz61aJYva1NF/o532I02iOXy0qLtkm7gEp7WL1GyyxL74E5GjdzxW+Ft6 l48jZi38USZi0IqyBdefS7zLT6S6oh2o0hAh1LCekOHk+Otfc2REgNBAUyMSS+gObdWt XNEELopaCXnA8NVPkv+lQMJ841Hc6z/Jp4G3qGW3fufXJcHYgqGPgTxwdZhtDUXXKkEX cGdg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1736907501; x=1737512301; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Q8dNygR7UFFvbzRNwqjbILq73kIw4oFHXTY0L0penA8=; b=gLmoXMGECXeoHsz3w52Q3Fgy/fAROTLpylBWmohzGRIk9Nj7HS/l+/Zgc/DtMCy02P 54RJKIkrHnZPoZ8+6aonO1Cj0ywHsoxW3fSpWdZdHCrLACtMxy21QlWs1z4W7RIsTJcz ZeEmXvxNWRynUXJsCihdhMc2XkbcDZpzVhf4cJa0A8oSXiybKw8Wy2I3eR1n/yZCni+j WD4wr6tD+K2rTZW4q3kOKXLXc4kP6wPa4dWbKqbwwIq44ArNythnEnSes6cnAbz0i9FT VnTkDsRgM03yq1m7xvRxIkxh+aslHs24GTnL8dv+D0I6UJz3C6kOfuvOF+T7vRKgdkho 8eAA== X-Forwarded-Encrypted: i=1; AJvYcCXIq25mkq4wM8DEAM+iVWQtiu3SsNaJWSkZIo0z3tMFYTOaXDN4yqQlnVx3oAAr70NBeGowS9XmlA==@kvack.org X-Gm-Message-State: AOJu0YxqmoP/CYGq8Ngnx0jgvyIx5L/JXE4Bbs3oCUceYqmxiEGZhTyk IcOz80jT9e/Jr4cQvdpYWhQPLOOd37Ljh2TKS8fuV/RDGOQQ7nxK X-Gm-Gg: ASbGncuHbas34VOHKMkGc7FEuNLDMMSoAzNVZVKeLbMoLo7cXm3j1rblk9apFs0nqsC MVTwmZ1LCai2GyRmAQt4x81KQwH+ya75J8u3kkagjq/Tnr84Gk4TiFxWM4FtcFt2jAb2xRDMUeu K/nuGwrXCshliUobKNKZLOq6OkY2lELAcbGx1V5ce+d7OQ4RjYObdtqvOb9hF+H49pPmdlx4zzN nF8MZQ1T3FFOUehl5LnErecXp3B+D1AEVPeyUS5tXIaoTgo9HtdlKWrYGBiS2lkcBemQSh93ZRS 5lRLTeig X-Google-Smtp-Source: AGHT+IFwyv6v50tn9W5bSyzXASzJW2tC+n3Yvr284DWZQwO0ZzTjXDMbHxo/pZeBv3MUI9+RJdh/7w== X-Received: by 2002:a17:902:cf0b:b0:215:431f:268a with SMTP id d9443c01a7336-21a83f647e1mr449439745ad.31.1736907501257; Tue, 14 Jan 2025 18:18:21 -0800 (PST) Received: from localhost.localdomain ([2620:10d:c090:400::5:4043]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-21a9f254040sm72719235ad.232.2025.01.14.18.18.19 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Tue, 14 Jan 2025 18:18:20 -0800 (PST) From: Alexei Starovoitov To: bpf@vger.kernel.org Cc: andrii@kernel.org, memxor@gmail.com, akpm@linux-foundation.org, peterz@infradead.org, vbabka@suse.cz, bigeasy@linutronix.de, rostedt@goodmis.org, houtao1@huawei.com, hannes@cmpxchg.org, shakeel.butt@linux.dev, mhocko@suse.com, willy@infradead.org, tglx@linutronix.de, jannh@google.com, tj@kernel.org, linux-mm@kvack.org, kernel-team@fb.com Subject: [PATCH bpf-next v5 6/7] mm: Make failslab, kfence, kmemleak aware of trylock mode Date: Tue, 14 Jan 2025 18:17:45 -0800 Message-Id: <20250115021746.34691-7-alexei.starovoitov@gmail.com> X-Mailer: git-send-email 2.39.5 (Apple Git-154) In-Reply-To: <20250115021746.34691-1-alexei.starovoitov@gmail.com> References: <20250115021746.34691-1-alexei.starovoitov@gmail.com> MIME-Version: 1.0 X-Rspamd-Queue-Id: 6C5851C0013 X-Rspam-User: X-Rspamd-Server: rspam07 X-Stat-Signature: hbc8rp48koa76qexjqqqdpxssuaw381p X-HE-Tag: 1736907502-276048 X-HE-Meta: U2FsdGVkX1+jjXX1WhTWqah0vd1WuiRpF9ZeASINKCvhhWMLrAfmN7ebnMqWb1JeedQRQ5PUHAR8mjwF6iXwogcSnt//HAU5sPIRQHkoTAQvS8zrsmMYUBvn5CZHicIiPYxYNosHb3/fR0r/lFIr9VtpO+uhQrMMjLB4IzWCHZw7qBr9eCYs5PZ3zwY+NMojqcqMry2T1oEzQGIRVQo3/LzFQ+6+41Lr4To/hUSUVUK5+He/DoCC5D5khvm1Mhc3TOjlD2GXZIpvD027bHlAXmjNlGdMDKeKwkX3VkQjEm7r2JSCpTRYfY51UP17aD1v5cJu4igFDgOAiEaNcQ97Ix+SaSTf74xvuELkHZArIE7t0WFycK7uB5ifvlWZVOZ3gMYAlmut8lcjxOyLr9kLb3cPFoMknNkyInReHzjSqxIl/yqRzqB9IlGqX0t/7kxaTXBjxk7DezwWfg8HKcgG0Ydm28VhrPGwyhQhwqmLqyphofg9qLBohbyu2JwhWPniDgxxxTYF8j8OmKtBiMGMIUtJtPd/UQQ+CvhLD8JtVYfAZamNs0YMTaQZ6EqrizSW+kDd5S+94uKeiHPsqmnKjX6aUZGjScM+EZk3Y+xiGD9cxIDCZ6xW7Z8X1XSokfHJ0BxLH9ZWVhvaqyHiBoVkODmDgldk9oDUjR8zGGgOHtGXRLAoG4ALbZt0NwBJaZNQRRmz+sKIy9sM4soKrdVPhILmdbWGj8Pk2TDTeMoBsAECKcxcwV//h1fUOzUBaqDcCkiLv3zBJ77NfxD21v0VZTlbuiVrSDl3IXTp5Hm2LWX8zwekuTGyQF0EcFo1ONTue/kgRHw9xnvY1lSXSvNj9ScNmuRSipPFT+X6WUTwKJG0Kut/W/5ywWId1pcePEJ8MnD2w1aMvi7KmC1B31NBvhpnMweL8Q1KrWxoZwzfIWhp+vqLDxZ4OtUOxzPrjf0ABKIXqEzBC3qPZMUfaTU kLc9CSDE AGWMBg7bGkjVnmXoEOAe7s5VG/vWzf7+d6Gjff498ZX9ryJ+c+DcmgkZYsWcwrZn0614/iJ5uXw74LHPzb0yo7eq0l0Y67pLEk9x7J5kuF8AfRTWTpjzqthVREOAz26aAmx0mi0PwEfcXnsZX54HK3vmD/Pbs8xIKjvSibE38EjUW6SSMBgGxvrv0Bmwbx+U6HwpRgrIDof+i7DMcXKaDK8/d7ESgwElD3PwWnbVemZDVsgDs+xP3yxqJtjRcQHxuNs3JxMVLOZKfpIzAk/65ZaQPvaJbX4y5pYyQf/Ik8G0T/pSNUFZDx8SMTtV9SKTgj/W6ZF8x2g0eRETe1D4B6Qq1YI9BN1WprFd2R9V5b1UFRbflYwW5tBKT9cOdCYrJVwEYE3GfvWVAMUz8ZqGs+dcF93/pXFv9WRMpe/fGz3o1MSjL1cqT2Js7CPCY83nJl3ONIIcuhh00iZM= 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: Alexei Starovoitov When gfpflags_allow_spinning() == false spin_locks cannot be taken. Make failslab, kfence, kmemleak compliant. Signed-off-by: Alexei Starovoitov --- mm/failslab.c | 3 +++ mm/kfence/core.c | 4 ++++ mm/kmemleak.c | 3 +++ 3 files changed, 10 insertions(+) diff --git a/mm/failslab.c b/mm/failslab.c index c3901b136498..86c7304ef25a 100644 --- a/mm/failslab.c +++ b/mm/failslab.c @@ -27,6 +27,9 @@ int should_failslab(struct kmem_cache *s, gfp_t gfpflags) if (gfpflags & __GFP_NOFAIL) return 0; + if (!gfpflags_allow_spinning(gfpflags)) + return 0; + if (failslab.ignore_gfp_reclaim && (gfpflags & __GFP_DIRECT_RECLAIM)) return 0; diff --git a/mm/kfence/core.c b/mm/kfence/core.c index 67fc321db79b..e5f2d63f3220 100644 --- a/mm/kfence/core.c +++ b/mm/kfence/core.c @@ -1096,6 +1096,10 @@ void *__kfence_alloc(struct kmem_cache *s, size_t size, gfp_t flags) if (s->flags & SLAB_SKIP_KFENCE) return NULL; + /* Bailout, since kfence_guarded_alloc() needs to take a lock */ + if (!gfpflags_allow_spinning(flags)) + return NULL; + allocation_gate = atomic_inc_return(&kfence_allocation_gate); if (allocation_gate > 1) return NULL; diff --git a/mm/kmemleak.c b/mm/kmemleak.c index 2a945c07ae99..64cb44948e9e 100644 --- a/mm/kmemleak.c +++ b/mm/kmemleak.c @@ -648,6 +648,9 @@ static struct kmemleak_object *__alloc_object(gfp_t gfp) { struct kmemleak_object *object; + if (!gfpflags_allow_spinning(gfp)) + return NULL; + object = mem_pool_alloc(gfp); if (!object) { pr_warn("Cannot allocate a kmemleak_object structure\n");