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: 110154 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp3225559vqr; Mon, 19 Jun 2023 13:05:26 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ44XlCedXjjKXRp4SepgZrN5/wiqbdQdHWjK2iO7Ui1Ye4qn4v2kMQ/oULuotjQKMCgtK2R X-Received: by 2002:a17:90a:4ec3:b0:25b:ec3d:b687 with SMTP id v3-20020a17090a4ec300b0025bec3db687mr10277456pjl.37.1687205125983; Mon, 19 Jun 2023 13:05:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1687205125; cv=none; d=google.com; s=arc-20160816; b=n0k1rtWdmuDExrwFLHHzLeVBudYcpSnTniVYZyFBMgI1RjtT+aawohiWMHPC6a66xW 5iWi6xSKeND5YaRFxYfDaETZhhw3mQTSWh2Fl0Ego4h+xFKmCYs2EWcWTyk8KynPZwY5 tI7qYtjxB4tHktBHgklgRjCNgGPVlGpyjmGSdb6LfZvU7oMFUzd1SHWduE4VrHLQYJyI SZC8L8DZBvTDhFVfzxKRle8xmtbvx1yIHpUUiEWz1Gg9bsF6NdSLuwfO2YV7kW+GlxMv LRDBs9xL9Cz41Faa0StBwcjattCmiasVDJf//LGfRkeaBVl5pEvOVNiyH13PcErL/emm bNsA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=HCw2VH+vwapV6l/h+dF5z2IFI4Xz0i/+vWzvGaN0ULY=; b=y+r2yD4brMnUISri8y9eghPYLivgCTxS4xqLtWXVaE0pUdsYzcHEqWCtMJAOLqx3po ZmZ6IlbcrX6558emHxS3II/pU4dTwDDniNL1HLIfIskQEhbexIo0DHBEnhD4WftKj48s rDL559wjArb0j0WyvVxoYR3EfyTtSm8JbSIhHK5VlvxgwqNatsdsXyKVGWri+dScs31k ze4P5tUF++3yRfJQOFeGKh55v5dfXkKgf8YUFwhhOl56iyJkSo4R4gEAdO0ewPat7lBP aXkGl+dKqlrCU8juJ6mJwPLZvQmewG6CJtG57NDSlD8INX8JOkG6W24dzGl410WkKIiG 4bxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="ob9C8F/z"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 34-20020a17090a0fa500b0025bf9d28b28si374988pjz.104.2023.06.19.13.05.10; Mon, 19 Jun 2023 13:05:25 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b="ob9C8F/z"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230449AbjFSTih (ORCPT + 99 others); Mon, 19 Jun 2023 15:38:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230457AbjFSTie (ORCPT ); Mon, 19 Jun 2023 15:38:34 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CFBEDE71 for ; Mon, 19 Jun 2023 12:38:31 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id 3f1490d57ef6-be47a3b3a01so4003385276.2 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=KU6Rf0W2XM6w74mpGDxPiMJi+vN+m0noZYDC0fbq1+cLYSRBE2GKKyZNPW7ZUrH/kz lAYinRD7evuTrE3oJjgn1duJ0GTq7FLsdFqvenHojcZTsKot1o5L1Xr2+fzyMXGJRzWR vjne6Bfhu8XZH/Xw6VY1bHev0q1VF4BHmcLlPMw+wk+nAK4DFisyawCNAb+kaOUbQkPW /TjnN3f8V5uTVMDykF8vrdgj2UpK2PWh35s77gosSwkUWEy0Y1QM590Zr8hB/sNqUBwY TT84rVWLk9JMOyAZX48ai5ZqHchpsfKg03Kbpyk4EGCao5+gaXMHu0CmT+ydVTQbC3in GN8g== X-Gm-Message-State: AC+VfDwIKcmwPdjSE0Zdj1m/gv0eWjaRWGINW9eNX5gIwrtjw71H4YmZ QGV/Hfge/og+qdOZT6S+v+TbEloV3yA= 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-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL 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-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1769162802111199642?= X-GMAIL-MSGID: =?utf-8?q?1769162802111199642?= 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); } }