Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp5416601iog; Wed, 22 Jun 2022 19:56:25 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s9/R+NpQ0EXkv8ku54+irUO8NXbX5CxMo9nVGfC1NQDuWCX0yNkUcWJAuAghP+P/9PI0VK X-Received: by 2002:a17:906:4f:b0:712:af2:29d9 with SMTP id 15-20020a170906004f00b007120af229d9mr6101492ejg.751.1655952984839; Wed, 22 Jun 2022 19:56:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655952984; cv=none; d=google.com; s=arc-20160816; b=tVrXtq8qxIl31B0U9naaldqZFjK30uSRs+Z7TlRLl322ch0/NN1Kln85l4k5kp2zV2 AOyvJGzdgTeVG2Zt2dX8yYOIF+s29SG0Hjzlp0FtxGqPJHqTSZuyq/CiafRfZDRuwzSR uIa0aj1pbnJCEUVr1bWFO/8CuVLO5BHU1kxcsdLVMwBUBu6nhu/fqojSfegYUOQCxLnh mz3X3txVMAHv6YtmFXyWC96se9XVS8mPsUMmxl2L4lPMM0Y9NeNqxcfDuBFw/gp179Ae iMD2mu0C51quyDpEq6vVLAI1Zav2h5T1zDqIWPSR3o/cUllIlSSdusN5emoRgsVyA5OH XJwQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=ap/l5/DtRvj53V2CP02OCV8Y9yv6B47W9rFtmSDPxls=; b=bVl+242ksjOCo/t9HK4gWnbl9iDA8uMk0X9ltNFhbvRSJu9C6AW+Lr32wMpkHmgW6m uk5+m4sCdS2HhvDM8nVvu+qXBLjmHfVX93Fn5MEGPCj97UgOLo1BYLX1zb6VOYP1ALyF MGhSSP8Hw7X5g8nnjh+rfJ39A+Db4U+nqeMDI886wSlTswYyPMiLp456beLdZJBsm/zB Ig4+oL0pS301Xfe0cwvylM73lwWCEB4+AsnBH+ilAMZ3eLVB++Q7H5UYhK057hp5wkWR vM1/sQ1yFkzYxYeRoYqu6e4IkYaTsyGrQFFVMmdKOW1WS1o1FhxpkGjkLLcSQus9rYgR +8Ww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=FpOyHo8x; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 6-20020a17090602c600b00707dfcfc53asi7386422ejk.411.2022.06.22.19.55.58; Wed, 22 Jun 2022 19:56:24 -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=@bytedance-com.20210112.gappssmtp.com header.s=20210112 header.b=FpOyHo8x; 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=fail (p=NONE sp=NONE dis=NONE) header.from=bytedance.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231344AbiFWCg0 (ORCPT + 99 others); Wed, 22 Jun 2022 22:36:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41750 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229615AbiFWCgZ (ORCPT ); Wed, 22 Jun 2022 22:36:25 -0400 Received: from mail-pl1-x632.google.com (mail-pl1-x632.google.com [IPv6:2607:f8b0:4864:20::632]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF7C43BF91 for ; Wed, 22 Jun 2022 19:36:24 -0700 (PDT) Received: by mail-pl1-x632.google.com with SMTP id d5so16936794plo.12 for ; Wed, 22 Jun 2022 19:36:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bytedance-com.20210112.gappssmtp.com; s=20210112; h=message-id:date:mime-version:user-agent:subject:content-language:to :cc:references:from:in-reply-to:content-transfer-encoding; bh=ap/l5/DtRvj53V2CP02OCV8Y9yv6B47W9rFtmSDPxls=; b=FpOyHo8x4jGy05YG6pNB+UTP0d2tDbI8uK8nVnAfyLYHadT0jVXhh164JY6S+Y4Ets StuLbjcpbIXgQfPPKNHjHdrFuZxp/1vsrAwNf+MIRPoxcw2kOtZI+0qyHYG4PtWf4EGZ 4YX3AIDmZ0EnsgevwSnayUEl1nJyIOGwjXbMlMLWZ8+We04oQ2oKyh0YzlwFBT2uW/5m sW28f3aZPh+rREYYdhaXmB1yj66IS6Pe9Nx5ez8jz2nMgKIo8SrdNIPH5bvcUB5LURHZ klTqDnqyx8w+fAKTMzbI11ocnkMFpG+Hji/l7D7R1aVizV0BooQ27c5D+vlP5GNpleON NAIQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=ap/l5/DtRvj53V2CP02OCV8Y9yv6B47W9rFtmSDPxls=; b=VfWfIHoW5QJH91XQBh1OlHy4W3Kww4Mo3zKq2WOMImKN3kn8Ovpn+Ag1lhsdA0+Jbl OPjMjGG4Minqj1Onti9J/7jsRNQIXuBxIaeskmGBsOMvGzmo+2slbyjgbIOLerrKVU4U QZH9s58zBf1suNjRe/3MkfTrGo5YE9gm10M2yNTTxe+Zntfr6CqJyjZZsY9H1o1H+43L YahNRPGmavuc5EDDsezVKYQ+l8Qfc3WDWbkrmPWVA8qfRJCXBBNkhhoQccYrGw1AO0Ad IperJ9SpDcN8d5OnT2EsRpbGvy4trYRYSYPcU0FfPQP7rqR/BtptxmnHupu70e7bWhXO ImDA== X-Gm-Message-State: AJIora/X3xrdxr1+bzx2b23x9xiXA3fddzaseXWeWoZO2oFvbEtS/42I mz+kf/lgvwomH01yai1ofuFhuw== X-Received: by 2002:a17:902:f60d:b0:16a:1a7f:a22f with SMTP id n13-20020a170902f60d00b0016a1a7fa22fmr21280279plg.13.1655951784244; Wed, 22 Jun 2022 19:36:24 -0700 (PDT) Received: from [10.4.214.173] ([139.177.225.237]) by smtp.gmail.com with ESMTPSA id a13-20020a1709027e4d00b0015e8d4eb26csm13583831pln.182.2022.06.22.19.36.12 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 22 Jun 2022 19:36:23 -0700 (PDT) Message-ID: <2d607f47-71fa-9505-b355-7203eb327bab@bytedance.com> Date: Thu, 23 Jun 2022 10:36:10 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:91.0) Gecko/20100101 Thunderbird/91.10.0 Subject: Re: [PATCH v12 12/14] mm: multi-gen LRU: debugfs interface Content-Language: en-US To: Yu Zhao Cc: Andrew Morton , Andi Kleen , Aneesh Kumar , Catalin Marinas , Dave Hansen , Hillf Danton , Jens Axboe , Johannes Weiner , Jonathan Corbet , Linus Torvalds , Matthew Wilcox , Mel Gorman , Michael Larabel , Michal Hocko , Mike Rapoport , Peter Zijlstra , Tejun Heo , Vlastimil Babka , Will Deacon , Linux ARM , "open list:DOCUMENTATION" , linux-kernel , Linux-MM , the arch/x86 maintainers , Kernel Page Reclaim v2 , Brian Geffon , Jan Alexander Steffens , Oleksandr Natalenko , Steven Barrett , Suleiman Souhlal , Daniel Byrne , Donald Carr , =?UTF-8?Q?Holger_Hoffst=c3=a4tte?= , Konstantin Kharlamov , Shuang Zhai , Sofia Trinh , Vaibhav Jain References: <20220614071650.206064-1-yuzhao@google.com> <20220614071650.206064-13-yuzhao@google.com> <214db251-827c-715c-54cf-9c0e9bb5fe30@bytedance.com> From: Qi Zheng In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,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 On 2022/6/23 03:13, Yu Zhao wrote: > On Wed, Jun 22, 2022 at 3:16 AM Qi Zheng wrote: > >>> +static ssize_t lru_gen_seq_write(struct file *file, const char __user *src, >>> + size_t len, loff_t *pos) >>> +{ >>> + void *buf; >>> + char *cur, *next; >>> + unsigned int flags; >>> + struct blk_plug plug; >>> + int err = -EINVAL; >>> + struct scan_control sc = { >>> + .may_writepage = true, >>> + .may_unmap = true, >>> + .may_swap = true, >>> + .reclaim_idx = MAX_NR_ZONES - 1, >>> + .gfp_mask = GFP_KERNEL, >>> + }; >>> + >>> + buf = kvmalloc(len + 1, GFP_KERNEL); >>> + if (!buf) >>> + return -ENOMEM; >>> + >>> + if (copy_from_user(buf, src, len)) { >>> + kvfree(buf); >>> + return -EFAULT; >>> + } >>> + >>> + if (!set_mm_walk(NULL)) { >> >> The current->reclaim_state will be dereferenced in set_mm_walk(), so >> calling set_mm_walk() before set_task_reclaim_state(current, >> &sc.reclaim_state) will cause panic: >> >> [ 1861.154916] BUG: kernel NULL pointer dereference, address: >> 0000000000000008 > > Thanks. > > Apparently I shot myself in the foot by one of the nits between v11 and v12. > >>> + kvfree(buf); >>> + return -ENOMEM; >>> + } >>> + >>> + set_task_reclaim_state(current, &sc.reclaim_state); >>> + flags = memalloc_noreclaim_save(); >>> + blk_start_plug(&plug); >>> + >>> + next = buf; >>> + next[len] = '\0'; >>> + >>> + while ((cur = strsep(&next, ",;\n"))) { >>> + int n; >>> + int end; >>> + char cmd; >>> + unsigned int memcg_id; >>> + unsigned int nid; >>> + unsigned long seq; >>> + unsigned int swappiness = -1; >>> + unsigned long opt = -1; >>> + >>> + cur = skip_spaces(cur); >>> + if (!*cur) >>> + continue; >>> + >>> + n = sscanf(cur, "%c %u %u %lu %n %u %n %lu %n", &cmd, &memcg_id, &nid, >>> + &seq, &end, &swappiness, &end, &opt, &end); >>> + if (n < 4 || cur[end]) { >>> + err = -EINVAL; >>> + break; >>> + } >>> + >>> + err = run_cmd(cmd, memcg_id, nid, seq, &sc, swappiness, opt); >>> + if (err) >>> + break; >>> + } >>> + >>> + blk_finish_plug(&plug); >>> + memalloc_noreclaim_restore(flags); >>> + set_task_reclaim_state(current, NULL); >>> + >>> + clear_mm_walk(); >> >> Ditto, we can't call clear_mm_walk() after >> set_task_reclaim_state(current, NULL). >> >> Maybe it can be modified as follows: >> >> diff --git a/mm/vmscan.c b/mm/vmscan.c >> index 2422edc786eb..552e6ae5243e 100644 >> --- a/mm/vmscan.c >> +++ b/mm/vmscan.c >> @@ -5569,12 +5569,12 @@ static ssize_t lru_gen_seq_write(struct file >> *file, const char __user *src, >> return -EFAULT; >> } >> >> + set_task_reclaim_state(current, &sc.reclaim_state); >> if (!set_mm_walk(NULL)) { >> kvfree(buf); >> return -ENOMEM; >> } >> >> - set_task_reclaim_state(current, &sc.reclaim_state); > > We need a `goto` because otherwise we leave a dangling Yes, right. With this: Reviewed-by: Qi Zheng > `current->reclaim_state`. (I swear I had one.) (I believe :)) -- Thanks, Qi