From patchwork Mon Jun 19 19:38:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yu Zhao X-Patchwork-Id: 13284895 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 B50BCEB64D9 for ; Mon, 19 Jun 2023 19:38:36 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 1F8EA8D0003; Mon, 19 Jun 2023 15:38:35 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1A8ED8D0001; Mon, 19 Jun 2023 15:38:35 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 071428D0003; Mon, 19 Jun 2023 15:38:35 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id EDE058D0001 for ; Mon, 19 Jun 2023 15:38:34 -0400 (EDT) Received: from smtpin15.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BA6E21C7BDF for ; Mon, 19 Jun 2023 19:38:34 +0000 (UTC) X-FDA: 80920509348.15.BF98891 Received: from mail-yb1-f201.google.com (mail-yb1-f201.google.com [209.85.219.201]) by imf23.hostedemail.com (Postfix) with ESMTP id 99AB0140018 for ; Mon, 19 Jun 2023 19:38:31 +0000 (UTC) Authentication-Results: imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="ob9C8F/z"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf23.hostedemail.com: domain of 3t66QZAYKCII405ngumuumrk.iusrot03-ssq1giq.uxm@flex--yuzhao.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3t66QZAYKCII405ngumuumrk.iusrot03-ssq1giq.uxm@flex--yuzhao.bounces.google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1687203512; 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-type:content-transfer-encoding:in-reply-to: references:dkim-signature; bh=HCw2VH+vwapV6l/h+dF5z2IFI4Xz0i/+vWzvGaN0ULY=; b=1PaAD8xncy6JUPJIGxSNA1WQnT6Mlq9xXGie8Hv4dvr7HOhjyat4F1u5yhU3vGU3OcsKi/ OI2UiGmJ9vLz0SWbjoywDcKWSNl1goj/2t6+Y/c3sX/MKWX4jR8w4jHzoNpYy5AzFqniRP 1bZLlKyOE7wgCQ2ujXqz4ty7x3lCogY= ARC-Authentication-Results: i=1; imf23.hostedemail.com; dkim=pass header.d=google.com header.s=20221208 header.b="ob9C8F/z"; dmarc=pass (policy=reject) header.from=google.com; spf=pass (imf23.hostedemail.com: domain of 3t66QZAYKCII405ngumuumrk.iusrot03-ssq1giq.uxm@flex--yuzhao.bounces.google.com designates 209.85.219.201 as permitted sender) smtp.mailfrom=3t66QZAYKCII405ngumuumrk.iusrot03-ssq1giq.uxm@flex--yuzhao.bounces.google.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1687203512; a=rsa-sha256; cv=none; b=WvJE5yWgGXaQ6434QrScV9xaPXpbY1sD1XrKc6Bfcwz4x3k8NG+yS1UG1p8vJdFeZ54j6l MrMn/nXp3Xt15BpqciedtnlriTjOra15MuqfuOu9ISrC7HtUh7p/3C1S2CzZTmzYeSpQOb KXF8HTkX2iP0kIHhnOxLsiUhjVdg2uI= Received: by mail-yb1-f201.google.com with SMTP id 3f1490d57ef6-bb2202e0108so4173430276.1 for ; Mon, 19 Jun 2023 12:38:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1687203511; x=1689795511; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc:subject :date:message-id:reply-to; bh=HCw2VH+vwapV6l/h+dF5z2IFI4Xz0i/+vWzvGaN0ULY=; b=ob9C8F/z7W2ZwmjqKz/Cvine6FVUEUnDsKk1zQIsGAIkjG83xxDJzueWto4L0n6VBq V0jkBXab7krBI+QchBRNdl5zRkUv1eEYXNfD54GlT4eg181CEItBbaNF2WGB6SkK9hWB alN+QbwXqOPTUwn3IOEBhW6FQ6gX1+KEah/ycaLWU4tl5xVPL4aJXhvXNAhDb92wLKgG JTv5Mp0z75TlwvOCjFlF6fz976sUTZfB1t/YeUx8BTpYTeRZaEJ7a9Gd6kCdydKWHfDx 4ZtGINXlu88f8GZnqSjrNh93MPA+YKVTVY4aOIaQXDRBafm7QJwqNuAvJ5Ho7Sr1UPRZ Q8WQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1687203511; x=1689795511; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=HCw2VH+vwapV6l/h+dF5z2IFI4Xz0i/+vWzvGaN0ULY=; b=Q1j6O/e9G0TvCepwSZI+MRXt6gO55Yz9YjChdqLhyzzhbbU2jMA5byLVcSYkVPLTpa XR01NEul8KSl/9JwORevBT/0En5gHr5hAzwf3kPIL1WTDZIZCmukgrYol2NavRH80236 EDyPwG9tIM4q2uRbiTnLIzQWwnHklC/mKAckdkbbliSAw85SrQEQyxBdUA2nzjJrg7Mf D/PICF+drpjyCS7+Kmvx5hfJ47zr0rdU/cDVeyrqGqJTZOyuO7oUcefbU5bdXBwpDUE/ KVyDvBK9RQU2q03UDC9bNfM50q9lLcpUg256apz7KowhWc9JXA4zzuAW7Fv9S76A1/KZ uiLw== X-Gm-Message-State: AC+VfDzOGmek0vO1VTxpyo68xdBqFIk3kXuwdY8wlvk1QWIC3M3ZsOk0 ecvXRkAQuHj2F9wEHqWxolj1B3ubJvE= X-Google-Smtp-Source: ACHHUZ5pfU5AaytiISOSDvFrNLXjh0g8DNDoFNsY2iGWO+BXyG7SrQ5ViqTG3yVka44liPSNzRY5KXR79KI= X-Received: from yuzhao.bld.corp.google.com ([2620:15c:183:202:6457:2153:f1fa:3f37]) (user=yuzhao job=sendgmr) by 2002:a25:23c1:0:b0:be7:ea0b:2702 with SMTP id j184-20020a2523c1000000b00be7ea0b2702mr1031854ybj.12.1687203511044; Mon, 19 Jun 2023 12:38:31 -0700 (PDT) Date: Mon, 19 Jun 2023 13:38:21 -0600 Message-Id: <20230619193821.2710944-1-yuzhao@google.com> Mime-Version: 1.0 X-Mailer: git-send-email 2.41.0.185.g7c58973941-goog Subject: [PATCH mm-unstable v1] mm/mglru: make memcg_lru->lock irq safe From: Yu Zhao To: Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, Yu Zhao , syzbot+87c490fd2be656269b6a@syzkaller.appspotmail.com X-Rspam-User: X-Rspamd-Server: rspam12 X-Rspamd-Queue-Id: 99AB0140018 X-Stat-Signature: zrjgacu86bx8koe97auq43byi64new6z X-HE-Tag: 1687203511-934239 X-HE-Meta: U2FsdGVkX1+6KKVy8qpeubKzzMDxVCu0aJiGh82q8sE5MJojbKkPEcWuCBiPxM6WFWIGAzLNTxskldYTnTjpc/8AJsPODZbjXLREepFj/yI0EoNe/Kg2IwSV0hFaP2u24VBDrwXb7kLQ2di3dSx00eKv98njm5T4/coZGpvvdkv4P9upV7hVCNQXrz7q3/7c9jMqWL7P7NV8qWymA7Djd5MaHNl+O/oi4AYPkG4STzBXhWcVNCmM4R8as+ujHtyIbxNeBkU4u8CJbqwUIhzhPQiYkX7Hs+AY7HYEc4LgDUWNsqvdL5XVOz+042hxoqrpj7tsASd/5ntiPXaJRIrRCTP9BemkXGsPZJxCv8IVPWvVOibJImXdBdpHM6e9qrs1RSsHtQpsY0nHQtv9eoXJHOx0/yCti15s16SYTa6X1PH72dQ8q4PpaDaqx4Lt4yBVUdi3G6mUoJq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nfG7HV8Dap+whMY6VM7z4tL5LeaLjRWsIEaa9ftEVykb8/UocTfVyVZPhKuOWdfiBssF7hotbDjX8eH+cF8Lq3yW73d1bNSanHkG1bWn1ucJunaE/Ea8wtDpyIDB+r478yD5CR1+H0g1gNzlEwkyNkTQ1f/ag5sAZTFVhO2Qp4HtA1GZ6a/08hp93eJAZUnqwJEXNYpU+xbRjWTfs2IoVZJd4R6DToNDBC4brKa1X4FphVhCakOb/YDR9ARWvTOCF2UF8f2cB/C5KmUWek8AZnJYZSLFuZ0sjrsUJ7GFlojzOIu1UAGJxjSuDDV5K9Lof/cOV0NuSWG9p/jgU= 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: lru_gen_rotate_memcg() can happen in softirq if memory.soft_limit_in_bytes is set. This requires memcg_lru->lock to be irq safe. This problem only affects memcg v1. Reported-by: syzbot+87c490fd2be656269b6a@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=87c490fd2be656269b6a Fixes: e4dde56cd208 ("mm: multi-gen LRU: per-node lru_gen_folio lists") Signed-off-by: Yu Zhao Reviewed-by: Yosry Ahmed --- mm/vmscan.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/mm/vmscan.c b/mm/vmscan.c index 45d17c7cc555..27f90896f789 100644 --- a/mm/vmscan.c +++ b/mm/vmscan.c @@ -4759,10 +4759,11 @@ static void lru_gen_rotate_memcg(struct lruvec *lruvec, int op) { int seg; int old, new; + unsigned long flags; int bin = get_random_u32_below(MEMCG_NR_BINS); struct pglist_data *pgdat = lruvec_pgdat(lruvec); - spin_lock(&pgdat->memcg_lru.lock); + spin_lock_irqsave(&pgdat->memcg_lru.lock, flags); VM_WARN_ON_ONCE(hlist_nulls_unhashed(&lruvec->lrugen.list)); @@ -4797,7 +4798,7 @@ static void lru_gen_rotate_memcg(struct lruvec *lruvec, int op) if (!pgdat->memcg_lru.nr_memcgs[old] && old == get_memcg_gen(pgdat->memcg_lru.seq)) WRITE_ONCE(pgdat->memcg_lru.seq, pgdat->memcg_lru.seq + 1); - spin_unlock(&pgdat->memcg_lru.lock); + spin_unlock_irqrestore(&pgdat->memcg_lru.lock, flags); } void lru_gen_online_memcg(struct mem_cgroup *memcg) @@ -4810,7 +4811,7 @@ void lru_gen_online_memcg(struct mem_cgroup *memcg) struct pglist_data *pgdat = NODE_DATA(nid); struct lruvec *lruvec = get_lruvec(memcg, nid); - spin_lock(&pgdat->memcg_lru.lock); + spin_lock_irq(&pgdat->memcg_lru.lock); VM_WARN_ON_ONCE(!hlist_nulls_unhashed(&lruvec->lrugen.list)); @@ -4821,7 +4822,7 @@ void lru_gen_online_memcg(struct mem_cgroup *memcg) lruvec->lrugen.gen = gen; - spin_unlock(&pgdat->memcg_lru.lock); + spin_unlock_irq(&pgdat->memcg_lru.lock); } } @@ -4845,7 +4846,7 @@ void lru_gen_release_memcg(struct mem_cgroup *memcg) struct pglist_data *pgdat = NODE_DATA(nid); struct lruvec *lruvec = get_lruvec(memcg, nid); - spin_lock(&pgdat->memcg_lru.lock); + spin_lock_irq(&pgdat->memcg_lru.lock); VM_WARN_ON_ONCE(hlist_nulls_unhashed(&lruvec->lrugen.list)); @@ -4857,7 +4858,7 @@ void lru_gen_release_memcg(struct mem_cgroup *memcg) if (!pgdat->memcg_lru.nr_memcgs[gen] && gen == get_memcg_gen(pgdat->memcg_lru.seq)) WRITE_ONCE(pgdat->memcg_lru.seq, pgdat->memcg_lru.seq + 1); - spin_unlock(&pgdat->memcg_lru.lock); + spin_unlock_irq(&pgdat->memcg_lru.lock); } }